|
1 /** |
|
2 * Head of code common to all C targets |
|
3 **/ |
|
4 |
|
5 #include "iec_types.h" |
|
6 /* |
|
7 * Prototypes of functions provided by generated C softPLC |
|
8 **/ |
|
9 void config_run__(unsigned long tick); |
|
10 void config_init__(void); |
|
11 |
|
12 /* |
|
13 * Prototypes of functions provided by generated target C code |
|
14 * */ |
|
15 void __init_debug(void); |
|
16 void __cleanup_debug(void); |
|
17 /*void __retrieve_debug(void);*/ |
|
18 void __publish_debug(void); |
|
19 |
|
20 /* |
|
21 * Variables used by generated C softPLC and plugins |
|
22 **/ |
|
23 IEC_TIME __CURRENT_TIME; |
|
24 IEC_BOOL __DEBUG = 0; |
|
25 unsigned long __tick = 0; |
|
26 |
|
27 /* |
|
28 * Variable generated by C softPLC and plugins |
|
29 **/ |
|
30 extern unsigned long greatest_tick_count__; |
|
31 /* Tick time provided by POUS.C */ |
|
32 extern unsigned long long common_ticktime__; |
|
33 |
|
34 /* Effective tick time with 1ms default value */ |
|
35 static long long Ttick = 1000000; |
|
36 |
|
37 /* Help to quit cleanly when init fail at a certain level */ |
|
38 static int init_level = 0; |
|
39 |
|
40 /* |
|
41 * Prototypes of functions exported by plugins |
|
42 **/ |
|
43 %(calls_prototypes)s |
|
44 |
|
45 /* |
|
46 * Retrieve input variables, run PLC and publish output variables |
|
47 **/ |
|
48 void __run(void) |
|
49 { |
|
50 __tick++; |
|
51 if (greatest_tick_count__) |
|
52 __tick %%= greatest_tick_count__; |
|
53 |
|
54 %(retrieve_calls)s |
|
55 |
|
56 /*__retrieve_debug();*/ |
|
57 |
|
58 config_run__(__tick); |
|
59 |
|
60 __publish_debug(); |
|
61 |
|
62 %(publish_calls)s |
|
63 |
|
64 } |
|
65 |
|
66 /* |
|
67 * Initialize variables according to PLC's default values, |
|
68 * and then init plugins with that values |
|
69 **/ |
|
70 int __init(int argc,char **argv) |
|
71 { |
|
72 int res = 0; |
|
73 init_level = 0; |
|
74 |
|
75 if(common_ticktime__) |
|
76 Ttick = common_ticktime__; |
|
77 |
|
78 config_init__(); |
|
79 __init_debug(); |
|
80 %(init_calls)s |
|
81 return res; |
|
82 } |
|
83 /* |
|
84 * Calls plugin cleanup proc. |
|
85 **/ |
|
86 void __cleanup(void) |
|
87 { |
|
88 %(cleanup_calls)s |
|
89 __cleanup_debug(); |
|
90 } |
|
91 |
|
92 void PLC_GetTime(IEC_TIME *CURRENT_TIME); |
|
93 void PLC_SetTimer(unsigned long long next, unsigned long long period); |
|
94 |
|
95 |
|
96 |