lib/accessor.h
author laurent
Sat, 05 Dec 2009 18:38:53 +0100
changeset 226 29f8ffc203c1
parent 225 36d05588f91b
child 227 560c1231ad1f
permissions -rwxr-xr-x
Adding support for setter and getter on complex datatype in ST
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     1
#ifndef __ACCESSOR_H
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     2
#define __ACCESSOR_H
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     5
// variable declaration macros
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
     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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    11
#define __DECLARE_GLOBAL_LOCATION(type, location)\
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    12
	extern type *location;
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    20
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    21
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    22
// variable initialization macros
225
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    23
#define __INIT_RETAIN(name, retained)\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    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
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    26
	name.value = initial;\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    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
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    29
	(*GLOBAL__##name).value = initial;\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    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
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    32
	resource##__##name.value = location;\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    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
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    36
	 name.value = &((*GLOBAL__##global).value);\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    39
	{extern type *location;\
225
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    40
	 name.value = location;\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    41
	 __INIT_RETAIN(name, retained)}
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    44
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    45
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    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
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    49
#define __GET_EXTERNAL(name, ...)\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    50
	(name.flags & __FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    51
#define __GET_LOCATED(name, ...)\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    52
	(name.flags & __FORCE_FLAG) ? name.fvalue __VA_ARGS__ : *(name.value) __VA_ARGS__
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    53
#define __GET_VAR_BY_REF(name)\
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    54
	&(name)
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    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
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    59
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    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
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    62
	if (!(name.flags & __FORCE_FLAG)) name.value __VA_ARGS__ = new_value
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    63
#define __SET_EXTERNAL(name, new_value, ...)\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    64
	if (!(name.flags & __FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    65
#define __SET_LOCATED(name, new_value, ...)\
36d05588f91b Fix accessor code
laurent
parents: 222
diff changeset
    66
	if (!(name.flags & __FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    67
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    68
#endif //__ACCESSOR_H