# HG changeset patch # User etisserant # Date 1219161791 -7200 # Node ID 9ceda59abd27aa58778018d94fb944e0053f74cc # Parent 32bd7ef4089716c3a81ce3ce116cd90edf533901 Re-organized types headers, to ease debug code generation diff -r 32bd7ef40897 -r 9ceda59abd27 lib/iec_std_lib.h --- a/lib/iec_std_lib.h Tue Aug 12 16:14:12 2008 +0200 +++ b/lib/iec_std_lib.h Tue Aug 19 18:03:11 2008 +0200 @@ -29,8 +29,6 @@ #include #include -#include "iec_std_lib_generated.h" - #ifdef DEBUG_IEC #define DBG(...) printf(__VA_ARGS__); #define DBG_TYPE(TYPENAME, name) __print_##TYPENAME(name); @@ -39,48 +37,14 @@ #define DBG_TYPE(TYPENAME, name) #endif -/*********************/ -/* IEC Types defs */ -/*********************/ - -/* Include non windows.h clashing typedefs */ -#include "iec_types.h" - -/* Those typdefs clash with windows.h */ -/* i.e. this file cannot be included aside windows.h */ -typedef IEC_BOOL BOOL; - -#define TRUE 1 -#define FALSE 0 - -typedef IEC_SINT SINT; -typedef IEC_INT INT; -typedef IEC_DINT DINT; -typedef IEC_LINT LINT; - -typedef IEC_USINT USINT; -typedef IEC_UINT UINT; -typedef IEC_UDINT UDINT; -typedef IEC_ULINT ULINT; - -typedef IEC_BYTE BYTE; -typedef IEC_WORD WORD; -typedef IEC_DWORD DWORD; -typedef IEC_LWORD LWORD; - -typedef IEC_REAL REAL; -typedef IEC_LREAL LREAL; - -typedef IEC_TIME TIME; -typedef IEC_DATE DATE; -typedef IEC_DT DT; -typedef IEC_TOD TOD; +/* + * Include type defs. + */ +#include "iec_types_all.h" #define __TIME_CMP(t1, t2) (t2.tv_sec == t1.tv_sec ? t1.tv_nsec - t2.tv_nsec : t1.tv_sec - t2.tv_sec) extern TIME __CURRENT_TIME; -typedef IEC_STRING STRING; - #define __STR_CMP(str1, str2) memcmp((char*)&str1.body,(char*)&str2.body, str1.len < str2.len ? str1.len : str2.len) /* TODO @@ -174,21 +138,6 @@ DATE DATEvar; } __IL_DEFVAR_T; -typedef struct { - BOOL state; // current step state. 0 : inative, 1: active - BOOL prev_state; // previous step state. 0 : inative, 1: active - TIME elapsed_time; // time since step is active -} STEP; - -typedef struct { - BOOL stored; // action storing state. 0 : not stored, 1: stored - BOOL state; // current action state. 0 : inative, 1: active - BOOL set; // set have been requested (reset each time the body is evaluated) - BOOL reset; // reset have been requested (reset each time the body is evaluated) - TIME set_remaining_time; // time before set will be requested - TIME reset_remaining_time; // time before reset will be requested -} ACTION; - /*****************/ /* Misc internal */ /*****************/ @@ -1020,47 +969,32 @@ __compare_string(__ne_, != ) - -/********************************/ -/* Type tools */ -/********************************/ -/* Enumerate native types */ -#define __decl_enum_type(TYPENAME) TYPENAME##_ENUM, -typedef enum{ - ANY(__decl_enum_type) -} __IEC_types_enum; - -/* Get size of type from its number */ -#define __decl_size_case(TYPENAME) case TYPENAME##_ENUM: return sizeof(TYPENAME); -static inline USINT __get_type_enum_size(__IEC_types_enum t){ - switch(t){ - ANY(__decl_size_case) - } -} - -/* Get string representation of referenced by void pointer where type is given as its number */ -#define __decl_str_case(cat,TYPENAME) case TYPENAME##_ENUM:return __##cat##_to_string(*(TYPENAME*)p); -#define __decl_str_case_bit(TYPENAME) __decl_str_case(bit,TYPENAME) -#define __decl_str_case_real(TYPENAME) __decl_str_case(real,TYPENAME) -#define __decl_str_case_sint(TYPENAME) __decl_str_case(sint,TYPENAME) -#define __decl_str_case_uint(TYPENAME) __decl_str_case(uint,TYPENAME) -static inline STRING __get_type_enum_str(__IEC_types_enum t, void* p){ - switch(t){ - __decl_str_case(bool,BOOL) - ANY_NBIT(__decl_str_case_bit) - ANY_REAL(__decl_str_case_real) - ANY_SINT(__decl_str_case_sint) - ANY_UINT(__decl_str_case_uint) - __decl_str_case(time,TIME) - __decl_str_case(date,DATE) - __decl_str_case(tod,TOD) - __decl_str_case(dt, DT) - } -} - - - - - - - +///* Get string representation of variable referenced by a void pointer +// * where type is given as its number */ +//#define __decl_str_case(cat,TYPENAME) \ +// case TYPENAME##_ENUM:\ +// return __##cat##_to_string(*(TYPENAME*)p); +//#define __decl_str_case_bit(TYPENAME) __decl_str_case(bit,TYPENAME) +//#define __decl_str_case_real(TYPENAME) __decl_str_case(real,TYPENAME) +//#define __decl_str_case_sint(TYPENAME) __decl_str_case(sint,TYPENAME) +//#define __decl_str_case_uint(TYPENAME) __decl_str_case(uint,TYPENAME) +//static inline STRING __get_type_enum_str(__IEC_types_enum t, void* p){ +// switch(t){ +// __decl_str_case(bool,BOOL) +// ANY_NBIT(__decl_str_case_bit) +// ANY_REAL(__decl_str_case_real) +// ANY_SINT(__decl_str_case_sint) +// ANY_UINT(__decl_str_case_uint) +// __decl_str_case(time,TIME) +// __decl_str_case(date,DATE) +// __decl_str_case(tod,TOD) +// __decl_str_case(dt, DT) +// } +//} +// + + + + + + diff -r 32bd7ef40897 -r 9ceda59abd27 lib/iec_types.h --- a/lib/iec_types.h Tue Aug 12 16:14:12 2008 +0200 +++ b/lib/iec_types.h Tue Aug 19 18:03:11 2008 +0200 @@ -1,3 +1,6 @@ +#ifndef IEC_TYPES_H +#define IEC_TYPES_H + #include #include #include @@ -51,3 +54,4 @@ uint8_t body[STR_MAX_LEN]; } IEC_STRING; +#endif /*IEC_TYPES_H*/ diff -r 32bd7ef40897 -r 9ceda59abd27 lib/iec_types_all.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/iec_types_all.h Tue Aug 19 18:03:11 2008 +0200 @@ -0,0 +1,97 @@ +#ifndef IEC_TYPES_ALL_H +#define IEC_TYPES_ALL_H + +#include "iec_std_lib_generated.h" + +/*********************/ +/* IEC Types defs */ +/*********************/ + +/* Include non windows.h clashing typedefs */ +#include "iec_types.h" + +/* Those typdefs clash with windows.h */ +/* i.e. this file cannot be included aside windows.h */ +typedef IEC_BOOL BOOL; + +#define TRUE 1 +#define FALSE 0 + +typedef IEC_SINT SINT; +typedef IEC_INT INT; +typedef IEC_DINT DINT; +typedef IEC_LINT LINT; + +typedef IEC_USINT USINT; +typedef IEC_UINT UINT; +typedef IEC_UDINT UDINT; +typedef IEC_ULINT ULINT; + +typedef IEC_BYTE BYTE; +typedef IEC_WORD WORD; +typedef IEC_DWORD DWORD; +typedef IEC_LWORD LWORD; + +typedef IEC_REAL REAL; +typedef IEC_LREAL LREAL; + +typedef IEC_TIME TIME; +typedef IEC_DATE DATE; +typedef IEC_DT DT; +typedef IEC_TOD TOD; + +typedef IEC_STRING STRING; + +typedef struct { + BOOL state; // current step state. 0 : inative, 1: active + BOOL prev_state; // previous step state. 0 : inative, 1: active + TIME elapsed_time; // time since step is active +} STEP; + +typedef struct { + BOOL stored; // action storing state. 0 : not stored, 1: stored + BOOL state; // current action state. 0 : inative, 1: active + BOOL set; // set have been requested (reset each time the body is evaluated) + BOOL reset; // reset have been requested (reset each time the body is evaluated) + TIME set_remaining_time; // time before set will be requested + TIME reset_remaining_time; // time before reset will be requested +} ACTION; + +/* Extra debug types for SFC */ +#define ANY_SFC(DO) DO(STEP) DO(TRANSITION) DO(ACTION) + +/* Enumerate native types */ +#define __decl_enum_type(TYPENAME) TYPENAME##_ENUM, +typedef enum{ + ANY(__decl_enum_type) + ANY_SFC(__decl_enum_type) + /*TODO handle custom types*/ +} __IEC_types_enum; + +/* Get size of type from its number */ +#define __decl_size_case(TYPENAME) case TYPENAME##_ENUM: return sizeof(TYPENAME); +#define __decl_size_case_force_BOOL(TYPENAME) case TYPENAME##_ENUM: return sizeof(BOOL); +static inline USINT __get_type_enum_size(__IEC_types_enum t){ + switch(t){ + ANY(__decl_size_case) + /* size do not correspond to real struct. + * only a bool is used to represent state*/ + ANY_SFC(__decl_size_case_force_BOOL) + /*TODO handle custom types*/ + } +} + +/* Get name of type from its number */ +#define __decl_typename_case(TYPENAME) case TYPENAME##_ENUM: return #TYPENAME ; +static inline const char* __get_type_enum_name(__IEC_types_enum t){ + switch(t){ + ANY(__decl_typename_case) + /* size do not correspond to real struct. + * only a bool is used to represent state*/ + ANY_SFC(__decl_typename_case) + /*TODO handle custom types*/ + } +} + + +#endif /*IEC_TYPES_ALL_H*/