author | etisserant |
Tue, 26 Feb 2008 15:04:12 +0100 | |
changeset 112 | fa0eaeaa9012 |
parent 100 | 24b504f67c72 |
child 178 | 2390b409eb93 |
permissions | -rw-r--r-- |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
1 |
#include <stdio.h> |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
2 |
#include <string.h> |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
3 |
#include <time.h> |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
4 |
#include <signal.h> |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
5 |
|
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
6 |
|
53 | 7 |
void PLC_timer_notify(sigval_t val) |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
8 |
{ |
100 | 9 |
clock_gettime(CLOCK_REALTIME, &__CURRENT_TIME); |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
10 |
__run(); |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
11 |
} |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
12 |
|
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
13 |
void catch_signal(int sig) |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
14 |
{ |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
15 |
signal(SIGTERM, catch_signal); |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
16 |
signal(SIGINT, catch_signal); |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
17 |
printf("Got Signal %d\n",sig); |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
18 |
} |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
19 |
|
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
20 |
int main(int argc,char **argv) |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
21 |
{ |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
22 |
timer_t timer; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
23 |
struct sigevent sigev; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
24 |
long tv_nsec = 1000000 * (maxval(common_ticktime__,1)%1000); |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
25 |
time_t tv_sec = common_ticktime__/1000; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
26 |
struct itimerspec timerValues; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
27 |
|
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
28 |
memset (&sigev, 0, sizeof (struct sigevent)); |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
29 |
memset (&timerValues, 0, sizeof (struct itimerspec)); |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
30 |
sigev.sigev_value.sival_int = 0; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
31 |
sigev.sigev_notify = SIGEV_THREAD; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
32 |
sigev.sigev_notify_attributes = NULL; |
53 | 33 |
sigev.sigev_notify_function = PLC_timer_notify; |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
34 |
timerValues.it_value.tv_sec = tv_sec; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
35 |
timerValues.it_value.tv_nsec = tv_nsec; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
36 |
timerValues.it_interval.tv_sec = tv_sec; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
37 |
timerValues.it_interval.tv_nsec = tv_nsec; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
38 |
|
57 | 39 |
if( __init(argc,argv) == 0 ){ |
40 |
timer_create (CLOCK_REALTIME, &sigev, &timer); |
|
41 |
timer_settime (timer, 0, &timerValues, NULL); |
|
42 |
||
43 |
/* install signal handler for manual break */ |
|
44 |
signal(SIGTERM, catch_signal); |
|
45 |
signal(SIGINT, catch_signal); |
|
46 |
||
47 |
pause(); |
|
48 |
||
49 |
timer_delete (timer); |
|
50 |
} |
|
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
51 |
__cleanup(); |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
52 |
|
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
53 |
return 0; |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
diff
changeset
|
54 |
} |