author | lbessard |
Wed, 25 Jul 2007 18:03:27 +0200 | |
changeset 46 | fc1b78ea6d84 |
parent 43 | 37dd4e2fd2ec |
child 57 | db9cadaab2ea |
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 |
static int tick = 0; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
24 |
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
|
25 |
{ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
26 |
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
|
27 |
printf("Tick %d\n",tick); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
28 |
config_run__(tick++); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
29 |
printf(" Located variables : \n"); |
43 | 30 |
#define __LOCATED_VAR(type, name) __print_##type(name); |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
31 |
#include "LOCATED_VARIABLES.h" |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
32 |
#undef __LOCATED_VAR |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
33 |
} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
34 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
35 |
void catch_signal(int sig) |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
36 |
{ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
37 |
signal(SIGTERM, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
38 |
signal(SIGINT, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
39 |
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
|
40 |
} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
41 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
42 |
#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
|
43 |
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
|
44 |
{ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
45 |
timer_t timer; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
46 |
struct sigevent sigev; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
struct itimerspec timerValues; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
50 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
sigev.sigev_notify = SIGEV_THREAD; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
55 |
sigev.sigev_notify_attributes = NULL; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
62 |
config_init__(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
63 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
64 |
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
|
65 |
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
|
66 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
67 |
/* 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
|
68 |
signal(SIGTERM, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
69 |
signal(SIGINT, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
70 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
71 |
pause(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
72 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
73 |
timer_delete (timer); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
74 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
75 |
return 0; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
76 |
} |