27 #include <stdio.h> |
27 #include <stdio.h> |
28 #include <stdlib.h> |
28 #include <stdlib.h> |
29 #include <string.h> |
29 #include <string.h> |
30 #include <stdarg.h> |
30 #include <stdarg.h> |
31 |
31 |
32 #include "iec_std_lib_generated.h" |
|
33 |
|
34 #ifdef DEBUG_IEC |
32 #ifdef DEBUG_IEC |
35 #define DBG(...) printf(__VA_ARGS__); |
33 #define DBG(...) printf(__VA_ARGS__); |
36 #define DBG_TYPE(TYPENAME, name) __print_##TYPENAME(name); |
34 #define DBG_TYPE(TYPENAME, name) __print_##TYPENAME(name); |
37 #else |
35 #else |
38 #define DBG(...) |
36 #define DBG(...) |
39 #define DBG_TYPE(TYPENAME, name) |
37 #define DBG_TYPE(TYPENAME, name) |
40 #endif |
38 #endif |
41 |
39 |
42 /*********************/ |
40 /* |
43 /* IEC Types defs */ |
41 * Include type defs. |
44 /*********************/ |
42 */ |
45 |
43 #include "iec_types_all.h" |
46 /* Include non windows.h clashing typedefs */ |
|
47 #include "iec_types.h" |
|
48 |
|
49 /* Those typdefs clash with windows.h */ |
|
50 /* i.e. this file cannot be included aside windows.h */ |
|
51 typedef IEC_BOOL BOOL; |
|
52 |
|
53 #define TRUE 1 |
|
54 #define FALSE 0 |
|
55 |
|
56 typedef IEC_SINT SINT; |
|
57 typedef IEC_INT INT; |
|
58 typedef IEC_DINT DINT; |
|
59 typedef IEC_LINT LINT; |
|
60 |
|
61 typedef IEC_USINT USINT; |
|
62 typedef IEC_UINT UINT; |
|
63 typedef IEC_UDINT UDINT; |
|
64 typedef IEC_ULINT ULINT; |
|
65 |
|
66 typedef IEC_BYTE BYTE; |
|
67 typedef IEC_WORD WORD; |
|
68 typedef IEC_DWORD DWORD; |
|
69 typedef IEC_LWORD LWORD; |
|
70 |
|
71 typedef IEC_REAL REAL; |
|
72 typedef IEC_LREAL LREAL; |
|
73 |
|
74 typedef IEC_TIME TIME; |
|
75 typedef IEC_DATE DATE; |
|
76 typedef IEC_DT DT; |
|
77 typedef IEC_TOD TOD; |
|
78 |
44 |
79 #define __TIME_CMP(t1, t2) (t2.tv_sec == t1.tv_sec ? t1.tv_nsec - t2.tv_nsec : t1.tv_sec - t2.tv_sec) |
45 #define __TIME_CMP(t1, t2) (t2.tv_sec == t1.tv_sec ? t1.tv_nsec - t2.tv_nsec : t1.tv_sec - t2.tv_sec) |
80 extern TIME __CURRENT_TIME; |
46 extern TIME __CURRENT_TIME; |
81 |
|
82 typedef IEC_STRING STRING; |
|
83 |
47 |
84 #define __STR_CMP(str1, str2) memcmp((char*)&str1.body,(char*)&str2.body, str1.len < str2.len ? str1.len : str2.len) |
48 #define __STR_CMP(str1, str2) memcmp((char*)&str1.body,(char*)&str2.body, str1.len < str2.len ? str1.len : str2.len) |
85 |
49 |
86 /* TODO |
50 /* TODO |
87 typedef struct { |
51 typedef struct { |
171 TIME TIMEvar; |
135 TIME TIMEvar; |
172 TOD TODvar; |
136 TOD TODvar; |
173 DT DTvar; |
137 DT DTvar; |
174 DATE DATEvar; |
138 DATE DATEvar; |
175 } __IL_DEFVAR_T; |
139 } __IL_DEFVAR_T; |
176 |
|
177 typedef struct { |
|
178 BOOL state; // current step state. 0 : inative, 1: active |
|
179 BOOL prev_state; // previous step state. 0 : inative, 1: active |
|
180 TIME elapsed_time; // time since step is active |
|
181 } STEP; |
|
182 |
|
183 typedef struct { |
|
184 BOOL stored; // action storing state. 0 : not stored, 1: stored |
|
185 BOOL state; // current action state. 0 : inative, 1: active |
|
186 BOOL set; // set have been requested (reset each time the body is evaluated) |
|
187 BOOL reset; // reset have been requested (reset each time the body is evaluated) |
|
188 TIME set_remaining_time; // time before set will be requested |
|
189 TIME reset_remaining_time; // time before reset will be requested |
|
190 } ACTION; |
|
191 |
140 |
192 /*****************/ |
141 /*****************/ |
193 /* Misc internal */ |
142 /* Misc internal */ |
194 /*****************/ |
143 /*****************/ |
195 |
144 |
1018 __ne_time(TIME) |
967 __ne_time(TIME) |
1019 |
968 |
1020 __compare_string(__ne_, != ) |
969 __compare_string(__ne_, != ) |
1021 |
970 |
1022 |
971 |
1023 |
972 ///* Get string representation of variable referenced by a void pointer |
1024 /********************************/ |
973 // * where type is given as its number */ |
1025 /* Type tools */ |
974 //#define __decl_str_case(cat,TYPENAME) \ |
1026 /********************************/ |
975 // case TYPENAME##_ENUM:\ |
1027 /* Enumerate native types */ |
976 // return __##cat##_to_string(*(TYPENAME*)p); |
1028 #define __decl_enum_type(TYPENAME) TYPENAME##_ENUM, |
977 //#define __decl_str_case_bit(TYPENAME) __decl_str_case(bit,TYPENAME) |
1029 typedef enum{ |
978 //#define __decl_str_case_real(TYPENAME) __decl_str_case(real,TYPENAME) |
1030 ANY(__decl_enum_type) |
979 //#define __decl_str_case_sint(TYPENAME) __decl_str_case(sint,TYPENAME) |
1031 } __IEC_types_enum; |
980 //#define __decl_str_case_uint(TYPENAME) __decl_str_case(uint,TYPENAME) |
1032 |
981 //static inline STRING __get_type_enum_str(__IEC_types_enum t, void* p){ |
1033 /* Get size of type from its number */ |
982 // switch(t){ |
1034 #define __decl_size_case(TYPENAME) case TYPENAME##_ENUM: return sizeof(TYPENAME); |
983 // __decl_str_case(bool,BOOL) |
1035 static inline USINT __get_type_enum_size(__IEC_types_enum t){ |
984 // ANY_NBIT(__decl_str_case_bit) |
1036 switch(t){ |
985 // ANY_REAL(__decl_str_case_real) |
1037 ANY(__decl_size_case) |
986 // ANY_SINT(__decl_str_case_sint) |
1038 } |
987 // ANY_UINT(__decl_str_case_uint) |
1039 } |
988 // __decl_str_case(time,TIME) |
1040 |
989 // __decl_str_case(date,DATE) |
1041 /* Get string representation of referenced by void pointer where type is given as its number */ |
990 // __decl_str_case(tod,TOD) |
1042 #define __decl_str_case(cat,TYPENAME) case TYPENAME##_ENUM:return __##cat##_to_string(*(TYPENAME*)p); |
991 // __decl_str_case(dt, DT) |
1043 #define __decl_str_case_bit(TYPENAME) __decl_str_case(bit,TYPENAME) |
992 // } |
1044 #define __decl_str_case_real(TYPENAME) __decl_str_case(real,TYPENAME) |
993 //} |
1045 #define __decl_str_case_sint(TYPENAME) __decl_str_case(sint,TYPENAME) |
994 // |
1046 #define __decl_str_case_uint(TYPENAME) __decl_str_case(uint,TYPENAME) |
995 |
1047 static inline STRING __get_type_enum_str(__IEC_types_enum t, void* p){ |
996 |
1048 switch(t){ |
997 |
1049 __decl_str_case(bool,BOOL) |
998 |
1050 ANY_NBIT(__decl_str_case_bit) |
999 |
1051 ANY_REAL(__decl_str_case_real) |
1000 |
1052 ANY_SINT(__decl_str_case_sint) |
|
1053 ANY_UINT(__decl_str_case_uint) |
|
1054 __decl_str_case(time,TIME) |
|
1055 __decl_str_case(date,DATE) |
|
1056 __decl_str_case(tod,TOD) |
|
1057 __decl_str_case(dt, DT) |
|
1058 } |
|
1059 } |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|