lib/accessor.h
author edouard
Fri, 04 Dec 2009 15:11:16 +0100
changeset 223 a09ed6620a7d
parent 222 8b1757417a54
child 224 270ba3d91e59
child 225 36d05588f91b
permissions -rwxr-xr-x
fixed cygwin build - still slooooooooow
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
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
#define __INIT_STRUCT(name, initial, 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
    24
    name.value = initial;\
222
8b1757417a54 Adding Flags bit symbols
laurent
parents: 221
diff changeset
    25
	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
    26
#define __INIT_VAR(name, initial, 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
    27
	__INIT_STRUCT(name, initial, 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
    28
#define __INIT_GLOBAL(name, initial, 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
    29
	__INIT_STRUCT((*GLOBAL__##name), initial, 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
    30
#define __INIT_GLOBAL_LOCATED(resource, name, location, 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
    31
	__INIT_STRUCT(resource##__##name, location, 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
    32
#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
    33
	{extern __IEC_##type##_t *GLOBAL__##global;\
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
	 __INIT_STRUCT(name, &((*GLOBAL__##global).value), 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
#define __INIT_LOCATED(type, location, name, retained)\
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    36
	{extern type *location;\
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
    37
	 __INIT_STRUCT(name, location, retained)}
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    38
#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
    39
	*(name.value) = initial;
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    40
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    41
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    42
// 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
    43
#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
    44
	name.value __VA_ARGS__
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    45
#define __GET_EXTERNAL(name)\
222
8b1757417a54 Adding Flags bit symbols
laurent
parents: 221
diff changeset
    46
	name.flags & FORCE_FLAG ? name.fvalue : *(name.value)
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    47
#define __GET_LOCATED(name)\
222
8b1757417a54 Adding Flags bit symbols
laurent
parents: 221
diff changeset
    48
	name.flags & FORCE_FLAG ? name.fvalue : *(name.value)
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    49
#define __GET_VAR_BY_REF(name)\
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    50
	&(name)
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    51
#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
    52
	name.value
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    53
#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
    54
	name.value
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    55
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    56
// 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
    57
#define __SET_VAR(name, new_value, ...)\
222
8b1757417a54 Adding Flags bit symbols
laurent
parents: 221
diff changeset
    58
	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
    59
#define __SET_EXTERNAL(name, new_value)\
222
8b1757417a54 Adding Flags bit symbols
laurent
parents: 221
diff changeset
    60
	if (!(name.flags & FORCE_FLAG)) *(name.value) = new_value
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    61
#define __SET_LOCATED(name, new_value)\
222
8b1757417a54 Adding Flags bit symbols
laurent
parents: 221
diff changeset
    62
	if (!(name.flags & FORCE_FLAG)) *(name.value) = new_value
219
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    63
9bb38736f126 Adding support for declare, init, get and set macros
laurent
parents:
diff changeset
    64
#endif //__ACCESSOR_H