msousa@350: /* msousa@350: * Copyright (C) 2007-2011: Edouard TISSERANT and Laurent BESSARD msousa@350: * msousa@350: * See COPYING and COPYING.LESSER files for copyright details. msousa@350: * msousa@350: * This library is free software; you can redistribute it and/or msousa@350: * modify it under the terms of the GNU Lesser General Public msousa@350: * License as published by the Free Software Foundation; either msousa@350: * version 3 of the License, or (at your option) any later version. msousa@350: * msousa@350: * This library is distributed in the hope that it will be useful, msousa@350: * but WITHOUT ANY WARRANTY; without even the implied warranty of msousa@350: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU msousa@350: * Lesser General Public License for more details. msousa@350: * msousa@350: * You should have received a copy of the GNU Lesser General Public License msousa@350: * along with this library. If not, see . msousa@350: * msousa@350: */ msousa@350: etisserant@137: #ifndef IEC_TYPES_ALL_H etisserant@137: #define IEC_TYPES_ALL_H etisserant@137: msousa@350: msousa@350: /* Macro that expand to subtypes */ msousa@350: #define __ANY(DO) __ANY_DERIVED(DO) __ANY_ELEMENTARY(DO) msousa@350: #define __ANY_DERIVED(DO) msousa@350: #define __ANY_ELEMENTARY(DO) __ANY_MAGNITUDE(DO) __ANY_BIT(DO) __ANY_STRING(DO) __ANY_DATE(DO) msousa@350: #define __ANY_MAGNITUDE(DO) __ANY_NUM(DO) DO(TIME) msousa@350: #define __ANY_BIT(DO) __ANY_NBIT(DO) DO(BOOL) msousa@350: #define __ANY_NBIT(DO) DO(BYTE) DO(WORD) DO(DWORD) DO(LWORD) msousa@350: #define __ANY_STRING(DO) DO(STRING) msousa@350: #define __ANY_DATE(DO) DO(DATE) DO(TOD) DO(DT) msousa@350: #define __ANY_NUM(DO) __ANY_REAL(DO) __ANY_INT(DO) msousa@350: #define __ANY_REAL(DO) DO(REAL) DO(LREAL) msousa@350: #define __ANY_INT(DO) __ANY_SINT(DO) __ANY_UINT(DO) msousa@350: #define __ANY_SINT(DO) DO(SINT) DO(INT) DO(DINT) DO(LINT) msousa@350: #define __ANY_UINT(DO) DO(USINT) DO(UINT) DO(UDINT) DO(ULINT) msousa@350: msousa@350: msousa@350: /* Macro that expand to subtypes */ msousa@350: #define __ANY_1(DO,P1) __ANY_DERIVED_1(DO,P1) __ANY_ELEMENTARY_1(DO,P1) msousa@350: #define __ANY_DERIVED_1(DO,P1) msousa@350: #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) msousa@350: #define __ANY_MAGNITUDE_1(DO,P1) __ANY_NUM_1(DO,P1) DO(TIME,P1) msousa@350: #define __ANY_BIT_1(DO,P1) __ANY_NBIT_1(DO,P1) DO(BOOL,P1) msousa@350: #define __ANY_NBIT_1(DO,P1) DO(BYTE,P1) DO(WORD,P1) DO(DWORD,P1) DO(LWORD,P1) msousa@350: #define __ANY_STRING_1(DO,P1) DO(STRING,P1) msousa@350: #define __ANY_DATE_1(DO,P1) DO(DATE,P1) DO(TOD,P1) DO(DT,P1) msousa@350: #define __ANY_NUM_1(DO,P1) __ANY_REAL_1(DO,P1) __ANY_INT_1(DO,P1) msousa@350: #define __ANY_REAL_1(DO,P1) DO(REAL,P1) DO(LREAL,P1) msousa@350: #define __ANY_INT_1(DO,P1) __ANY_SINT_1(DO,P1) __ANY_UINT_1(DO,P1) msousa@350: #define __ANY_SINT_1(DO,P1) DO(SINT,P1) DO(INT,P1) DO(DINT,P1) DO(LINT,P1) msousa@350: #define __ANY_UINT_1(DO,P1) DO(USINT,P1) DO(UINT,P1) DO(UDINT,P1) DO(ULINT,P1) msousa@350: msousa@350: etisserant@137: etisserant@137: /*********************/ etisserant@137: /* IEC Types defs */ etisserant@137: /*********************/ etisserant@137: etisserant@137: /* Include non windows.h clashing typedefs */ etisserant@137: #include "iec_types.h" etisserant@137: conti@743: #ifndef TRUE conti@743: #define TRUE 1 conti@743: #define FALSE 0 conti@743: #endif laurent@221: edouard@224: #define __IEC_DEBUG_FLAG 0x01 edouard@224: #define __IEC_FORCE_FLAG 0x02 edouard@224: #define __IEC_RETAIN_FLAG 0x04 Edouard@301: #define __IEC_OUTPUT_FLAG 0x08 laurent@222: laurent@221: #define __DECLARE_IEC_TYPE(type)\ laurent@221: typedef IEC_##type type;\ laurent@221: \ laurent@221: typedef struct {\ laurent@221: IEC_##type value;\ laurent@221: IEC_BYTE flags;\ laurent@221: } __IEC_##type##_t;\ laurent@221: \ laurent@221: typedef struct {\ laurent@221: IEC_##type *value;\ laurent@221: IEC_BYTE flags;\ laurent@221: IEC_##type fvalue;\ laurent@221: } __IEC_##type##_p; laurent@221: mjsousa@909: mjsousa@909: laurent@327: #define __DECLARE_DERIVED_TYPE(type, base)\ laurent@221: typedef base type;\ laurent@404: typedef __IEC_##base##_t __IEC_##type##_t;\ laurent@404: typedef __IEC_##base##_p __IEC_##type##_p; laurent@221: laurent@221: #define __DECLARE_COMPLEX_STRUCT(type)\ laurent@221: typedef struct {\ laurent@221: type value;\ laurent@221: IEC_BYTE flags;\ laurent@221: } __IEC_##type##_t;\ laurent@221: \ laurent@221: typedef struct {\ laurent@221: type *value;\ laurent@221: IEC_BYTE flags;\ laurent@394: type fvalue;\ laurent@221: } __IEC_##type##_p; laurent@221: laurent@327: #define __DECLARE_ENUMERATED_TYPE(type, ...)\ laurent@327: typedef enum {\ laurent@327: __VA_ARGS__\ laurent@327: } type;\ laurent@327: __DECLARE_COMPLEX_STRUCT(type) laurent@327: laurent@327: #define __DECLARE_ARRAY_TYPE(type, base, size)\ laurent@237: typedef struct {\ laurent@237: base table size;\ laurent@237: } type;\ laurent@327: __DECLARE_COMPLEX_STRUCT(type) laurent@221: laurent@327: #define __DECLARE_STRUCT_TYPE(type, elements)\ laurent@327: typedef struct {\ laurent@327: elements\ laurent@327: } type;\ laurent@327: __DECLARE_COMPLEX_STRUCT(type) laurent@221: mjsousa@909: #define __DECLARE_REFTO_TYPE(type, name)\ mjsousa@932: typedef name type;\ mjsousa@909: __DECLARE_COMPLEX_STRUCT(type) mjsousa@909: mjsousa@909: etisserant@137: /* Those typdefs clash with windows.h */ etisserant@137: /* i.e. this file cannot be included aside windows.h */ msousa@350: __ANY(__DECLARE_IEC_TYPE) laurent@221: etisserant@137: typedef struct { mjsousa@897: __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!! mjsousa@899: BOOL prev_state; // previous step state. 0 : inative, 1: active mjsousa@899: __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!! etisserant@137: } STEP; etisserant@137: mjsousa@897: etisserant@137: typedef struct { etisserant@137: BOOL stored; // action storing state. 0 : not stored, 1: stored Laurent@628: __IEC_BOOL_t state; // current action state. 0 : inative, 1: active etisserant@137: BOOL set; // set have been requested (reset each time the body is evaluated) etisserant@137: BOOL reset; // reset have been requested (reset each time the body is evaluated) etisserant@137: TIME set_remaining_time; // time before set will be requested etisserant@137: TIME reset_remaining_time; // time before reset will be requested etisserant@137: } ACTION; etisserant@137: etisserant@137: /* Extra debug types for SFC */ msousa@350: #define __ANY_SFC(DO) DO(STEP) DO(TRANSITION) DO(ACTION) etisserant@137: etisserant@137: /* Enumerate native types */ etisserant@137: #define __decl_enum_type(TYPENAME) TYPENAME##_ENUM, edouard@224: #define __decl_enum_pointer(TYPENAME) TYPENAME##_P_ENUM, laurent@235: #define __decl_enum_output(TYPENAME) TYPENAME##_O_ENUM, etisserant@137: typedef enum{ msousa@350: __ANY(__decl_enum_type) msousa@350: __ANY(__decl_enum_pointer) msousa@350: __ANY(__decl_enum_output) edouard@224: /* SFC specific types are never external or global */ edouard@224: UNKNOWN_ENUM etisserant@137: } __IEC_types_enum; etisserant@137: etisserant@137: /* Get size of type from its number */ edouard@224: #define __decl_size_case(TYPENAME) \ edouard@224: case TYPENAME##_ENUM:\ edouard@246: case TYPENAME##_O_ENUM:\ edouard@224: case TYPENAME##_P_ENUM:\ edouard@224: return sizeof(TYPENAME); etisserant@137: static inline USINT __get_type_enum_size(__IEC_types_enum t){ etisserant@137: switch(t){ msousa@350: __ANY(__decl_size_case) etisserant@137: /* size do not correspond to real struct. etisserant@137: * only a bool is used to represent state*/ edouard@224: default: edouard@224: return 0; etisserant@137: } laurent@199: return 0; etisserant@137: } etisserant@137: etisserant@137: #endif /*IEC_TYPES_ALL_H*/