equal
deleted
inserted
replaced
8 * Buffer content is read asynchronously, (from non real time part), |
8 * Buffer content is read asynchronously, (from non real time part), |
9 * and then buffer marked free again. |
9 * and then buffer marked free again. |
10 * |
10 * |
11 * |
11 * |
12 * */ |
12 * */ |
13 |
13 #ifdef TARGET_DEBUG_AND_RETAIN_DISABLE |
14 #ifdef TARGET_DEBUG_DISABLE |
|
15 |
14 |
16 void __init_debug (void){} |
15 void __init_debug (void){} |
17 void __cleanup_debug (void){} |
16 void __cleanup_debug (void){} |
18 void __retrieve_debug(void){} |
17 void __retrieve_debug(void){} |
19 void __publish_debug (void){} |
18 void __publish_debug (void){} |
24 #include "POUS.h" |
23 #include "POUS.h" |
25 /*for memcpy*/ |
24 /*for memcpy*/ |
26 #include <string.h> |
25 #include <string.h> |
27 #include <stdio.h> |
26 #include <stdio.h> |
28 |
27 |
|
28 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
29 #define BUFFER_SIZE %(buffer_size)d |
29 #define BUFFER_SIZE %(buffer_size)d |
30 |
30 |
31 /* Atomically accessed variable for buffer state */ |
31 /* Atomically accessed variable for buffer state */ |
32 #define BUFFER_FREE 0 |
32 #define BUFFER_FREE 0 |
33 #define BUFFER_BUSY 1 |
33 #define BUFFER_BUSY 1 |
36 /* The buffer itself */ |
36 /* The buffer itself */ |
37 char debug_buffer[BUFFER_SIZE]; |
37 char debug_buffer[BUFFER_SIZE]; |
38 |
38 |
39 /* Buffer's cursor*/ |
39 /* Buffer's cursor*/ |
40 static char* buffer_cursor = debug_buffer; |
40 static char* buffer_cursor = debug_buffer; |
|
41 #endif |
|
42 |
41 static unsigned int retain_offset = 0; |
43 static unsigned int retain_offset = 0; |
42 /*** |
44 /*** |
43 * Declare programs |
45 * Declare programs |
44 **/ |
46 **/ |
45 %(programs_declarations)s |
47 %(programs_declarations)s |
124 extern void InitRetain(void); |
126 extern void InitRetain(void); |
125 |
127 |
126 void __init_debug(void) |
128 void __init_debug(void) |
127 { |
129 { |
128 /* init local static vars */ |
130 /* init local static vars */ |
|
131 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
129 buffer_cursor = debug_buffer; |
132 buffer_cursor = debug_buffer; |
|
133 buffer_state = BUFFER_FREE; |
|
134 #endif |
|
135 |
130 retain_offset = 0; |
136 retain_offset = 0; |
131 buffer_state = BUFFER_FREE; |
|
132 InitRetain(); |
137 InitRetain(); |
133 /* Iterate over all variables to fill debug buffer */ |
138 /* Iterate over all variables to fill debug buffer */ |
134 if(CheckRetainBuffer()){ |
139 if(CheckRetainBuffer()){ |
135 __for_each_variable_do(RemindIterator); |
140 __for_each_variable_do(RemindIterator); |
136 }else{ |
141 }else{ |
145 |
150 |
146 extern unsigned long __tick; |
151 extern unsigned long __tick; |
147 |
152 |
148 void __cleanup_debug(void) |
153 void __cleanup_debug(void) |
149 { |
154 { |
|
155 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
150 buffer_cursor = debug_buffer; |
156 buffer_cursor = debug_buffer; |
151 InitiateDebugTransfer(); |
157 InitiateDebugTransfer(); |
|
158 #endif |
|
159 |
152 CleanupRetain(); |
160 CleanupRetain(); |
153 } |
161 } |
154 |
162 |
155 void __retrieve_debug(void) |
163 void __retrieve_debug(void) |
156 { |
164 { |
167 |
175 |
168 visible_value_p = UnpackVar(dsc, &real_value_p, &flags); |
176 visible_value_p = UnpackVar(dsc, &real_value_p, &flags); |
169 |
177 |
170 if(flags & ( __IEC_DEBUG_FLAG | __IEC_RETAIN_FLAG)){ |
178 if(flags & ( __IEC_DEBUG_FLAG | __IEC_RETAIN_FLAG)){ |
171 USINT size = __get_type_enum_size(dsc->type); |
179 USINT size = __get_type_enum_size(dsc->type); |
|
180 |
|
181 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
172 if(flags & __IEC_DEBUG_FLAG){ |
182 if(flags & __IEC_DEBUG_FLAG){ |
173 /* copy visible variable to buffer */; |
183 /* copy visible variable to buffer */; |
174 if(do_debug){ |
184 if(do_debug){ |
175 /* compute next cursor positon. |
185 /* compute next cursor positon. |
176 No need to check overflow, as BUFFER_SIZE |
186 No need to check overflow, as BUFFER_SIZE |
190 /* re-force real value of outputs (M and Q)*/ |
200 /* re-force real value of outputs (M and Q)*/ |
191 if((flags & __IEC_FORCE_FLAG) && (flags & __IEC_OUTPUT_FLAG)){ |
201 if((flags & __IEC_FORCE_FLAG) && (flags & __IEC_OUTPUT_FLAG)){ |
192 memcpy(real_value_p, visible_value_p, size); |
202 memcpy(real_value_p, visible_value_p, size); |
193 } |
203 } |
194 } |
204 } |
|
205 #endif |
|
206 |
195 if(flags & __IEC_RETAIN_FLAG){ |
207 if(flags & __IEC_RETAIN_FLAG){ |
196 /* compute next cursor positon*/ |
208 /* compute next cursor positon*/ |
197 unsigned int next_retain_offset = retain_offset + size; |
209 unsigned int next_retain_offset = retain_offset + size; |
198 /* if buffer not full */ |
210 /* if buffer not full */ |
199 Retain(retain_offset, size, real_value_p); |
211 Retain(retain_offset, size, real_value_p); |
246 |
258 |
247 void __publish_debug(void) |
259 void __publish_debug(void) |
248 { |
260 { |
249 retain_offset = 0; |
261 retain_offset = 0; |
250 InValidateRetainBuffer(); |
262 InValidateRetainBuffer(); |
|
263 |
|
264 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
251 /* Check there is no running debugger re-configuration */ |
265 /* Check there is no running debugger re-configuration */ |
252 if(TryEnterDebugSection()){ |
266 if(TryEnterDebugSection()){ |
253 /* Lock buffer */ |
267 /* Lock buffer */ |
254 long latest_state = AtomicCompareExchange( |
268 long latest_state = AtomicCompareExchange( |
255 &buffer_state, |
269 &buffer_state, |
271 }else{ |
285 }else{ |
272 /* when not debugging, do only retain */ |
286 /* when not debugging, do only retain */ |
273 __for_each_variable_do(RetainIterator); |
287 __for_each_variable_do(RetainIterator); |
274 } |
288 } |
275 LeaveDebugSection(); |
289 LeaveDebugSection(); |
276 }else{ |
290 }else |
|
291 #endif |
|
292 { |
277 /* when not debugging, do only retain */ |
293 /* when not debugging, do only retain */ |
278 __for_each_variable_do(RetainIterator); |
294 __for_each_variable_do(RetainIterator); |
279 } |
295 } |
280 ValidateRetainBuffer(); |
296 ValidateRetainBuffer(); |
281 } |
297 } |
282 |
298 |
|
299 #ifndef TARGET_ONLINE_DEBUG_DISABLE |
283 #define __RegisterDebugVariable_case_t(TYPENAME) \ |
300 #define __RegisterDebugVariable_case_t(TYPENAME) \ |
284 case TYPENAME##_ENUM :\ |
301 case TYPENAME##_ENUM :\ |
285 ((__IEC_##TYPENAME##_t *)varp)->flags |= flags;\ |
302 ((__IEC_##TYPENAME##_t *)varp)->flags |= flags;\ |
286 if(force)\ |
303 if(force)\ |
287 ((__IEC_##TYPENAME##_t *)varp)->value = *((TYPENAME *)force);\ |
304 ((__IEC_##TYPENAME##_t *)varp)->value = *((TYPENAME *)force);\ |
360 *size = buffer_cursor - debug_buffer; |
377 *size = buffer_cursor - debug_buffer; |
361 *buffer = debug_buffer; |
378 *buffer = debug_buffer; |
362 } |
379 } |
363 return wait_error; |
380 return wait_error; |
364 } |
381 } |
365 |
382 #endif |
366 #endif |
383 #endif |
367 |
384 |