etisserant@280: /**
Edouard@985:  * Head of code common to all C targets
greg@332:  **/
etisserant@209: 
Edouard@1001: #include "beremiz.h"
Edouard@1391: #include <string.h>
etisserant@209: /*
laurent@397:  * Prototypes of functions provided by generated C softPLC
greg@332:  **/
laurent@397: void config_run__(unsigned long tick);
etisserant@209: void config_init__(void);
etisserant@280: 
etisserant@280: /*
laurent@397:  * Prototypes of functions provided by generated target C code
etisserant@280:  * */
Edouard@1392: long long AtomicCompareExchange64(long long*, long long, long long);
etisserant@235: void __init_debug(void);
etisserant@235: void __cleanup_debug(void);
etisserant@280: /*void __retrieve_debug(void);*/
etisserant@280: void __publish_debug(void);
etisserant@235: 
etisserant@209: /*
etisserant@280:  *  Variables used by generated C softPLC and plugins
etisserant@209:  **/
etisserant@209: IEC_TIME __CURRENT_TIME;
laurent@397: IEC_BOOL __DEBUG = 0;
ed@446: unsigned long __tick = 0;
Edouard@1463: char *PLC_ID = NULL;
laurent@397: 
laurent@397: /*
laurent@397:  *  Variable generated by C softPLC and plugins
laurent@397:  **/
laurent@397: extern unsigned long greatest_tick_count__;
Edouard@985: 
etisserant@280: /* Help to quit cleanly when init fail at a certain level */
etisserant@209: static int init_level = 0;
etisserant@209: 
etisserant@209: /*
greg@332:  * Prototypes of functions exported by plugins
etisserant@209:  **/
etisserant@209: %(calls_prototypes)s
etisserant@209: 
etisserant@209: /*
greg@332:  * Retrieve input variables, run PLC and publish output variables
etisserant@209:  **/
greg@423: void __run(void)
etisserant@209: {
etisserant@236:     __tick++;
laurent@397:     if (greatest_tick_count__)
laurent@397:         __tick %%= greatest_tick_count__;
etisserant@236: 
etisserant@209:     %(retrieve_calls)s
etisserant@209: 
etisserant@239:     /*__retrieve_debug();*/
greg@332: 
etisserant@209:     config_run__(__tick);
etisserant@209: 
etisserant@239:     __publish_debug();
greg@332: 
etisserant@209:     %(publish_calls)s
etisserant@209: 
etisserant@209: }
etisserant@209: 
etisserant@209: /*
laurent@397:  * Initialize variables according to PLC's default values,
greg@332:  * and then init plugins with that values
etisserant@209:  **/
etisserant@209: int __init(int argc,char **argv)
etisserant@209: {
laurent@386:     int res = 0;
greg@423:     init_level = 0;
Edouard@985:     
Edouard@1428:     /* Effective tick time with 1ms default value */
Edouard@1428:     if(!common_ticktime__)
Edouard@1428:         common_ticktime__ = 1000000;
Edouard@985: 
etisserant@209:     config_init__();
etisserant@235:     __init_debug();
etisserant@209:     %(init_calls)s
laurent@386:     return res;
etisserant@209: }
etisserant@209: /*
etisserant@209:  * Calls plugin cleanup proc.
etisserant@209:  **/
greg@423: void __cleanup(void)
etisserant@209: {
etisserant@209:     %(cleanup_calls)s
etisserant@235:     __cleanup_debug();
etisserant@209: }
etisserant@209: 
etisserant@209: void PLC_GetTime(IEC_TIME *CURRENT_TIME);
edouard@518: void PLC_SetTimer(unsigned long long next, unsigned long long period);
etisserant@209: 
etisserant@280: 
Edouard@985: