author | etisserant |
Mon, 04 Aug 2008 15:14:25 +0200 | |
changeset 135 | 0f3f6714b938 |
parent 57 | db9cadaab2ea |
child 150 | 398cfd6e8e4a |
permissions | -rw-r--r-- |
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
1 |
#ifdef __WIN32__ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
2 |
#include <stdio.h> |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
3 |
#include <sys/timeb.h> |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
4 |
#include <time.h> |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
5 |
#include <windows.h> |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
6 |
#else |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
7 |
#include <stdio.h> |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
8 |
#include <string.h> |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
9 |
#include <time.h> |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
10 |
#include <signal.h> |
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
11 |
#endif |
41
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 provied by 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 |
extern int common_ticktime__; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
17 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
18 |
/* |
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
19 |
* Functions and variables provied by plc.c |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
20 |
**/ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
21 |
void run(long int tv_sec, long int tv_nsec); |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
22 |
|
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
23 |
#define maxval(a,b) ((a>b)?a:b) |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
24 |
|
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
25 |
#ifdef __WIN32__ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
26 |
void timer_notify() |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
27 |
{ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
28 |
struct _timeb timebuffer; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
29 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
30 |
_ftime( &timebuffer ); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
31 |
run(timebuffer.time, timebuffer.millitm * 1000000); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
32 |
} |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
33 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
34 |
int main(int argc,char **argv) |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
35 |
{ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
36 |
HANDLE hTimer = NULL; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
37 |
LARGE_INTEGER liDueTime; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
38 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
39 |
liDueTime.QuadPart = -10000 * maxval(common_ticktime__,1);; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
40 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
41 |
// Create a waitable timer. |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
42 |
hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer"); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
43 |
if (NULL == hTimer) |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
44 |
{ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
45 |
printf("CreateWaitableTimer failed (%d)\n", GetLastError()); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
46 |
return 1; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
47 |
} |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
48 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
49 |
config_init__(); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
50 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
51 |
// Set a timer to wait for 10 seconds. |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
52 |
if (!SetWaitableTimer(hTimer, &liDueTime, common_ticktime__, NULL, NULL, 0)) |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
53 |
{ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
54 |
printf("SetWaitableTimer failed (%d)\n", GetLastError()); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
55 |
return 2; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
56 |
} |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
57 |
|
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
58 |
while(1){ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
59 |
// Wait for the timer. |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
60 |
if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0) |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
61 |
{ |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
62 |
printf("WaitForSingleObject failed (%d)\n", GetLastError()); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
63 |
break; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
64 |
} |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
65 |
timer_notify(); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
66 |
} |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
67 |
return 0; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
68 |
} |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
69 |
#else |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
70 |
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
|
71 |
{ |
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
72 |
struct timespec CURRENT_TIME; |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
73 |
clock_gettime(CLOCK_REALTIME, &CURRENT_TIME); |
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
74 |
run(CURRENT_TIME.tv_sec, CURRENT_TIME.tv_nsec); |
41
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
75 |
} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
76 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
77 |
void catch_signal(int sig) |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
78 |
{ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
79 |
signal(SIGTERM, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
80 |
signal(SIGINT, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
81 |
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
|
82 |
} |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
83 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
84 |
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
|
85 |
{ |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
86 |
timer_t timer; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
87 |
struct sigevent sigev; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
88 |
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
|
89 |
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
|
90 |
struct itimerspec timerValues; |
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 |
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
|
93 |
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
|
94 |
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
|
95 |
sigev.sigev_notify = SIGEV_THREAD; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
96 |
sigev.sigev_notify_attributes = NULL; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
103 |
config_init__(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
104 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
108 |
/* 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
|
109 |
signal(SIGTERM, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
110 |
signal(SIGINT, catch_signal); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
111 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
112 |
pause(); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
113 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
114 |
timer_delete (timer); |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
115 |
|
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
116 |
return 0; |
8998c8b24b60
First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents:
diff
changeset
|
117 |
} |
57
db9cadaab2ea
Now generated SoftPLC compiles with mingw32 and run windows.
etisserant
parents:
43
diff
changeset
|
118 |
#endif |