author | Mario de Sousa <msousa@fe.up.pt> |
Mon, 22 Aug 2011 16:08:07 +0100 | |
changeset 358 | a2c4af8f0c18 |
parent 252 | 0bda13ec66b3 |
child 377 | 60b012b7793f |
permissions | -rwxr-xr-x |
219 | 1 |
#ifndef __ACCESSOR_H |
2 |
#define __ACCESSOR_H |
|
3 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
4 |
|
219 | 5 |
// variable declaration macros |
6 |
#define __DECLARE_VAR(type, name)\ |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
7 |
__IEC_##type##_t name; |
219 | 8 |
#define __DECLARE_GLOBAL(type, resource, name)\ |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
9 |
__IEC_##type##_t resource##__##name;\ |
231
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
10 |
static __IEC_##type##_t *GLOBAL__##name = &resource##__##name;\ |
242 | 11 |
void __INIT_GLOBAL_##name(type value) {\ |
12 |
(*GLOBAL__##name).value = value;\ |
|
13 |
}\ |
|
231
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
14 |
void __SET_GLOBAL_##name(type value) {\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
15 |
if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
16 |
(*GLOBAL__##name).value = value;\ |
242 | 17 |
}\ |
18 |
type* __GET_GLOBAL_##name(void) {\ |
|
19 |
return &((*GLOBAL__##name).value);\ |
|
231
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
20 |
} |
219 | 21 |
#define __DECLARE_GLOBAL_LOCATION(type, location)\ |
22 |
extern type *location; |
|
23 |
#define __DECLARE_GLOBAL_LOCATED(type, resource, name)\ |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
24 |
__IEC_##type##_p resource##__##name;\ |
242 | 25 |
static __IEC_##type##_p *GLOBAL__##name = &resource##__##name;\ |
26 |
void __INIT_GLOBAL_##name(type value) {\ |
|
27 |
*((*GLOBAL__##name).value) = value;\ |
|
28 |
}\ |
|
29 |
void __SET_GLOBAL_##name(type value) {\ |
|
30 |
if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\ |
|
31 |
*((*GLOBAL__##name).value) = value;\ |
|
32 |
}\ |
|
33 |
type* __GET_GLOBAL_##name(void) {\ |
|
34 |
return (*GLOBAL__##name).value;\ |
|
35 |
} |
|
219 | 36 |
#define __DECLARE_EXTERNAL(type, name)\ |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
37 |
__IEC_##type##_p name; |
219 | 38 |
#define __DECLARE_LOCATED(type, name)\ |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
39 |
__IEC_##type##_p name; |
219 | 40 |
|
41 |
||
42 |
// variable initialization macros |
|
225 | 43 |
#define __INIT_RETAIN(name, retained)\ |
227 | 44 |
name.flags |= retained?__IEC_RETAIN_FLAG:0; |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
45 |
#define __INIT_VAR(name, initial, retained)\ |
225 | 46 |
name.value = initial;\ |
47 |
__INIT_RETAIN(name, retained) |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
48 |
#define __INIT_GLOBAL(name, initial, retained)\ |
242 | 49 |
__INIT_GLOBAL_##name(initial);\ |
225 | 50 |
__INIT_RETAIN((*GLOBAL__##name), retained) |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
51 |
#define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\ |
225 | 52 |
resource##__##name.value = location;\ |
53 |
__INIT_RETAIN(resource##__##name, retained) |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
54 |
#define __INIT_EXTERNAL(type, global, name, retained)\ |
242 | 55 |
name.value = __GET_GLOBAL_##global();\ |
56 |
__INIT_RETAIN(name, retained) |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
57 |
#define __INIT_LOCATED(type, location, name, retained)\ |
219 | 58 |
{extern type *location;\ |
225 | 59 |
name.value = location;\ |
60 |
__INIT_RETAIN(name, retained)} |
|
219 | 61 |
#define __INIT_LOCATED_VALUE(name, initial)\ |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
62 |
*(name.value) = initial; |
219 | 63 |
|
64 |
||
65 |
// variable getting macros |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
66 |
#define __GET_VAR(name, ...)\ |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
67 |
name.value __VA_ARGS__ |
225 | 68 |
#define __GET_EXTERNAL(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
69 |
((name.flags & __IEC_FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__) |
225 | 70 |
#define __GET_LOCATED(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
71 |
((name.flags & __IEC_FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__) |
235 | 72 |
#define __GET_VAR_BY_REF(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
73 |
((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(name.value __VA_ARGS__)) |
235 | 74 |
#define __GET_EXTERNAL_BY_REF(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
75 |
((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
235 | 76 |
#define __GET_LOCATED_BY_REF(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
77 |
((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
219 | 78 |
|
79 |
// variable setting macros |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
80 |
#define __SET_VAR(name, new_value, ...)\ |
224 | 81 |
if (!(name.flags & __IEC_FORCE_FLAG)) name.value __VA_ARGS__ = new_value |
231
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
82 |
#define __SET_EXTERNAL(global, name, new_value)\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
83 |
if (!(name.flags & __IEC_FORCE_FLAG))\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
84 |
__SET_GLOBAL_##global(new_value) |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
85 |
#define __SET_COMPLEX_EXTERNAL(name, new_value, ...)\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
86 |
*(name.value) __VA_ARGS__ = new_value |
225 | 87 |
#define __SET_LOCATED(name, new_value, ...)\ |
227 | 88 |
if (!(name.flags & __IEC_FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value |
219 | 89 |
|
90 |
#endif //__ACCESSOR_H |