author | laurent |
Fri, 09 Dec 2011 10:01:48 +0100 | |
changeset 393 | f09a5ffe1edc |
parent 392 | 9b88b8b6bccd |
child 394 | 8a04e93f9ef2 |
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; |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
9 |
#define __DECLARE_GLOBAL(type, domain, name)\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
10 |
__IEC_##type##_t domain##__##name;\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
11 |
static __IEC_##type##_t *GLOBAL__##name = &(domain##__##name);\ |
242 | 12 |
void __INIT_GLOBAL_##name(type value) {\ |
13 |
(*GLOBAL__##name).value = value;\ |
|
14 |
}\ |
|
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
15 |
IEC_BYTE __IS_GLOBAL_##name##_FORCED(void) {\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
16 |
return (*GLOBAL__##name).flags & __IEC_FORCE_FLAG;\ |
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;\ |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
25 |
static __IEC_##type##_p *GLOBAL__##name = &(resource##__##name);\ |
242 | 26 |
void __INIT_GLOBAL_##name(type value) {\ |
27 |
*((*GLOBAL__##name).value) = value;\ |
|
28 |
}\ |
|
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
29 |
IEC_BYTE __IS_GLOBAL_##name##_FORCED(void) {\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
30 |
return (*GLOBAL__##name).flags & __IEC_FORCE_FLAG;\ |
242 | 31 |
}\ |
32 |
type* __GET_GLOBAL_##name(void) {\ |
|
33 |
return (*GLOBAL__##name).value;\ |
|
34 |
} |
|
219 | 35 |
#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
|
36 |
__IEC_##type##_p name; |
219 | 37 |
#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
|
38 |
__IEC_##type##_p name; |
219 | 39 |
|
40 |
||
41 |
// variable initialization macros |
|
225 | 42 |
#define __INIT_RETAIN(name, retained)\ |
227 | 43 |
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
|
44 |
#define __INIT_VAR(name, initial, retained)\ |
225 | 45 |
name.value = initial;\ |
46 |
__INIT_RETAIN(name, retained) |
|
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
47 |
#define __INIT_GLOBAL(type, name, initial, retained)\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
48 |
{\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
49 |
static const type temp = initial;\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
50 |
__INIT_GLOBAL_##name(temp);\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
51 |
__INIT_RETAIN((*GLOBAL__##name), retained)\ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
252
diff
changeset
|
52 |
} |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
53 |
#define __INIT_GLOBAL_LOCATED(domain, name, location, retained)\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
54 |
domain##__##name.value = location;\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
55 |
__INIT_RETAIN(domain##__##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
|
56 |
#define __INIT_EXTERNAL(type, global, name, retained)\ |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
57 |
{\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
58 |
extern type* __GET_GLOBAL_##global();\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
59 |
name.value = __GET_GLOBAL_##global();\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
60 |
__INIT_RETAIN(name, retained)\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
61 |
} |
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 |
#define __INIT_LOCATED(type, location, name, retained)\ |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
63 |
{\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
64 |
extern type *location;\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
65 |
name.value = location;\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
66 |
__INIT_RETAIN(name, retained)\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
67 |
} |
219 | 68 |
#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
|
69 |
*(name.value) = initial; |
219 | 70 |
|
71 |
||
72 |
// 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
|
73 |
#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
|
74 |
name.value __VA_ARGS__ |
225 | 75 |
#define __GET_EXTERNAL(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
76 |
((name.flags & __IEC_FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__) |
225 | 77 |
#define __GET_LOCATED(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
78 |
((name.flags & __IEC_FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__) |
235 | 79 |
#define __GET_VAR_BY_REF(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
80 |
((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(name.value __VA_ARGS__)) |
235 | 81 |
#define __GET_EXTERNAL_BY_REF(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
82 |
((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
235 | 83 |
#define __GET_LOCATED_BY_REF(name, ...)\ |
252
0bda13ec66b3
Bug with getter for pointed variables in accessors fixed
laurent
parents:
242
diff
changeset
|
84 |
((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
219 | 85 |
|
86 |
// variable setting macros |
|
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
87 |
#define __SET_VAR(prefix, name, new_value, ...)\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
88 |
if (!(prefix name.flags & __IEC_FORCE_FLAG)) prefix name.value __VA_ARGS__ = new_value |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
89 |
#define __SET_EXTERNAL(prefix, name, new_value, ...)\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
90 |
if (!(prefix name.flags & __IEC_FORCE_FLAG || __IS_GLOBAL_##name##_FORCED()))\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
91 |
(*(prefix name.value)) __VA_ARGS__ = new_value |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
92 |
#define __SET_LOCATED(prefix, name, new_value, ...)\ |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
377
diff
changeset
|
93 |
if (!(prefix name.flags & __IEC_FORCE_FLAG)) *(prefix name.value) __VA_ARGS__ = new_value |
219 | 94 |
|
95 |
#endif //__ACCESSOR_H |