lib/accessor.h
changeset 242 0036357a990f
parent 235 ed66dc50f31a
child 252 0bda13ec66b3
equal deleted inserted replaced
241:0ba6d614573e 242:0036357a990f
     6 #define __DECLARE_VAR(type, name)\
     6 #define __DECLARE_VAR(type, name)\
     7 	__IEC_##type##_t name;
     7 	__IEC_##type##_t name;
     8 #define __DECLARE_GLOBAL(type, resource, name)\
     8 #define __DECLARE_GLOBAL(type, resource, name)\
     9 	__IEC_##type##_t resource##__##name;\
     9 	__IEC_##type##_t resource##__##name;\
    10 	static __IEC_##type##_t *GLOBAL__##name = &resource##__##name;\
    10 	static __IEC_##type##_t *GLOBAL__##name = &resource##__##name;\
       
    11 	void __INIT_GLOBAL_##name(type value) {\
       
    12 		(*GLOBAL__##name).value = value;\
       
    13 	}\
    11 	void __SET_GLOBAL_##name(type value) {\
    14 	void __SET_GLOBAL_##name(type value) {\
    12 		if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\
    15 		if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\
    13 			(*GLOBAL__##name).value = value;\
    16 			(*GLOBAL__##name).value = value;\
       
    17 	}\
       
    18 	type* __GET_GLOBAL_##name(void) {\
       
    19 		return &((*GLOBAL__##name).value);\
    14 	}
    20 	}
    15 #define __DECLARE_GLOBAL_LOCATION(type, location)\
    21 #define __DECLARE_GLOBAL_LOCATION(type, location)\
    16 	extern type *location;
    22 	extern type *location;
    17 #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\
    23 #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\
    18 	__IEC_##type##_p resource##__##name;\
    24 	__IEC_##type##_p resource##__##name;\
    19 	static __IEC_##type##_p *GLOBAL__##name;
    25 	static __IEC_##type##_p *GLOBAL__##name = &resource##__##name;\
       
    26 	void __INIT_GLOBAL_##name(type value) {\
       
    27 		*((*GLOBAL__##name).value) = value;\
       
    28 	}\
       
    29 	void __SET_GLOBAL_##name(type value) {\
       
    30 		if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\
       
    31 			*((*GLOBAL__##name).value) = value;\
       
    32 	}\
       
    33 	type* __GET_GLOBAL_##name(void) {\
       
    34 		return (*GLOBAL__##name).value;\
       
    35 	}
    20 #define __DECLARE_EXTERNAL(type, name)\
    36 #define __DECLARE_EXTERNAL(type, name)\
    21 	__IEC_##type##_p name;
    37 	__IEC_##type##_p name;
    22 #define __DECLARE_LOCATED(type, name)\
    38 #define __DECLARE_LOCATED(type, name)\
    23 	__IEC_##type##_p name;
    39 	__IEC_##type##_p name;
    24 
    40 
    28     name.flags |= retained?__IEC_RETAIN_FLAG:0;
    44     name.flags |= retained?__IEC_RETAIN_FLAG:0;
    29 #define __INIT_VAR(name, initial, retained)\
    45 #define __INIT_VAR(name, initial, retained)\
    30 	name.value = initial;\
    46 	name.value = initial;\
    31 	__INIT_RETAIN(name, retained)
    47 	__INIT_RETAIN(name, retained)
    32 #define __INIT_GLOBAL(name, initial, retained)\
    48 #define __INIT_GLOBAL(name, initial, retained)\
    33 	(*GLOBAL__##name).value = initial;\
    49 	__INIT_GLOBAL_##name(initial);\
    34 	__INIT_RETAIN((*GLOBAL__##name), retained)
    50 	__INIT_RETAIN((*GLOBAL__##name), retained)
    35 #define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\
    51 #define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\
    36 	resource##__##name.value = location;\
    52 	resource##__##name.value = location;\
    37 	__INIT_RETAIN(resource##__##name, retained)
    53 	__INIT_RETAIN(resource##__##name, retained)
    38 #define __INIT_EXTERNAL(type, global, name, retained)\
    54 #define __INIT_EXTERNAL(type, global, name, retained)\
    39 	{extern __IEC_##type##_t *GLOBAL__##global;\
    55 	name.value = __GET_GLOBAL_##global();\
    40 	 name.value = &((*GLOBAL__##global).value);\
    56     __INIT_RETAIN(name, retained)
    41      __INIT_RETAIN(name, retained)}
       
    42 #define __INIT_LOCATED(type, location, name, retained)\
    57 #define __INIT_LOCATED(type, location, name, retained)\
    43 	{extern type *location;\
    58 	{extern type *location;\
    44 	 name.value = location;\
    59 	 name.value = location;\
    45 	 __INIT_RETAIN(name, retained)}
    60 	 __INIT_RETAIN(name, retained)}
    46 #define __INIT_LOCATED_VALUE(name, initial)\
    61 #define __INIT_LOCATED_VALUE(name, initial)\