lib/C/iec_types_all.h
changeset 904 423ea3749212
parent 899 a3f734a23566
child 909 8b2a31dea131
equal deleted inserted replaced
903:f712705bef65 904:423ea3749212
       
     1 /*
       
     2  * Copyright (C) 2007-2011: Edouard TISSERANT and Laurent BESSARD
       
     3  *
       
     4  * See COPYING and COPYING.LESSER files for copyright details.
       
     5  *
       
     6  * This library is free software; you can redistribute it and/or
       
     7  * modify it under the terms of the GNU Lesser General Public
       
     8  * License as published by the Free Software Foundation; either
       
     9  * version 3 of the License, or (at your option) any later version.
       
    10  *
       
    11  * This library is distributed in the hope that it will be useful,
       
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    14  * Lesser General Public License for more details.
       
    15  * 
       
    16  * You should have received a copy of the GNU Lesser General Public License 
       
    17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
       
    18  *
       
    19  */
       
    20 
       
    21 #ifndef IEC_TYPES_ALL_H
       
    22 #define IEC_TYPES_ALL_H
       
    23 
       
    24 
       
    25 /* Macro that expand to subtypes */
       
    26 #define __ANY(DO)                 __ANY_DERIVED(DO) __ANY_ELEMENTARY(DO)
       
    27 #define __ANY_DERIVED(DO)
       
    28 #define __ANY_ELEMENTARY(DO)      __ANY_MAGNITUDE(DO) __ANY_BIT(DO) __ANY_STRING(DO) __ANY_DATE(DO)
       
    29 #define __ANY_MAGNITUDE(DO)       __ANY_NUM(DO) DO(TIME)
       
    30 #define __ANY_BIT(DO)             __ANY_NBIT(DO) DO(BOOL)
       
    31 #define __ANY_NBIT(DO)            DO(BYTE) DO(WORD) DO(DWORD) DO(LWORD)
       
    32 #define __ANY_STRING(DO)          DO(STRING)
       
    33 #define __ANY_DATE(DO)            DO(DATE) DO(TOD) DO(DT)
       
    34 #define __ANY_NUM(DO)             __ANY_REAL(DO) __ANY_INT(DO)
       
    35 #define __ANY_REAL(DO)            DO(REAL) DO(LREAL)
       
    36 #define __ANY_INT(DO)             __ANY_SINT(DO) __ANY_UINT(DO)
       
    37 #define __ANY_SINT(DO)            DO(SINT) DO(INT) DO(DINT) DO(LINT)
       
    38 #define __ANY_UINT(DO)            DO(USINT) DO(UINT) DO(UDINT) DO(ULINT)
       
    39 
       
    40 
       
    41 /* Macro that expand to subtypes */
       
    42 #define __ANY_1(DO,P1)            __ANY_DERIVED_1(DO,P1) __ANY_ELEMENTARY_1(DO,P1)
       
    43 #define __ANY_DERIVED_1(DO,P1)
       
    44 #define __ANY_ELEMENTARY_1(DO,P1) __ANY_MAGNITUDE_1(DO,P1) __ANY_BIT_1(DO,P1) __ANY_STRING_1(DO,P1) __ANY_DATE_1(DO,P1)
       
    45 #define __ANY_MAGNITUDE_1(DO,P1)  __ANY_NUM_1(DO,P1) DO(TIME,P1)
       
    46 #define __ANY_BIT_1(DO,P1)        __ANY_NBIT_1(DO,P1) DO(BOOL,P1)
       
    47 #define __ANY_NBIT_1(DO,P1)       DO(BYTE,P1) DO(WORD,P1) DO(DWORD,P1) DO(LWORD,P1)
       
    48 #define __ANY_STRING_1(DO,P1)     DO(STRING,P1)
       
    49 #define __ANY_DATE_1(DO,P1)       DO(DATE,P1) DO(TOD,P1) DO(DT,P1)
       
    50 #define __ANY_NUM_1(DO,P1)        __ANY_REAL_1(DO,P1) __ANY_INT_1(DO,P1)
       
    51 #define __ANY_REAL_1(DO,P1)       DO(REAL,P1) DO(LREAL,P1)
       
    52 #define __ANY_INT_1(DO,P1)        __ANY_SINT_1(DO,P1) __ANY_UINT_1(DO,P1)
       
    53 #define __ANY_SINT_1(DO,P1)       DO(SINT,P1) DO(INT,P1) DO(DINT,P1) DO(LINT,P1)
       
    54 #define __ANY_UINT_1(DO,P1)       DO(USINT,P1) DO(UINT,P1) DO(UDINT,P1) DO(ULINT,P1)
       
    55 
       
    56 
       
    57 
       
    58 /*********************/
       
    59 /*  IEC Types defs   */
       
    60 /*********************/
       
    61 
       
    62 /* Include non windows.h clashing typedefs */
       
    63 #include "iec_types.h"
       
    64 
       
    65 #ifndef TRUE
       
    66   #define TRUE 1
       
    67   #define FALSE 0
       
    68 #endif
       
    69 
       
    70 #define __IEC_DEBUG_FLAG 0x01
       
    71 #define __IEC_FORCE_FLAG 0x02
       
    72 #define __IEC_RETAIN_FLAG 0x04
       
    73 #define __IEC_OUTPUT_FLAG 0x08
       
    74 
       
    75 #define __DECLARE_IEC_TYPE(type)\
       
    76 typedef IEC_##type type;\
       
    77 \
       
    78 typedef struct {\
       
    79   IEC_##type value;\
       
    80   IEC_BYTE flags;\
       
    81 } __IEC_##type##_t;\
       
    82 \
       
    83 typedef struct {\
       
    84   IEC_##type *value;\
       
    85   IEC_BYTE flags;\
       
    86   IEC_##type fvalue;\
       
    87 } __IEC_##type##_p;
       
    88 
       
    89 #define __DECLARE_DERIVED_TYPE(type, base)\
       
    90 typedef base type;\
       
    91 typedef __IEC_##base##_t __IEC_##type##_t;\
       
    92 typedef __IEC_##base##_p __IEC_##type##_p;
       
    93 
       
    94 #define __DECLARE_COMPLEX_STRUCT(type)\
       
    95 typedef struct {\
       
    96   type value;\
       
    97   IEC_BYTE flags;\
       
    98 } __IEC_##type##_t;\
       
    99 \
       
   100 typedef struct {\
       
   101   type *value;\
       
   102   IEC_BYTE flags;\
       
   103   type fvalue;\
       
   104 } __IEC_##type##_p;
       
   105 
       
   106 #define __DECLARE_ENUMERATED_TYPE(type, ...)\
       
   107 typedef enum {\
       
   108   __VA_ARGS__\
       
   109 } type;\
       
   110 __DECLARE_COMPLEX_STRUCT(type)
       
   111 
       
   112 #define __DECLARE_ARRAY_TYPE(type, base, size)\
       
   113 typedef struct {\
       
   114   base table size;\
       
   115 } type;\
       
   116 __DECLARE_COMPLEX_STRUCT(type)
       
   117 
       
   118 #define __DECLARE_STRUCT_TYPE(type, elements)\
       
   119 typedef struct {\
       
   120   elements\
       
   121 } type;\
       
   122 __DECLARE_COMPLEX_STRUCT(type)
       
   123 
       
   124 /* Those typdefs clash with windows.h */
       
   125 /* i.e. this file cannot be included aside windows.h */
       
   126 __ANY(__DECLARE_IEC_TYPE)
       
   127 
       
   128 typedef struct {
       
   129   __IEC_BOOL_t X;  // state;  --> current step state. 0 : inative, 1: active.   We name it 'X' as it may be accessed from IEC 61131.3 code using stepname.X syntax!!
       
   130   BOOL prev_state; // previous step state. 0 : inative, 1: active
       
   131   __IEC_TIME_t T;  // elapsed_time;  --> time since step is active.   We name it 'T' as it may be accessed from IEC 61131.3 code using stepname.T syntax!!
       
   132 } STEP;
       
   133 
       
   134 
       
   135 typedef struct {
       
   136   BOOL stored;  // action storing state. 0 : not stored, 1: stored
       
   137   __IEC_BOOL_t state; // current action state. 0 : inative, 1: active
       
   138   BOOL set;   // set have been requested (reset each time the body is evaluated)
       
   139   BOOL reset; // reset have been requested (reset each time the body is evaluated)
       
   140   TIME set_remaining_time;    // time before set will be requested
       
   141   TIME reset_remaining_time;  // time before reset will be requested
       
   142 } ACTION;
       
   143 
       
   144 /* Extra debug types for SFC */
       
   145 #define __ANY_SFC(DO) DO(STEP) DO(TRANSITION) DO(ACTION)
       
   146 
       
   147 /* Enumerate native types */
       
   148 #define __decl_enum_type(TYPENAME) TYPENAME##_ENUM,
       
   149 #define __decl_enum_pointer(TYPENAME) TYPENAME##_P_ENUM,
       
   150 #define __decl_enum_output(TYPENAME) TYPENAME##_O_ENUM,
       
   151 typedef enum{
       
   152   __ANY(__decl_enum_type)
       
   153   __ANY(__decl_enum_pointer)
       
   154   __ANY(__decl_enum_output)
       
   155   /* SFC specific types are never external or global */
       
   156   UNKNOWN_ENUM
       
   157 } __IEC_types_enum;
       
   158 
       
   159 /* Get size of type from its number */
       
   160 #define __decl_size_case(TYPENAME) \
       
   161 	case TYPENAME##_ENUM:\
       
   162 	case TYPENAME##_O_ENUM:\
       
   163 	case TYPENAME##_P_ENUM:\
       
   164 		return sizeof(TYPENAME);
       
   165 static inline USINT __get_type_enum_size(__IEC_types_enum t){
       
   166  switch(t){
       
   167   __ANY(__decl_size_case)
       
   168   /* size do not correspond to real struct.
       
   169    * only a bool is used to represent state*/
       
   170   default:
       
   171 	  return 0;
       
   172  }
       
   173  return 0;
       
   174 }
       
   175 
       
   176 #endif /*IEC_TYPES_ALL_H*/