author | laurent |
Fri, 04 Nov 2011 18:40:58 +0100 | |
changeset 388 | 17eaad42ba88 |
parent 377 | 60b012b7793f |
child 392 | 9b88b8b6bccd |
permissions | -rwxr-xr-x |
219 | 1 |
#ifndef __ACCESSOR_H |
2 |
#define __ACCESSOR_H |
|
3 |
||
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
4 |
#define __INITIAL_VALUE(...) __VA_ARGS__ |
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
|
5 |
|
219 | 6 |
// variable declaration macros |
7 |
#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
|
8 |
__IEC_##type##_t name; |
219 | 9 |
#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
|
10 |
__IEC_##type##_t resource##__##name;\ |
231
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
11 |
static __IEC_##type##_t *GLOBAL__##name = &resource##__##name;\ |
242 | 12 |
void __INIT_GLOBAL_##name(type value) {\ |
13 |
(*GLOBAL__##name).value = value;\ |
|
14 |
}\ |
|
231
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
15 |
void __SET_GLOBAL_##name(type value) {\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
16 |
if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
17 |
(*GLOBAL__##name).value = value;\ |
242 | 18 |
}\ |
19 |
type* __GET_GLOBAL_##name(void) {\ |
|
20 |
return &((*GLOBAL__##name).value);\ |
|
231
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
21 |
} |
219 | 22 |
#define __DECLARE_GLOBAL_LOCATION(type, location)\ |
23 |
extern type *location; |
|
24 |
#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
|
25 |
__IEC_##type##_p resource##__##name;\ |
242 | 26 |
static __IEC_##type##_p *GLOBAL__##name = &resource##__##name;\ |
27 |
void __INIT_GLOBAL_##name(type value) {\ |
|
28 |
*((*GLOBAL__##name).value) = value;\ |
|
29 |
}\ |
|
30 |
void __SET_GLOBAL_##name(type value) {\ |
|
31 |
if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\ |
|
32 |
*((*GLOBAL__##name).value) = value;\ |
|
33 |
}\ |
|
34 |
type* __GET_GLOBAL_##name(void) {\ |
|
35 |
return (*GLOBAL__##name).value;\ |
|
36 |
} |
|
219 | 37 |
#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
|
38 |
__IEC_##type##_p name; |
219 | 39 |
#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
|
40 |
__IEC_##type##_p name; |
219 | 41 |
|
42 |
||
43 |
// variable initialization macros |
|
225 | 44 |
#define __INIT_RETAIN(name, retained)\ |
227 | 45 |
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
|
46 |
#define __INIT_VAR(name, initial, retained)\ |
225 | 47 |
name.value = initial;\ |
48 |
__INIT_RETAIN(name, retained) |
|
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
49 |
#define __INIT_GLOBAL(type, name, initial, retained)\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
50 |
{\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
51 |
static const type temp = initial;\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
52 |
__INIT_GLOBAL_##name(temp);\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
53 |
__INIT_RETAIN((*GLOBAL__##name), retained)\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
54 |
} |
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
|
55 |
#define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\ |
225 | 56 |
resource##__##name.value = location;\ |
57 |
__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
|
58 |
#define __INIT_EXTERNAL(type, global, name, retained)\ |
242 | 59 |
name.value = __GET_GLOBAL_##global();\ |
60 |
__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
|
61 |
#define __INIT_LOCATED(type, location, name, retained)\ |
219 | 62 |
{extern type *location;\ |
225 | 63 |
name.value = location;\ |
64 |
__INIT_RETAIN(name, retained)} |
|
219 | 65 |
#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
|
66 |
*(name.value) = initial; |
219 | 67 |
|
68 |
||
69 |
// 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
|
70 |
#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
|
71 |
name.value __VA_ARGS__ |
225 | 72 |
#define __GET_EXTERNAL(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__) |
225 | 74 |
#define __GET_LOCATED(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_VAR_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__)) |
235 | 78 |
#define __GET_EXTERNAL_BY_REF(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
79 |
((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
235 | 80 |
#define __GET_LOCATED_BY_REF(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
81 |
((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
219 | 82 |
|
83 |
// 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
|
84 |
#define __SET_VAR(name, new_value, ...)\ |
224 | 85 |
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
|
86 |
#define __SET_EXTERNAL(global, name, new_value)\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
87 |
if (!(name.flags & __IEC_FORCE_FLAG))\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
88 |
__SET_GLOBAL_##global(new_value) |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
89 |
#define __SET_COMPLEX_EXTERNAL(name, new_value, ...)\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
90 |
*(name.value) __VA_ARGS__ = new_value |
225 | 91 |
#define __SET_LOCATED(name, new_value, ...)\ |
227 | 92 |
if (!(name.flags & __IEC_FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value |
219 | 93 |
|
94 |
#endif //__ACCESSOR_H |