author | laurent |
Tue, 08 Dec 2009 16:28:10 +0100 | |
changeset 480 | 746b2e02f6fb |
parent 477 | f66a092b6e74 |
child 483 | bc26c42d2eec |
permissions | -rw-r--r-- |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
1 |
/* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
2 |
* DEBUGGER code |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
3 |
* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
4 |
* On "publish", when buffer is free, debugger stores arbitrary variables |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
5 |
* content into, and mark this buffer as filled |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
6 |
* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
7 |
* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
8 |
* Buffer content is read asynchronously, (from non real time part), |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
9 |
* and then buffer marked free again. |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
10 |
* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
11 |
* |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
12 |
* */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
13 |
#include "iec_types_all.h" |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
14 |
#include "POUS.h" |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
15 |
/*for memcpy*/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
16 |
#include <string.h> |
335
c5f3f71e7260
fixed bug : buffer overflow when debugging PLC with python blocks
greg
parents:
280
diff
changeset
|
17 |
#include <stdio.h> |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
18 |
|
335
c5f3f71e7260
fixed bug : buffer overflow when debugging PLC with python blocks
greg
parents:
280
diff
changeset
|
19 |
#define BUFFER_SIZE %(buffer_size)d |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
20 |
#define MAX_SUBSCRIBTION %(subscription_table_count)d |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
21 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
22 |
/* Atomically accessed variable for buffer state */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
23 |
#define BUFFER_FREE 0 |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
24 |
#define BUFFER_BUSY 1 |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
25 |
static long buffer_state = BUFFER_FREE; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
26 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
27 |
/* The buffer itself */ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
28 |
char debug_buffer[BUFFER_SIZE]; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
29 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
30 |
/* Buffer's cursor*/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
31 |
static char* buffer_cursor = debug_buffer; |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
32 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
33 |
/*** |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
34 |
* Declare programs |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
35 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
36 |
%(programs_declarations)s |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
37 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
38 |
/*** |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
39 |
* Declare global variables from resources and conf |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
40 |
**/ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
41 |
%(extern_variables_declarations)s |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
42 |
|
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
43 |
typedef void(*__for_each_variable_do_fp)(void*, __IEC_types_enum); |
452
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
44 |
void __for_each_variable_do(__for_each_variable_do_fp fp) |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
45 |
{ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
46 |
%(for_each_variable_do_code)s |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
47 |
} |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
48 |
|
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
49 |
__IEC_types_enum __find_variable(unsigned int varindex, void ** varp) |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
50 |
{ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
51 |
switch(varindex){ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
52 |
%(find_variable_case_code)s |
452
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
53 |
default: |
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
54 |
*varp = NULL; |
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
55 |
return UNKNOWN_ENUM; |
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
56 |
} |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
57 |
} |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
58 |
|
423 | 59 |
void __init_debug(void) |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
60 |
{ |
280
f2ef79f3dba0
Added native (not a plugin) asynchronous python eval function block - Beta. Code cleanup in C code templates.
etisserant
parents:
244
diff
changeset
|
61 |
buffer_state = BUFFER_FREE; |
244 | 62 |
} |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
63 |
|
423 | 64 |
void __cleanup_debug(void) |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
65 |
{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
66 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
67 |
|
423 | 68 |
void __retrieve_debug(void) |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
69 |
{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
70 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
71 |
|
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
72 |
extern int TryEnterDebugSection(void); |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
73 |
extern void LeaveDebugSection(void); |
386 | 74 |
extern long AtomicCompareExchange(long*, long, long); |
75 |
extern void InitiateDebugTransfer(void); |
|
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
76 |
|
397
6a7ff66a811d
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
394
diff
changeset
|
77 |
extern unsigned long __tick; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
78 |
|
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
79 |
#define __BufferDebugDataIterator_case_t(TYPENAME) \ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
80 |
case TYPENAME##_ENUM :\ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
81 |
flags = ((__IEC_##TYPENAME##_t *)varp)->flags;\ |
458
dfc6164e4022
Debugger still doesn't work crash less...
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
452
diff
changeset
|
82 |
ptrvalue = &((__IEC_##TYPENAME##_t *)varp)->value;\ |
dfc6164e4022
Debugger still doesn't work crash less...
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
452
diff
changeset
|
83 |
break; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
84 |
|
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
85 |
#define __BufferDebugDataIterator_case_p(TYPENAME)\ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
86 |
case TYPENAME##_P_ENUM :\ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
87 |
flags = ((__IEC_##TYPENAME##_p *)varp)->flags;\ |
458
dfc6164e4022
Debugger still doesn't work crash less...
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
452
diff
changeset
|
88 |
ptrvalue = ((__IEC_##TYPENAME##_p *)varp)->value;\ |
dfc6164e4022
Debugger still doesn't work crash less...
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
452
diff
changeset
|
89 |
break; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
90 |
|
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
91 |
void BufferDebugDataIterator(void* varp, __IEC_types_enum vartype) |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
92 |
{ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
93 |
void *ptrvalue = NULL; |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
94 |
char flags = 0; |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
95 |
/* find data to copy*/ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
96 |
switch(vartype){ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
97 |
ANY(__BufferDebugDataIterator_case_t) |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
98 |
ANY(__BufferDebugDataIterator_case_p) |
452
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
99 |
default: |
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
100 |
break; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
101 |
} |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
102 |
if(flags && __IEC_DEBUG_FLAG){ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
103 |
USINT size = __get_type_enum_size(vartype); |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
104 |
/* compute next cursor positon*/ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
105 |
char* next_cursor = buffer_cursor + size; |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
106 |
/* if buffer not full */ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
107 |
if(next_cursor <= debug_buffer + BUFFER_SIZE) |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
108 |
{ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
109 |
/* copy data to the buffer */ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
110 |
memcpy(buffer_cursor, ptrvalue, size); |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
111 |
/* increment cursor according size*/ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
112 |
buffer_cursor = next_cursor; |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
113 |
}else{ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
114 |
/*TODO : signal overflow*/ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
115 |
} |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
116 |
} |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
117 |
} |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
118 |
|
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
119 |
|
423 | 120 |
void __publish_debug(void) |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
121 |
{ |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
122 |
/* Check there is no running debugger re-configuration */ |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
123 |
if(TryEnterDebugSection()){ |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
124 |
/* Lock buffer */ |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
125 |
long latest_state = AtomicCompareExchange( |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
126 |
&buffer_state, |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
127 |
BUFFER_FREE, |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
128 |
BUFFER_BUSY); |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
129 |
|
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
130 |
/* If buffer was free */ |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
131 |
if(latest_state == BUFFER_FREE) |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
132 |
{ |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
133 |
/* Reset buffer cursor */ |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
134 |
buffer_cursor = debug_buffer; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
135 |
/* Iterate over all variables to fill debug buffer */ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
136 |
__for_each_variable_do(BufferDebugDataIterator); |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
137 |
|
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
138 |
/* Leave debug section, |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
139 |
* Trigger asynchronous transmission |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
140 |
* (returns immediately) */ |
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
141 |
InitiateDebugTransfer(); /* size */ |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
142 |
} |
239
112b4bc523b3
Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents:
236
diff
changeset
|
143 |
LeaveDebugSection(); |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
144 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
145 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
146 |
|
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
147 |
#define __RegisterDebugVariable_case_t(TYPENAME) \ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
148 |
case TYPENAME##_ENUM :\ |
477
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
149 |
((__IEC_##TYPENAME##_t *)varp)->flags |= flags;\ |
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
150 |
if(force)\ |
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
151 |
((__IEC_##TYPENAME##_t *)varp)->value = *((TYPENAME *)force);\ |
458
dfc6164e4022
Debugger still doesn't work crash less...
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
452
diff
changeset
|
152 |
break; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
153 |
#define __RegisterDebugVariable_case_p(TYPENAME)\ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
154 |
case TYPENAME##_P_ENUM :\ |
477
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
155 |
((__IEC_##TYPENAME##_p *)varp)->flags |= flags;\ |
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
156 |
if(force)\ |
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
157 |
((__IEC_##TYPENAME##_p *)varp)->fvalue = *((TYPENAME *)force);\ |
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
158 |
break; |
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
159 |
void RegisterDebugVariable(int idx, void* force) |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
160 |
{ |
452
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
161 |
void *varp = NULL; |
477
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
162 |
unsigned char flags = force ? __IEC_DEBUG_FLAG | __IEC_FORCE_FLAG : __IEC_DEBUG_FLAG; |
458
dfc6164e4022
Debugger still doesn't work crash less...
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
452
diff
changeset
|
163 |
switch(__find_variable(idx, &varp)){ |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
164 |
ANY(__RegisterDebugVariable_case_t) |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
165 |
ANY(__RegisterDebugVariable_case_p) |
452
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
166 |
default: |
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
167 |
break; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
168 |
} |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
169 |
} |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
170 |
|
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
171 |
#define __ResetDebugVariablesIterator_case_t(TYPENAME) \ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
172 |
case TYPENAME##_ENUM :\ |
477
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
173 |
((__IEC_##TYPENAME##_t *)varp)->flags &= ~(__IEC_DEBUG_FLAG|__IEC_FORCE_FLAG);\ |
458
dfc6164e4022
Debugger still doesn't work crash less...
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
452
diff
changeset
|
174 |
break; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
175 |
|
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
176 |
#define __ResetDebugVariablesIterator_case_p(TYPENAME)\ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
177 |
case TYPENAME##_P_ENUM :\ |
477
f66a092b6e74
Arbitrary variable forcing
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
458
diff
changeset
|
178 |
((__IEC_##TYPENAME##_p *)varp)->flags &= ~(__IEC_DEBUG_FLAG|__IEC_FORCE_FLAG);\ |
458
dfc6164e4022
Debugger still doesn't work crash less...
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
452
diff
changeset
|
179 |
break; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
180 |
|
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
181 |
void ResetDebugVariablesIterator(void* varp, __IEC_types_enum vartype) |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
182 |
{ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
183 |
/* force debug flag to 0*/ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
184 |
switch(vartype){ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
185 |
ANY(__ResetDebugVariablesIterator_case_t) |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
186 |
ANY(__ResetDebugVariablesIterator_case_p) |
452
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
187 |
default: |
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
188 |
break; |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
189 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
190 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
191 |
|
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
192 |
void ResetDebugVariables(void) |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
193 |
{ |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
194 |
__for_each_variable_do(ResetDebugVariablesIterator); |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
195 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
196 |
|
423 | 197 |
void FreeDebugData(void) |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
198 |
{ |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
199 |
/* atomically mark buffer as free */ |
423 | 200 |
long latest_state; |
201 |
latest_state = AtomicCompareExchange( |
|
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
202 |
&buffer_state, |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
203 |
BUFFER_BUSY, |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
204 |
BUFFER_FREE); |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
205 |
} |
452
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
450
diff
changeset
|
206 |
int WaitDebugData(unsigned long *tick); |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
207 |
/* Wait until debug data ready and return pointer to it */ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
208 |
int GetDebugData(unsigned long *tick, unsigned long *size, void **buffer){ |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
209 |
int res = WaitDebugData(tick); |
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
210 |
*size = buffer_cursor - debug_buffer; |
458
dfc6164e4022
Debugger still doesn't work crash less...
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
452
diff
changeset
|
211 |
*buffer = debug_buffer; |
450
18583d13f0fa
Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents:
423
diff
changeset
|
212 |
return res; |
209
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
213 |
} |
08dc3d064cb5
Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff
changeset
|
214 |