lib/iec_types_all.h
changeset 224 270ba3d91e59
parent 222 8b1757417a54
child 227 560c1231ad1f
equal deleted inserted replaced
223:a09ed6620a7d 224:270ba3d91e59
    11 #include "iec_types.h"
    11 #include "iec_types.h"
    12 
    12 
    13 #define TRUE 1
    13 #define TRUE 1
    14 #define FALSE 0
    14 #define FALSE 0
    15 
    15 
    16 #define DEBUG_FLAG 1
    16 #define __IEC_DEBUG_FLAG 0x01
    17 #define FORCE_FLAG 2
    17 #define __IEC_FORCE_FLAG 0x02
    18 #define RETAIN_FLAG 4
    18 #define __IEC_RETAIN_FLAG 0x04
    19 
    19 
    20 #define __DECLARE_IEC_TYPE(type)\
    20 #define __DECLARE_IEC_TYPE(type)\
    21 typedef IEC_##type type;\
    21 typedef IEC_##type type;\
    22 \
    22 \
    23 typedef struct {\
    23 typedef struct {\
    56 
    56 
    57 /* Those typdefs clash with windows.h */
    57 /* Those typdefs clash with windows.h */
    58 /* i.e. this file cannot be included aside windows.h */
    58 /* i.e. this file cannot be included aside windows.h */
    59 ANY(__DECLARE_IEC_TYPE)
    59 ANY(__DECLARE_IEC_TYPE)
    60 
    60 
    61 
       
    62 /*
       
    63 typedef IEC_BOOL  BOOL;
       
    64 
       
    65 typedef IEC_SINT    SINT;
       
    66 typedef IEC_INT   INT;
       
    67 typedef IEC_DINT   DINT;
       
    68 typedef IEC_LINT   LINT;
       
    69 
       
    70 typedef IEC_USINT    USINT;
       
    71 typedef IEC_UINT   UINT;
       
    72 typedef IEC_UDINT   UDINT;
       
    73 typedef IEC_ULINT   ULINT;
       
    74 
       
    75 typedef IEC_BYTE    BYTE;
       
    76 typedef IEC_WORD   WORD;
       
    77 typedef IEC_DWORD   DWORD;
       
    78 typedef IEC_LWORD   LWORD;
       
    79 
       
    80 typedef IEC_REAL    REAL;
       
    81 typedef IEC_LREAL   LREAL;
       
    82 
       
    83 typedef IEC_TIME TIME;
       
    84 typedef IEC_DATE DATE;
       
    85 typedef IEC_DT DT;
       
    86 typedef IEC_TOD TOD;
       
    87 
       
    88 typedef IEC_STRING STRING;
       
    89 */
       
    90 
       
    91 typedef struct {
    61 typedef struct {
    92   __IEC_BOOL_t state;     // current step state. 0 : inative, 1: active
    62   __IEC_BOOL_t state;     // current step state. 0 : inative, 1: active
    93   BOOL prev_state;  // previous step state. 0 : inative, 1: active
    63   BOOL prev_state;  // previous step state. 0 : inative, 1: active
    94   TIME elapsed_time;  // time since step is active
    64   TIME elapsed_time;  // time since step is active
    95 } STEP;
    65 } STEP;
   106 /* Extra debug types for SFC */
    76 /* Extra debug types for SFC */
   107 #define ANY_SFC(DO) DO(STEP) DO(TRANSITION) DO(ACTION)
    77 #define ANY_SFC(DO) DO(STEP) DO(TRANSITION) DO(ACTION)
   108 
    78 
   109 /* Enumerate native types */
    79 /* Enumerate native types */
   110 #define __decl_enum_type(TYPENAME) TYPENAME##_ENUM,
    80 #define __decl_enum_type(TYPENAME) TYPENAME##_ENUM,
       
    81 #define __decl_enum_pointer(TYPENAME) TYPENAME##_P_ENUM,
   111 typedef enum{
    82 typedef enum{
   112   ANY(__decl_enum_type)
    83   ANY(__decl_enum_type)
   113   ANY_SFC(__decl_enum_type)
    84   ANY(__decl_enum_pointer)
   114   /*TODO handle custom types*/
    85   /* SFC specific types are never external or global */
       
    86   UNKNOWN_ENUM
   115 } __IEC_types_enum;
    87 } __IEC_types_enum;
   116 
    88 
   117 /* Get size of type from its number */
    89 /* Get size of type from its number */
   118 #define __decl_size_case(TYPENAME) case TYPENAME##_ENUM: return sizeof(TYPENAME);
    90 #define __decl_size_case(TYPENAME) \
   119 #define __decl_size_case_force_BOOL(TYPENAME) case TYPENAME##_ENUM: return sizeof(BOOL);
    91 	case TYPENAME##_ENUM:\
       
    92 	case TYPENAME##_P_ENUM:\
       
    93 		return sizeof(TYPENAME);
   120 static inline USINT __get_type_enum_size(__IEC_types_enum t){
    94 static inline USINT __get_type_enum_size(__IEC_types_enum t){
   121  switch(t){
    95  switch(t){
   122   ANY(__decl_size_case)
    96   ANY(__decl_size_case)
   123   /* size do not correspond to real struct.
    97   /* size do not correspond to real struct.
   124    * only a bool is used to represent state*/
    98    * only a bool is used to represent state*/
   125   ANY_SFC(__decl_size_case_force_BOOL)
    99   default:
   126   /*TODO handle custom types*/
   100 	  return 0;
   127  }
   101  }
   128  return 0;
   102  return 0;
   129 }
   103 }
   130 
   104 
   131 /* Get name of type from its number */
       
   132 #define __decl_typename_case(TYPENAME) case TYPENAME##_ENUM: return #TYPENAME ;
       
   133 static inline const char* __get_type_enum_name(__IEC_types_enum t){
       
   134  switch(t){
       
   135   ANY(__decl_typename_case)
       
   136   /* size do not correspond to real struct.
       
   137    * only a bool is used to represent state*/
       
   138   ANY_SFC(__decl_typename_case)
       
   139   /*TODO handle custom types*/
       
   140  }
       
   141  return 0;
       
   142 }
       
   143 
       
   144 
       
   145 #endif /*IEC_TYPES_ALL_H*/
   105 #endif /*IEC_TYPES_ALL_H*/