author | laurent |
Thu, 22 Apr 2010 07:03:18 +0200 | |
changeset 240 | f78fa87bb4cb |
parent 235 | ed66dc50f31a |
child 242 | 0036357a990f |
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;\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
11 |
void __SET_GLOBAL_##name(type value) {\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
12 |
if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
13 |
(*GLOBAL__##name).value = value;\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
14 |
} |
219 | 15 |
#define __DECLARE_GLOBAL_LOCATION(type, location)\ |
16 |
extern type *location; |
|
17 |
#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
|
18 |
__IEC_##type##_p resource##__##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
|
19 |
static __IEC_##type##_p *GLOBAL__##name; |
219 | 20 |
#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
|
21 |
__IEC_##type##_p name; |
219 | 22 |
#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
|
23 |
__IEC_##type##_p name; |
219 | 24 |
|
25 |
||
26 |
// variable initialization macros |
|
225 | 27 |
#define __INIT_RETAIN(name, retained)\ |
227 | 28 |
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
|
29 |
#define __INIT_VAR(name, initial, retained)\ |
225 | 30 |
name.value = initial;\ |
31 |
__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
|
32 |
#define __INIT_GLOBAL(name, initial, retained)\ |
225 | 33 |
(*GLOBAL__##name).value = initial;\ |
34 |
__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
|
35 |
#define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\ |
225 | 36 |
resource##__##name.value = location;\ |
37 |
__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
|
38 |
#define __INIT_EXTERNAL(type, global, name, retained)\ |
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 |
{extern __IEC_##type##_t *GLOBAL__##global;\ |
225 | 40 |
name.value = &((*GLOBAL__##global).value);\ |
41 |
__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
|
42 |
#define __INIT_LOCATED(type, location, name, retained)\ |
219 | 43 |
{extern type *location;\ |
225 | 44 |
name.value = location;\ |
45 |
__INIT_RETAIN(name, retained)} |
|
219 | 46 |
#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
|
47 |
*(name.value) = initial; |
219 | 48 |
|
49 |
||
50 |
// 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
|
51 |
#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
|
52 |
name.value __VA_ARGS__ |
225 | 53 |
#define __GET_EXTERNAL(name, ...)\ |
227 | 54 |
(name.flags & __IEC_FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__ |
225 | 55 |
#define __GET_LOCATED(name, ...)\ |
227 | 56 |
(name.flags & __IEC_FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__ |
235 | 57 |
#define __GET_VAR_BY_REF(name, ...)\ |
58 |
(name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(name.value __VA_ARGS__) |
|
59 |
#define __GET_EXTERNAL_BY_REF(name, ...)\ |
|
60 |
(name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__) |
|
61 |
#define __GET_LOCATED_BY_REF(name, ...)\ |
|
62 |
(name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__) |
|
219 | 63 |
|
64 |
// 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
|
65 |
#define __SET_VAR(name, new_value, ...)\ |
224 | 66 |
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
|
67 |
#define __SET_EXTERNAL(global, name, new_value)\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
68 |
if (!(name.flags & __IEC_FORCE_FLAG))\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
69 |
__SET_GLOBAL_##global(new_value) |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
70 |
#define __SET_COMPLEX_EXTERNAL(name, new_value, ...)\ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
227
diff
changeset
|
71 |
*(name.value) __VA_ARGS__ = new_value |
225 | 72 |
#define __SET_LOCATED(name, new_value, ...)\ |
227 | 73 |
if (!(name.flags & __IEC_FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value |
219 | 74 |
|
75 |
#endif //__ACCESSOR_H |