author | etisserant |
Tue, 17 Jul 2007 12:19:59 +0200 | |
changeset 42 | b45c7f34dec1 |
parent 41 | 8998c8b24b60 |
child 43 | 37dd4e2fd2ec |
permissions | -rw-r--r-- |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
1 |
#include <time.h> |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
2 |
#include <signal.h> |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
3 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
4 |
#include "iec_std_lib.h" |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
5 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
6 |
/* |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
7 |
* Functions and variables provied by generated C softPLC |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
8 |
**/ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
9 |
void config_run__(int tick); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
10 |
void config_init__(void); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
11 |
extern int common_ticktime__; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
12 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
13 |
/* |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
14 |
* Functions and variables to export to generated C softPLC |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
15 |
**/ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
16 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
17 |
TIME __CURRENT_TIME; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
18 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
19 |
#define __LOCATED_VAR(type, name) type name; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
20 |
#include "LOCATED_VARIABLES.h" |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
21 |
#undef __LOCATED_VAR |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
22 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
23 |
#define print_BOOL(name) printf(" %s = (BOOL) %s\n",#name, name?"TRUE":"FALSE"); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
24 |
#define print_SINT(name) printf(" %s = (SINT) %d\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
25 |
#define print_INT(name) printf(" %s = (INT) %d\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
26 |
#define print_DINT(name) printf(" %s = (DINT) %d\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
27 |
#define print_LINT(name) printf(" %s = (LINT) %d\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
28 |
#define print_USINT(name) printf(" %s = (USINT) %u\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
29 |
#define print_UINT(name) printf(" %s = (UINT) %u\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
30 |
#define print_UDINT(name) printf(" %s = (UDINT) %u\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
31 |
#define print_ULINT(name) printf(" %s = (ULINT) %lu\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
32 |
#define print_REAL(name) printf(" %s = (REAL) %f\n",#name, (double)name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
33 |
#define print_LREAL(name) printf(" %s = (LREAL) %f\n",#name, (double)name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
34 |
#define print_TIME(name) {tmp STRING = __time_to_string(name);tmp.body[tmp.len] = 0; printf(" %s = (TIME) %s*s\n",#name, tmp.len, &tmp.body);} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
35 |
#define print_DATE(name) {tmp STRING = __date_to_string(name);tmp.body[tmp.len] = 0; printf(" %s = (TIME) %*s\n",#name, tmp.len, &tmp.body);} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
36 |
#define print_TOD(name) {tmp STRING = __tod_to_string(name);tmp.body[tmp.len] = 0; printf(" %s = (TIME) %*s\n",#name, tmp.len, &tmp.body);} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
37 |
#define print_DT(name) {tmp STRING = __dt_to_string(name);tmp.body[tmp.len] = 0; printf(" %s = (TIME) %*s\n",#name, tmp.len, &tmp.body);} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
38 |
#define print_STRING(name) printf(" %s = (STRING) {%d, \"%*s\"}\n",#name, name.len, name.len, &name.body); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
39 |
#define print_BYTE(name) printf(" %s = (BYTE) 0x%2.2x\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
40 |
#define print_WORD(name) printf(" %s = (WORD) 0x%d4.4\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
41 |
#define print_DWORD(name) printf(" %s = (DWORD) 0x%d8.8\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
42 |
#define print_LWORD(name) printf(" %s = (LWORD) 0x%d16.16\n",#name, name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
43 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
44 |
static int tick = 0; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
45 |
void timer_notify(sigval_t val) |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
46 |
{ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
47 |
clock_gettime(CLOCK_REALTIME, &__CURRENT_TIME); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
48 |
printf("Tick %d\n",tick); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
49 |
config_run__(tick++); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
50 |
printf(" Located variables : \n"); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
51 |
#define __LOCATED_VAR(type, name) print_##type(name); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
52 |
#include "LOCATED_VARIABLES.h" |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
53 |
#undef __LOCATED_VAR |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
54 |
} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
55 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
56 |
void catch_signal(int sig) |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
57 |
{ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
58 |
signal(SIGTERM, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
59 |
signal(SIGINT, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
60 |
printf("Got Signal %d\n",sig); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
61 |
} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
62 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
63 |
#define maxval(a,b) ((a>b)?a:b) |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
64 |
int main(int argc,char **argv) |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
65 |
{ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
66 |
timer_t timer; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
67 |
struct sigevent sigev; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
68 |
long tv_nsec = 1000000 * (maxval(common_ticktime__,1)%1000); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
69 |
time_t tv_sec = common_ticktime__/1000; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
70 |
struct itimerspec timerValues; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
71 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
72 |
memset (&sigev, 0, sizeof (struct sigevent)); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
73 |
memset (&timerValues, 0, sizeof (struct itimerspec)); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
74 |
sigev.sigev_value.sival_int = 0; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
75 |
sigev.sigev_notify = SIGEV_THREAD; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
76 |
sigev.sigev_notify_attributes = NULL; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
77 |
sigev.sigev_notify_function = timer_notify; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
78 |
timerValues.it_value.tv_sec = tv_sec; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
79 |
timerValues.it_value.tv_nsec = tv_nsec; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
80 |
timerValues.it_interval.tv_sec = tv_sec; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
81 |
timerValues.it_interval.tv_nsec = tv_nsec; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
82 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
83 |
config_init__(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
84 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
85 |
timer_create (CLOCK_REALTIME, &sigev, &timer); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
86 |
timer_settime (timer, 0, &timerValues, NULL); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
87 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
88 |
/* install signal handler for manual break */ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
89 |
signal(SIGTERM, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
90 |
signal(SIGINT, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
91 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
92 |
pause(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
93 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
94 |
timer_delete (timer); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
95 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
96 |
return 0; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
97 |
} |