author | laurent |
Sat, 05 Dec 2009 18:38:53 +0100 | |
changeset 226 | 29f8ffc203c1 |
parent 225 | 36d05588f91b |
child 227 | 560c1231ad1f |
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;\ |
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 |
static __IEC_##type##_t *GLOBAL__##name = &resource##__##name; |
219 | 11 |
#define __DECLARE_GLOBAL_LOCATION(type, location)\ |
12 |
extern type *location; |
|
13 |
#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
|
14 |
__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
|
15 |
static __IEC_##type##_p *GLOBAL__##name; |
219 | 16 |
#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
|
17 |
__IEC_##type##_p name; |
219 | 18 |
#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
|
19 |
__IEC_##type##_p name; |
219 | 20 |
|
21 |
||
22 |
// variable initialization macros |
|
225 | 23 |
#define __INIT_RETAIN(name, retained)\ |
24 |
name.flags |= retained?__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
|
25 |
#define __INIT_VAR(name, initial, retained)\ |
225 | 26 |
name.value = initial;\ |
27 |
__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
|
28 |
#define __INIT_GLOBAL(name, initial, retained)\ |
225 | 29 |
(*GLOBAL__##name).value = initial;\ |
30 |
__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
|
31 |
#define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\ |
225 | 32 |
resource##__##name.value = location;\ |
33 |
__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
|
34 |
#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
|
35 |
{extern __IEC_##type##_t *GLOBAL__##global;\ |
225 | 36 |
name.value = &((*GLOBAL__##global).value);\ |
37 |
__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
|
38 |
#define __INIT_LOCATED(type, location, name, retained)\ |
219 | 39 |
{extern type *location;\ |
225 | 40 |
name.value = location;\ |
41 |
__INIT_RETAIN(name, retained)} |
|
219 | 42 |
#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
|
43 |
*(name.value) = initial; |
219 | 44 |
|
45 |
||
46 |
// 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
|
47 |
#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
|
48 |
name.value __VA_ARGS__ |
225 | 49 |
#define __GET_EXTERNAL(name, ...)\ |
50 |
(name.flags & __FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__ |
|
51 |
#define __GET_LOCATED(name, ...)\ |
|
52 |
(name.flags & __FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__ |
|
219 | 53 |
#define __GET_VAR_BY_REF(name)\ |
54 |
&(name) |
|
55 |
#define __GET_EXTERNAL_BY_REF(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
|
56 |
name.value |
219 | 57 |
#define __GET_LOCATED_BY_REF(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
|
58 |
name.value |
219 | 59 |
|
60 |
// 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
|
61 |
#define __SET_VAR(name, new_value, ...)\ |
225 | 62 |
if (!(name.flags & __FORCE_FLAG)) name.value __VA_ARGS__ = new_value |
63 |
#define __SET_EXTERNAL(name, new_value, ...)\ |
|
64 |
if (!(name.flags & __FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value |
|
65 |
#define __SET_LOCATED(name, new_value, ...)\ |
|
66 |
if (!(name.flags & __FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value |
|
219 | 67 |
|
68 |
#endif //__ACCESSOR_H |