/* Generated by TiZi -- XCODE mode WASM wrapper
 * Compiled with WASI-SDK to WASM bytecode (.wasm).
 * Executed by WAMR (iwasm) in the target runtime.
 *
 * Exports:
 *   plc_init()      -- called once at PLC startup
 *   plc_run(ms)     -- called every scan cycle; ms = host time in milliseconds
 */
#include <stdint.h>
#include "iec_std_lib.h"
#include "config.h"

TIME __CURRENT_TIME;
BOOL __DEBUG = 0;

extern void config_init__(void);
extern void config_run__(unsigned long tick);

static unsigned long s_tick = 0;

__attribute__((visibility("default")))
void plc_init(void) {
    config_init__();
}

__attribute__((visibility("default")))
void plc_run(uint32_t ms) {
    __CURRENT_TIME.tv_sec  = (long)(ms / 1000u);
    __CURRENT_TIME.tv_nsec = (long)((ms % 1000u) * 1000000u);
    config_run__(s_tick++);
}
