equal
deleted
inserted
replaced
6 #include <sys/timeb.h> |
6 #include <sys/timeb.h> |
7 #include <time.h> |
7 #include <time.h> |
8 #include <windows.h> |
8 #include <windows.h> |
9 |
9 |
10 /* provided by POUS.C */ |
10 /* provided by POUS.C */ |
11 extern int common_ticktime__; |
11 extern unsigned long common_ticktime__; |
12 |
12 |
13 long AtomicCompareExchange(long* atomicvar, long compared, long exchange) |
13 long AtomicCompareExchange(long* atomicvar, long compared, long exchange) |
14 { |
14 { |
15 return InterlockedCompareExchange(atomicvar, exchange, compared); |
15 return InterlockedCompareExchange(atomicvar, exchange, compared); |
16 } |
16 } |
72 |
72 |
73 #define maxval(a,b) ((a>b)?a:b) |
73 #define maxval(a,b) ((a>b)?a:b) |
74 int startPLC(int argc,char **argv) |
74 int startPLC(int argc,char **argv) |
75 { |
75 { |
76 unsigned long thread_id = 0; |
76 unsigned long thread_id = 0; |
77 /* Translate PLC's microseconds to Ttick nanoseconds */ |
77 /* Define Ttick to 1ms if common_ticktime not defined */ |
78 Ttick = 1000000 * maxval(common_ticktime__,1); |
78 Ttick = common_ticktime__?common_ticktime__:1000000; |
79 |
79 |
80 debug_sem = CreateSemaphore( |
80 debug_sem = CreateSemaphore( |
81 NULL, // default security attributes |
81 NULL, // default security attributes |
82 1, // initial count |
82 1, // initial count |
83 1, // maximum count |
83 1, // maximum count |
140 else{ |
140 else{ |
141 return 1; |
141 return 1; |
142 } |
142 } |
143 return 0; |
143 return 0; |
144 } |
144 } |
145 static int __debug_tick; |
145 static unsigned long __debug_tick; |
146 |
146 |
147 int TryEnterDebugSection(void) |
147 int TryEnterDebugSection(void) |
148 { |
148 { |
149 //printf("TryEnterDebugSection\n"); |
149 //printf("TryEnterDebugSection\n"); |
150 return WaitForSingleObject(debug_sem, 0) == WAIT_OBJECT_0; |
150 return WaitForSingleObject(debug_sem, 0) == WAIT_OBJECT_0; |
168 CloseHandle(PLC_timer); |
168 CloseHandle(PLC_timer); |
169 CloseHandle(PLC_thread); |
169 CloseHandle(PLC_thread); |
170 } |
170 } |
171 |
171 |
172 /* from plc_debugger.c */ |
172 /* from plc_debugger.c */ |
173 int WaitDebugData() |
173 unsigned long WaitDebugData() |
174 { |
174 { |
175 if(WaitForSingleObject(debug_wait_sem, INFINITE) != WAIT_OBJECT_0) return -1; |
175 if(WaitForSingleObject(debug_wait_sem, INFINITE) != WAIT_OBJECT_0) return -1; |
176 return __debug_tick; |
176 return __debug_tick; |
177 } |
177 } |
178 |
178 |