lib/iec_types_all.h
changeset 258 d7d92b2f87e9
parent 246 e8b5b163804d
child 301 15bf9ecb936d
equal deleted inserted replaced
257:90782e241346 258:d7d92b2f87e9
     8 /*********************/
     8 /*********************/
     9 
     9 
    10 /* Include non windows.h clashing typedefs */
    10 /* Include non windows.h clashing typedefs */
    11 #include "iec_types.h"
    11 #include "iec_types.h"
    12 
    12 
    13 /* Those typdefs clash with windows.h */
       
    14 /* i.e. this file cannot be included aside windows.h */
       
    15 typedef IEC_BOOL  BOOL;
       
    16 
       
    17 #define TRUE 1
    13 #define TRUE 1
    18 #define FALSE 0
    14 #define FALSE 0
    19 
    15 
    20 typedef IEC_SINT    SINT;
    16 #define __IEC_DEBUG_FLAG 0x01
    21 typedef IEC_INT   INT;
    17 #define __IEC_FORCE_FLAG 0x02
    22 typedef IEC_DINT   DINT;
    18 #define __IEC_RETAIN_FLAG 0x04
    23 typedef IEC_LINT   LINT;
       
    24 
    19 
    25 typedef IEC_USINT    USINT;
    20 #define __DECLARE_IEC_TYPE(type)\
    26 typedef IEC_UINT   UINT;
    21 typedef IEC_##type type;\
    27 typedef IEC_UDINT   UDINT;
    22 \
    28 typedef IEC_ULINT   ULINT;
    23 typedef struct {\
       
    24   IEC_##type value;\
       
    25   IEC_BYTE flags;\
       
    26 } __IEC_##type##_t;\
       
    27 \
       
    28 typedef struct {\
       
    29   IEC_##type *value;\
       
    30   IEC_BYTE flags;\
       
    31   IEC_##type fvalue;\
       
    32 } __IEC_##type##_p;
    29 
    33 
    30 typedef IEC_BYTE    BYTE;
    34 #define __DECLARE_DERIVED_TYPE(base, type)\
    31 typedef IEC_WORD   WORD;
    35 typedef base type;\
    32 typedef IEC_DWORD   DWORD;
    36 typedef __IEC_##base##_t __IEC_##type##_t;
    33 typedef IEC_LWORD   LWORD;
       
    34 
    37 
    35 typedef IEC_REAL    REAL;
    38 #define __DECLARE_COMPLEX_STRUCT(type)\
    36 typedef IEC_LREAL   LREAL;
    39 typedef struct {\
       
    40   type value;\
       
    41   IEC_BYTE flags;\
       
    42 } __IEC_##type##_t;\
       
    43 \
       
    44 typedef struct {\
       
    45   type *value;\
       
    46   IEC_BYTE flags;\
       
    47 } __IEC_##type##_p;
    37 
    48 
    38 typedef IEC_TIME TIME;
    49 #define __DECLARE_ARRAY_TYPE(base, type, size)\
    39 typedef IEC_DATE DATE;
    50 typedef struct {\
    40 typedef IEC_DT DT;
    51   base table size;\
    41 typedef IEC_TOD TOD;
    52 } type;\
       
    53 __DECLARE_COMPLEX_STRUCT(type);
    42 
    54 
    43 typedef IEC_STRING STRING;
    55 #define __DECLARE_STRUCT_TYPE(elements, type)\
       
    56 typedef elements type;\
       
    57 __DECLARE_COMPLEX_STRUCT(type);
       
    58 
       
    59 /* Those typdefs clash with windows.h */
       
    60 /* i.e. this file cannot be included aside windows.h */
       
    61 ANY(__DECLARE_IEC_TYPE)
    44 
    62 
    45 typedef struct {
    63 typedef struct {
    46   BOOL state;     // current step state. 0 : inative, 1: active
    64   __IEC_BOOL_t state;     // current step state. 0 : inative, 1: active
    47   BOOL prev_state;  // previous step state. 0 : inative, 1: active
    65   BOOL prev_state;  // previous step state. 0 : inative, 1: active
    48   TIME elapsed_time;  // time since step is active
    66   TIME elapsed_time;  // time since step is active
    49 } STEP;
    67 } STEP;
    50 
    68 
    51 typedef struct {
    69 typedef struct {
    60 /* Extra debug types for SFC */
    78 /* Extra debug types for SFC */
    61 #define ANY_SFC(DO) DO(STEP) DO(TRANSITION) DO(ACTION)
    79 #define ANY_SFC(DO) DO(STEP) DO(TRANSITION) DO(ACTION)
    62 
    80 
    63 /* Enumerate native types */
    81 /* Enumerate native types */
    64 #define __decl_enum_type(TYPENAME) TYPENAME##_ENUM,
    82 #define __decl_enum_type(TYPENAME) TYPENAME##_ENUM,
       
    83 #define __decl_enum_pointer(TYPENAME) TYPENAME##_P_ENUM,
       
    84 #define __decl_enum_output(TYPENAME) TYPENAME##_O_ENUM,
    65 typedef enum{
    85 typedef enum{
    66   ANY(__decl_enum_type)
    86   ANY(__decl_enum_type)
    67   ANY_SFC(__decl_enum_type)
    87   ANY(__decl_enum_pointer)
    68   /*TODO handle custom types*/
    88   ANY(__decl_enum_output)
       
    89   /* SFC specific types are never external or global */
       
    90   UNKNOWN_ENUM
    69 } __IEC_types_enum;
    91 } __IEC_types_enum;
    70 
    92 
    71 /* Get size of type from its number */
    93 /* Get size of type from its number */
    72 #define __decl_size_case(TYPENAME) case TYPENAME##_ENUM: return sizeof(TYPENAME);
    94 #define __decl_size_case(TYPENAME) \
    73 #define __decl_size_case_force_BOOL(TYPENAME) case TYPENAME##_ENUM: return sizeof(BOOL);
    95 	case TYPENAME##_ENUM:\
       
    96 	case TYPENAME##_O_ENUM:\
       
    97 	case TYPENAME##_P_ENUM:\
       
    98 		return sizeof(TYPENAME);
    74 static inline USINT __get_type_enum_size(__IEC_types_enum t){
    99 static inline USINT __get_type_enum_size(__IEC_types_enum t){
    75  switch(t){
   100  switch(t){
    76   ANY(__decl_size_case)
   101   ANY(__decl_size_case)
    77   /* size do not correspond to real struct.
   102   /* size do not correspond to real struct.
    78    * only a bool is used to represent state*/
   103    * only a bool is used to represent state*/
    79   ANY_SFC(__decl_size_case_force_BOOL)
   104   default:
    80   /*TODO handle custom types*/
   105 	  return 0;
    81  }
   106  }
       
   107  return 0;
    82 }
   108 }
    83 
   109 
    84 /* Get name of type from its number */
       
    85 #define __decl_typename_case(TYPENAME) case TYPENAME##_ENUM: return #TYPENAME ;
       
    86 static inline const char* __get_type_enum_name(__IEC_types_enum t){
       
    87  switch(t){
       
    88   ANY(__decl_typename_case)
       
    89   /* size do not correspond to real struct.
       
    90    * only a bool is used to represent state*/
       
    91   ANY_SFC(__decl_typename_case)
       
    92   /*TODO handle custom types*/
       
    93  }
       
    94 }
       
    95 
       
    96 
       
    97 #endif /*IEC_TYPES_ALL_H*/
   110 #endif /*IEC_TYPES_ALL_H*/