84 return 1; |
84 return 1; |
85 } |
85 } |
86 return 0; |
86 return 0; |
87 } |
87 } |
88 |
88 |
|
89 static int __debug_tick; |
|
90 |
|
91 static pthread_mutex_t wait_mutex = PTHREAD_MUTEX_INITIALIZER; |
|
92 static pthread_cond_t wait_cond = PTHREAD_COND_INITIALIZER; |
|
93 |
|
94 void AbortDebug() |
|
95 { |
|
96 /* Eventually unlock debugger thread*/ |
|
97 __debug_tick = -1; |
|
98 pthread_mutex_lock(&wait_mutex); |
|
99 pthread_cond_broadcast(&wait_cond); |
|
100 pthread_mutex_unlock(&wait_mutex); |
|
101 } |
|
102 |
89 int stopPLC() |
103 int stopPLC() |
90 { |
104 { |
91 /* Stop the PLC */ |
105 /* Stop the PLC */ |
92 PLC_SetTimer(0,0); |
106 PLC_SetTimer(0,0); |
93 timer_delete (PLC_timer); |
107 timer_delete (PLC_timer); |
94 __cleanup(); |
108 __cleanup(); |
|
109 AbortDebug(); |
95 } |
110 } |
96 |
111 |
97 pthread_mutex_t DebugLock = PTHREAD_MUTEX_INITIALIZER; |
|
98 |
|
99 static int __debug_tick; |
|
100 extern int __tick; |
112 extern int __tick; |
101 /* from plc_debugger.c */ |
113 /* from plc_debugger.c */ |
102 int WaitDebugData() |
114 int WaitDebugData() |
103 { |
115 { |
104 /* Wait signal from PLC thread */ |
116 /* Wait signal from PLC thread */ |
105 pthread_mutex_lock(&DebugLock); |
117 pthread_mutex_lock(&wait_mutex); |
|
118 pthread_cond_wait(&wait_cond, &wait_mutex); |
|
119 pthread_mutex_unlock(&wait_mutex); |
106 return __debug_tick; |
120 return __debug_tick; |
107 } |
121 } |
108 |
122 |
109 /* Called by PLC thread when debug_publish finished |
123 /* Called by PLC thread when debug_publish finished |
110 * This is supposed to unlock debugger thread in WaitDebugData*/ |
124 * This is supposed to unlock debugger thread in WaitDebugData*/ |
111 void InitiateDebugTransfer() |
125 void InitiateDebugTransfer() |
112 { |
126 { |
113 /* signal debugger thread to continue*/ |
127 /* signal debugger thread to continue*/ |
114 __debug_tick = __tick; |
128 __debug_tick = __tick; |
115 pthread_mutex_unlock(&DebugLock); |
129 pthread_mutex_lock(&wait_mutex); |
|
130 pthread_cond_broadcast(&wait_cond); |
|
131 pthread_mutex_unlock(&wait_mutex); |
116 } |
132 } |