targets/plc_main_head.c
changeset 985 cd8dadcef426
parent 568 20a223828a06
child 1001 3f966bbb3fba
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/plc_main_head.c	Fri Mar 15 17:47:53 2013 +0900
@@ -0,0 +1,96 @@
+/**
+ * Head of code common to all C targets
+ **/
+
+#include "iec_types.h"
+/*
+ * Prototypes of functions provided by generated C softPLC
+ **/
+void config_run__(unsigned long tick);
+void config_init__(void);
+
+/*
+ * Prototypes of functions provided by generated target C code
+ * */
+void __init_debug(void);
+void __cleanup_debug(void);
+/*void __retrieve_debug(void);*/
+void __publish_debug(void);
+
+/*
+ *  Variables used by generated C softPLC and plugins
+ **/
+IEC_TIME __CURRENT_TIME;
+IEC_BOOL __DEBUG = 0;
+unsigned long __tick = 0;
+
+/*
+ *  Variable generated by C softPLC and plugins
+ **/
+extern unsigned long greatest_tick_count__;
+/* Tick time provided by POUS.C */
+extern unsigned long long common_ticktime__;
+
+/* Effective tick time with 1ms default value */
+static long long Ttick = 1000000;
+
+/* Help to quit cleanly when init fail at a certain level */
+static int init_level = 0;
+
+/*
+ * Prototypes of functions exported by plugins
+ **/
+%(calls_prototypes)s
+
+/*
+ * Retrieve input variables, run PLC and publish output variables
+ **/
+void __run(void)
+{
+    __tick++;
+    if (greatest_tick_count__)
+        __tick %%= greatest_tick_count__;
+
+    %(retrieve_calls)s
+
+    /*__retrieve_debug();*/
+
+    config_run__(__tick);
+
+    __publish_debug();
+
+    %(publish_calls)s
+
+}
+
+/*
+ * Initialize variables according to PLC's default values,
+ * and then init plugins with that values
+ **/
+int __init(int argc,char **argv)
+{
+    int res = 0;
+    init_level = 0;
+    
+    if(common_ticktime__)
+        Ttick = common_ticktime__;
+
+    config_init__();
+    __init_debug();
+    %(init_calls)s
+    return res;
+}
+/*
+ * Calls plugin cleanup proc.
+ **/
+void __cleanup(void)
+{
+    %(cleanup_calls)s
+    __cleanup_debug();
+}
+
+void PLC_GetTime(IEC_TIME *CURRENT_TIME);
+void PLC_SetTimer(unsigned long long next, unsigned long long period);
+
+
+