equal
deleted
inserted
replaced
145 static unsigned long __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 if(WaitForSingleObject(debug_sem, 0) == WAIT_OBJECT_0){ |
|
151 /* Only enter if debug active */ |
|
152 if(__DEBUG){ |
|
153 return 1; |
|
154 } |
|
155 ReleaseSemaphore(debug_sem, 1, NULL); |
|
156 return 0; |
|
157 } |
151 } |
158 } |
152 |
159 |
153 void LeaveDebugSection(void) |
160 void LeaveDebugSection(void) |
154 { |
161 { |
155 ReleaseSemaphore(debug_sem, 1, NULL); |
162 ReleaseSemaphore(debug_sem, 1, NULL); |
169 CloseHandle(PLC_thread); |
176 CloseHandle(PLC_thread); |
170 } |
177 } |
171 |
178 |
172 /* from plc_debugger.c */ |
179 /* from plc_debugger.c */ |
173 int WaitDebugData(unsigned long *tick) |
180 int WaitDebugData(unsigned long *tick) |
174 unsigned long WaitDebugData() |
|
175 { |
181 { |
176 *tick = __debug_tick; |
182 *tick = __debug_tick; |
177 /* Wait signal from PLC thread */ |
183 /* Wait signal from PLC thread */ |
178 return WaitForSingleObject(debug_wait_sem, INFINITE) != WAIT_OBJECT_0; |
184 return WaitForSingleObject(debug_wait_sem, INFINITE) != WAIT_OBJECT_0; |
179 } |
185 } |
186 __debug_tick = __tick; |
192 __debug_tick = __tick; |
187 /* signal debugger thread it can read data */ |
193 /* signal debugger thread it can read data */ |
188 ReleaseSemaphore(debug_wait_sem, 1, NULL); |
194 ReleaseSemaphore(debug_wait_sem, 1, NULL); |
189 } |
195 } |
190 |
196 |
191 void suspendDebug() |
197 void suspendDebug(int disable) |
192 { |
198 { |
193 __DEBUG = 0; |
|
194 /* Prevent PLC to enter debug code */ |
199 /* Prevent PLC to enter debug code */ |
195 WaitForSingleObject(debug_sem, INFINITE); |
200 WaitForSingleObject(debug_sem, INFINITE); |
|
201 /*__DEBUG is protected by this mutex */ |
|
202 __DEBUG = !disable; |
196 } |
203 } |
197 |
204 |
198 void resumeDebug() |
205 void resumeDebug() |
199 { |
206 { |
200 __DEBUG = 1; |
207 __DEBUG = 1; |