equal
deleted
inserted
replaced
35 #define WAITPYTHON_PIPE_MINOR 2 |
35 #define WAITPYTHON_PIPE_MINOR 2 |
36 #define PYTHON_PIPE_DEVICE "/dev/rtp3" |
36 #define PYTHON_PIPE_DEVICE "/dev/rtp3" |
37 #define PYTHON_PIPE_MINOR 3 |
37 #define PYTHON_PIPE_MINOR 3 |
38 #define PIPE_SIZE 1 |
38 #define PIPE_SIZE 1 |
39 |
39 |
|
40 // rt-pipes commands |
|
41 |
|
42 #define PYTHON_PENDING_COMMAND 1 |
|
43 #define PYTHON_FINISH 2 |
|
44 |
|
45 #define DEBUG_FINISH 2 |
|
46 |
|
47 #define DEBUG_PENDING_DATA 1 |
|
48 #define DEBUG_UNLOCK 1 |
40 |
49 |
41 long AtomicCompareExchange(long* atomicvar,long compared, long exchange) |
50 long AtomicCompareExchange(long* atomicvar,long compared, long exchange) |
42 { |
51 { |
43 return __sync_val_compare_and_swap(atomicvar, compared, exchange); |
52 return __sync_val_compare_and_swap(atomicvar, compared, exchange); |
44 } |
53 } |
80 PLC_GetTime(&__CURRENT_TIME); |
89 PLC_GetTime(&__CURRENT_TIME); |
81 __run(); |
90 __run(); |
82 if (PLC_shutdown) break; |
91 if (PLC_shutdown) break; |
83 rt_task_wait_period(NULL); |
92 rt_task_wait_period(NULL); |
84 } |
93 } |
|
94 /* since xenomai 3 it is not enough to close() |
|
95 file descriptor to unblock read()... */ |
|
96 { |
|
97 /* explicitely finish python thread */ |
|
98 char msg = PYTHON_FINISH; |
|
99 rt_pipe_write(&WaitPython_pipe, &msg, sizeof(msg), P_NORMAL); |
|
100 } |
|
101 { |
|
102 /* explicitely finish debug thread */ |
|
103 char msg = DEBUG_FINISH; |
|
104 rt_pipe_write(&WaitDebug_pipe, &msg, sizeof(msg), P_NORMAL); |
|
105 } |
85 } |
106 } |
86 |
107 |
87 static unsigned long __debug_tick; |
108 static unsigned long __debug_tick; |
88 |
109 |
89 void PLC_cleanup_all(void) |
110 void PLC_cleanup_all(void) |
254 AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
275 AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
255 } |
276 } |
256 return 0; |
277 return 0; |
257 } |
278 } |
258 |
279 |
259 #define DEBUG_UNLOCK 1 |
|
260 void LeaveDebugSection(void) |
280 void LeaveDebugSection(void) |
261 { |
281 { |
262 if(AtomicCompareExchange( &debug_state, |
282 if(AtomicCompareExchange( &debug_state, |
263 DEBUG_BUSY, DEBUG_FREE) == DEBUG_BUSY){ |
283 DEBUG_BUSY, DEBUG_FREE) == DEBUG_BUSY){ |
264 char msg = DEBUG_UNLOCK; |
284 char msg = DEBUG_UNLOCK; |
267 } |
287 } |
268 } |
288 } |
269 |
289 |
270 extern unsigned long __tick; |
290 extern unsigned long __tick; |
271 |
291 |
272 #define DEBUG_PENDING_DATA 1 |
|
273 int WaitDebugData(unsigned long *tick) |
292 int WaitDebugData(unsigned long *tick) |
274 { |
293 { |
275 char cmd; |
294 char cmd; |
276 int res; |
295 int res; |
277 if (PLC_shutdown) return -1; |
296 if (PLC_shutdown) return -1; |
317 void resumeDebug(void) |
336 void resumeDebug(void) |
318 { |
337 { |
319 AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
338 AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); |
320 } |
339 } |
321 |
340 |
322 #define PYTHON_PENDING_COMMAND 1 |
|
323 |
|
324 #define PYTHON_FREE 0 |
341 #define PYTHON_FREE 0 |
325 #define PYTHON_BUSY 1 |
342 #define PYTHON_BUSY 1 |
326 static long python_state = PYTHON_FREE; |
343 static long python_state = PYTHON_FREE; |
327 |
344 |
328 int WaitPythonCommands(void) |
345 int WaitPythonCommands(void) |