/*
 * DEBUGGER code
 * 
 * On "publish", when buffer is free, debugger stores arbitrary variables 
 * content into, and mark this buffer as filled
 * 
 * 
 * Buffer content is read asynchronously, (from non real time part), 
 * and then buffer marked free again.
 *  
 * 
 * */
#ifdef TARGET_DEBUG_AND_RETAIN_DISABLE

void __init_debug    (void){}
void __cleanup_debug (void){}
void __retrieve_debug(void){}
void __publish_debug (void){}

#else

#include "iec_types_all.h"
#include "POUS.h"
/*for memcpy*/
#include <string.h>
#include <stdio.h>

#ifndef TARGET_ONLINE_DEBUG_DISABLE
#define BUFFER_SIZE 1144

/* Atomically accessed variable for buffer state */
#define BUFFER_FREE 0
#define BUFFER_BUSY 1
static long buffer_state = BUFFER_FREE;

/* The buffer itself */
char debug_buffer[BUFFER_SIZE];

/* Buffer's cursor*/
static char* buffer_cursor = debug_buffer;
#endif

static unsigned int retain_offset = 0;
/***
 * Declare programs 
 **/
extern MAIN RES0__INSTANCE0;

/***
 * Declare global variables from resources and conf 
 **/
extern __IEC_BOOL_t RES0__RUN_BIT;
extern       MAIN   RES0__INSTANCE0;

typedef const struct {
    void *ptr;
    __IEC_types_enum type;
} dbgvardsc_t;

static dbgvardsc_t dbgvardsc[] = {
{&(RES0__RUN_BIT), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.FLOW_K), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.FLOW_TI), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.FLOW_TD), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.PRODUCT_FLOW), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.PRODUCT_FLOW_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.CYCLE_TIME), TIME_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.POS_UPDATE_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.CURR_POS_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.NEW_POS), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.CURR_POS), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.FLOW_SET_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.FLOW_SET_IN), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL0.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL1.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.FLOW_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.FLOW_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.POS_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.POS_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_REAL2.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_UINT0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_UINT0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_UINT0.REAL_IN), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_UINT0.UINT_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_UINT0.DIV1_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_UINT0.MUL4_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SCALE_TO_UINT0.REAL_TO_UINT6_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.SUB59_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.MUL60_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.ADD58_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.FLOW_CONTROL0.LIMIT40_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.FIRST_RUN), BOOL_ENUM},
{&(RES0__INSTANCE0.FLOW_SET), UINT_ENUM},
{&(RES0__INSTANCE0.A_SETPOINT), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_SP), UINT_ENUM},
{&(RES0__INSTANCE0.OVERRIDE_SP), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_SP), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.A_IN_PURGE_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.A_IN_PURGE), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.A_SETPOINT_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.A_SETPOINT), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.CURR_POS), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.VALVE_POS_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.POS_UPDATE_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.VALVE_POS_NOMINAL), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.NEW_POS), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.COMPOSITION_K), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.COMPOSITION_TI), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.CYCLE_TIME), TIME_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL3.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL2.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_UINT0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_UINT0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_UINT0.REAL_IN), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_UINT0.UINT_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_UINT0.DIV1_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_UINT0.MUL4_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_UINT0.REAL_TO_UINT6_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.COMP_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.COMP_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.POS_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.POS_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SCALE_TO_REAL0.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.SUB45_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.MUL46_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.ADD42_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.COMPOSITION_CONTROL0.LIMIT44_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED0.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED0.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED0.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED0.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED0.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.F1_VALVE_POS), UINT_ENUM},
{&(RES0__INSTANCE0.F1_FLOW), UINT_ENUM},
{&(RES0__INSTANCE0.F2_VALVE_POS), UINT_ENUM},
{&(RES0__INSTANCE0.F2_FLOW), UINT_ENUM},
{&(RES0__INSTANCE0.PURGE_VALVE_POS), UINT_ENUM},
{&(RES0__INSTANCE0.PURGE_FLOW), UINT_ENUM},
{&(RES0__INSTANCE0.PRODUCT_VALVE_POS), UINT_ENUM},
{&(RES0__INSTANCE0.PRODUCT_FLOW), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL), UINT_ENUM},
{&(RES0__INSTANCE0.A_IN_PURGE), UINT_ENUM},
{&(RES0__INSTANCE0.B_IN_PURGE), UINT_ENUM},
{&(RES0__INSTANCE0.C_IN_PURGE), UINT_ENUM},
{&(RES0__INSTANCE0.F1_VALVE_SP), UINT_ENUM},
{&(RES0__INSTANCE0.F2_VALVE_SP), UINT_ENUM},
{&(RES0__INSTANCE0.PURGE_VALVE_SP), UINT_ENUM},
{&(RES0__INSTANCE0.PRODUCT_VALVE_SP), UINT_ENUM},
{&(RES0__INSTANCE0.PRODUCT_VALVE_SAFE), UINT_ENUM},
{&(RES0__INSTANCE0.PURGE_VALVE_SAFE), UINT_ENUM},
{&(RES0__INSTANCE0.F1_VALVE_SAFE), UINT_ENUM},
{&(RES0__INSTANCE0.F2_VALVE_SAFE), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.PRESSURE_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.PRESSURE), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.PRESSURE_SP_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.PRESSURE_SP), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.CURR_POS), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.VALVE_POS_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.POS_UPDATE_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.VALVE_POS_NOMINAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.VALVE_POS), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.PRESSURE_K), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.PRESSURE_TI), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.CYCLE_TIME), TIME_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL5.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL4.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_UINT0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_UINT0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_UINT0.REAL_IN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_UINT0.UINT_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_UINT0.DIV1_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_UINT0.MUL4_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_UINT0.REAL_TO_UINT6_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.PRESSURE_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.PRESSURE_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.POS_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.POS_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SCALE_TO_REAL0.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SUB57_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.MUL60_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.SUB53_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_CONTROL0.LIMIT55_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.HMI_PRESSURE), INT_ENUM},
{&(RES0__INSTANCE0.HMI_LEVEL), INT_ENUM},
{&(RES0__INSTANCE0.HMI_F1_VALVE_POS), INT_ENUM},
{&(RES0__INSTANCE0.HMI_F1_FLOW), INT_ENUM},
{&(RES0__INSTANCE0.HMI_F2_VALVE_POS), INT_ENUM},
{&(RES0__INSTANCE0.HMI_F2_FLOW), INT_ENUM},
{&(RES0__INSTANCE0.HMI_PURGE_VALVE_POS), INT_ENUM},
{&(RES0__INSTANCE0.HMI_PURGE_FLOW), INT_ENUM},
{&(RES0__INSTANCE0.HMI_PRODUCT_VALVE_POS), INT_ENUM},
{&(RES0__INSTANCE0.HMI_PRODUCT_FLOW), INT_ENUM},
{&(RES0__INSTANCE0.SCAN_COUNT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED1.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED1.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED1.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED1.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED1.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED1.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED1.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED2.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED2.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED2.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED2.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED2.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED2.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED2.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED3.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED3.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED3.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED3.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED3.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED3.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED3.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED4.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED4.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED4.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED4.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED4.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED4.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED4.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED5.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED5.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED5.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED5.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED5.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED5.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED5.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED6.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED6.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED6.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED6.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED6.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED6.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED6.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED7.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED7.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED7.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED7.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED7.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED7.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED7.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED8.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED8.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED8.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED8.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED8.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED8.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED8.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED9.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED9.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED9.INPUT_UINT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED9.OUTPUT_INT), INT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED9.DIV3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED9.ABS8_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.SCALE_TO_SIGNED9.UINT_TO_INT9_OUT), INT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.PRESSURE_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.PRESSURE), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.CURR_SP), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.CURR_SP_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.PRODUCT_SP_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SP_UPDATE), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.PRODUCT_SP_NOMINL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.PRODUCT_SP), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.OVERRIDE_SP_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.OVERRIDE_SP), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.OVERRIDE_K), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.OVERRIDE_TI), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.CYCLE_TIME), TIME_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL7.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.PRESSURE_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.PRESSURE_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.FLOW_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.FLOW_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SCALE_TO_REAL0.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.SUB86_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.MUL87_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.MAX84_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.ADD85_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.LIMIT67_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.DIV73_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.MUL75_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.PRESSURE_OVERRIDE0.REAL_TO_UINT79_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.LIQUID_LEVEL), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.LEVEL_SP), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.CURR_POS), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.NEW_POS), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.CYCLE_TIME), TIME_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.LEVEL_K), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.LEVEL_TI), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL0.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.LEVEL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.LEVEL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.POS_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.POS_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.LEVEL_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.POS_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.POS_UPDATE_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SP_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL1.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.RAW_INPUT_VALUE), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.SCALED_REAL), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.REAL_MAX), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.REAL_MIN), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.RAW_MAX), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.RAW_MIN), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.RATE), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_REAL2.OFFSET), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_UINT0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_UINT0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_UINT0.REAL_IN), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_UINT0.UINT_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_UINT0.DIV1_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_UINT0.MUL4_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SCALE_TO_UINT0.REAL_TO_UINT6_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SUB32_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.MUL33_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.SUB30_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.LEVEL_CONTROL0.LIMIT25_OUT), REAL_ENUM},
{&(RES0__INSTANCE0.RUN_BIT), BOOL_P_ENUM},
{&(RES0__INSTANCE0.RUN_BIT0), BOOL_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.EN), BOOL_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.FLOW_SP_C), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.A_SP_C), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.PRESS_SP_C), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.OVER_SP_C), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.LEVEL_SP_C), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.FLOW_SP), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.A_SP), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.PRESS_SP), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.OVER_SP), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.LEVEL_SP), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.MOVE3_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.MOVE7_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.MOVE11_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.MOVE15_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.INITIALIZE_SP0.MOVE19_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.ADD87_OUT), UINT_ENUM},
{&(RES0__INSTANCE0.GE91_OUT), BOOL_ENUM},
{&(RES0__INSTANCE0.MOVE92_ENO), BOOL_ENUM},
{&(RES0__INSTANCE0.MOVE92_OUT), UINT_ENUM}
};

typedef void(*__for_each_variable_do_fp)(dbgvardsc_t*);
void __for_each_variable_do(__for_each_variable_do_fp fp)
{
    unsigned int i;
    for(i = 0; i < sizeof(dbgvardsc)/sizeof(dbgvardsc_t); i++){
        dbgvardsc_t *dsc = &dbgvardsc[i];
        if(dsc->type != UNKNOWN_ENUM) 
            (*fp)(dsc);
    }
}

#define __Unpack_case_t(TYPENAME) \
        case TYPENAME##_ENUM :\
            *flags = ((__IEC_##TYPENAME##_t *)varp)->flags;\
            forced_value_p = *real_value_p = &((__IEC_##TYPENAME##_t *)varp)->value;\
            break;

#define __Unpack_case_p(TYPENAME)\
        case TYPENAME##_O_ENUM :\
            *flags = __IEC_OUTPUT_FLAG;\
        case TYPENAME##_P_ENUM :\
            *flags |= ((__IEC_##TYPENAME##_p *)varp)->flags;\
            *real_value_p = ((__IEC_##TYPENAME##_p *)varp)->value;\
            forced_value_p = &((__IEC_##TYPENAME##_p *)varp)->fvalue;\
            break;

void* UnpackVar(dbgvardsc_t *dsc, void **real_value_p, char *flags)
{
    void *varp = dsc->ptr;
    void *forced_value_p = NULL;
    *flags = 0;
    /* find data to copy*/
    switch(dsc->type){
        __ANY(__Unpack_case_t)
        __ANY(__Unpack_case_p)
    default:
        break;
    }
    if (*flags & __IEC_FORCE_FLAG)
        return forced_value_p;
    return *real_value_p;
}

void Remind(unsigned int offset, unsigned int count, void * p);

void RemindIterator(dbgvardsc_t *dsc)
{
    void *real_value_p = NULL;
    char flags = 0;
    UnpackVar(dsc, &real_value_p, &flags);

    if(flags & __IEC_RETAIN_FLAG){
        USINT size = __get_type_enum_size(dsc->type);
        /* compute next cursor positon*/
        unsigned int next_retain_offset = retain_offset + size;
        /* if buffer not full */
        Remind(retain_offset, size, real_value_p);
        /* increment cursor according size*/
        retain_offset = next_retain_offset;
    }
}

extern int CheckRetainBuffer(void);
extern void InitRetain(void);

void __init_debug(void)
{
    /* init local static vars */
#ifndef TARGET_ONLINE_DEBUG_DISABLE	
    buffer_cursor = debug_buffer;
    buffer_state = BUFFER_FREE;
#endif

    retain_offset = 0;
    InitRetain();
    /* Iterate over all variables to fill debug buffer */
    if(CheckRetainBuffer()){
    	__for_each_variable_do(RemindIterator);
    }else{
    	char mstr[] = "RETAIN memory invalid - defaults used";
        LogMessage(LOG_WARNING, mstr, sizeof(mstr));
    }
    retain_offset = 0;
}

extern void InitiateDebugTransfer(void);
extern void CleanupRetain(void);

extern unsigned long __tick;

void __cleanup_debug(void)
{
#ifndef TARGET_ONLINE_DEBUG_DISABLE	
    buffer_cursor = debug_buffer;
    InitiateDebugTransfer();
#endif    

    CleanupRetain();
}

void __retrieve_debug(void)
{
}


void Retain(unsigned int offset, unsigned int count, void * p);

static inline void BufferIterator(dbgvardsc_t *dsc, int do_debug)
{
    void *real_value_p = NULL;
    void *visible_value_p = NULL;
    char flags = 0;

    visible_value_p = UnpackVar(dsc, &real_value_p, &flags);

    if(flags & ( __IEC_DEBUG_FLAG | __IEC_RETAIN_FLAG)){
        USINT size = __get_type_enum_size(dsc->type);

#ifndef TARGET_ONLINE_DEBUG_DISABLE	
        if(flags & __IEC_DEBUG_FLAG){
            /* copy visible variable to buffer */;
            if(do_debug){
                /* compute next cursor positon.
                   No need to check overflow, as BUFFER_SIZE
                   is computed large enough */
		if((dsc->type == STRING_ENUM)   ||
		   (dsc->type == STRING_P_ENUM) ||
		   (dsc->type == STRING_O_ENUM)){
                    /* optimization for strings */
                    size = ((STRING*)visible_value_p)->len + 1;
                }
                char* next_cursor = buffer_cursor + size;
                /* copy data to the buffer */
                memcpy(buffer_cursor, visible_value_p, size);
                /* increment cursor according size*/
                buffer_cursor = next_cursor;
            }
            /* re-force real value of outputs (M and Q)*/
            if((flags & __IEC_FORCE_FLAG) && (flags & __IEC_OUTPUT_FLAG)){
                memcpy(real_value_p, visible_value_p, size);
            }
        }
#endif	

        if(flags & __IEC_RETAIN_FLAG){
            /* compute next cursor positon*/
            unsigned int next_retain_offset = retain_offset + size;
            /* if buffer not full */
            Retain(retain_offset, size, real_value_p);
            /* increment cursor according size*/
            retain_offset = next_retain_offset;
        }
    }
}

void DebugIterator(dbgvardsc_t *dsc){
    BufferIterator(dsc, 1);
}

void RetainIterator(dbgvardsc_t *dsc){
    BufferIterator(dsc, 0);
}


unsigned int retain_size = 0;

/* GetRetainSizeIterator */
void GetRetainSizeIterator(dbgvardsc_t *dsc)
{
    void *real_value_p = NULL;
    char flags = 0;
    UnpackVar(dsc, &real_value_p, &flags);

    if(flags & __IEC_RETAIN_FLAG){
        USINT size = __get_type_enum_size(dsc->type);
        /* Calc retain buffer size */
        retain_size += size;
    }
}

/* Return size of all retain variables */
unsigned int GetRetainSize(void)
{
    __for_each_variable_do(GetRetainSizeIterator);
    return retain_size;
}


extern void PLC_GetTime(IEC_TIME*);
extern int TryEnterDebugSection(void);
extern long AtomicCompareExchange(long*, long, long);
extern long long AtomicCompareExchange64(long long* , long long , long long);
extern void LeaveDebugSection(void);
extern void ValidateRetainBuffer(void);
extern void InValidateRetainBuffer(void);

void __publish_debug(void)
{
    retain_offset = 0;
    InValidateRetainBuffer();
    
#ifndef TARGET_ONLINE_DEBUG_DISABLE 
    /* Check there is no running debugger re-configuration */
    if(TryEnterDebugSection()){
        /* Lock buffer */
        long latest_state = AtomicCompareExchange(
            &buffer_state,
            BUFFER_FREE,
            BUFFER_BUSY);
            
        /* If buffer was free */
        if(latest_state == BUFFER_FREE)
        {
            /* Reset buffer cursor */
            buffer_cursor = debug_buffer;
            /* Iterate over all variables to fill debug buffer */
            __for_each_variable_do(DebugIterator);
            
            /* Leave debug section,
             * Trigger asynchronous transmission 
             * (returns immediately) */
            InitiateDebugTransfer(); /* size */
        }else{
            /* when not debugging, do only retain */
            __for_each_variable_do(RetainIterator);
        }
        LeaveDebugSection();
    }else
#endif
    {
        /* when not debugging, do only retain */
        __for_each_variable_do(RetainIterator);
    }
    ValidateRetainBuffer();
}

#ifndef TARGET_ONLINE_DEBUG_DISABLE
#define __RegisterDebugVariable_case_t(TYPENAME) \
        case TYPENAME##_ENUM :\
            ((__IEC_##TYPENAME##_t *)varp)->flags |= flags;\
            if(force)\
             ((__IEC_##TYPENAME##_t *)varp)->value = *((TYPENAME *)force);\
            break;
#define __RegisterDebugVariable_case_p(TYPENAME)\
        case TYPENAME##_P_ENUM :\
            ((__IEC_##TYPENAME##_p *)varp)->flags |= flags;\
            if(force)\
             ((__IEC_##TYPENAME##_p *)varp)->fvalue = *((TYPENAME *)force);\
            break;\
        case TYPENAME##_O_ENUM :\
            ((__IEC_##TYPENAME##_p *)varp)->flags |= flags;\
            if(force){\
             ((__IEC_##TYPENAME##_p *)varp)->fvalue = *((TYPENAME *)force);\
             *(((__IEC_##TYPENAME##_p *)varp)->value) = *((TYPENAME *)force);\
            }\
            break;
void RegisterDebugVariable(unsigned int idx, void* force)
{
    if(idx  < sizeof(dbgvardsc)/sizeof(dbgvardsc_t)){
        unsigned char flags = force ?
            __IEC_DEBUG_FLAG | __IEC_FORCE_FLAG :
            __IEC_DEBUG_FLAG;
        dbgvardsc_t *dsc = &dbgvardsc[idx];
        void *varp = dsc->ptr;
        switch(dsc->type){
            __ANY(__RegisterDebugVariable_case_t)
            __ANY(__RegisterDebugVariable_case_p)
        default:
            break;
        }
    }
}

#define __ResetDebugVariablesIterator_case_t(TYPENAME) \
        case TYPENAME##_ENUM :\
            ((__IEC_##TYPENAME##_t *)varp)->flags &= ~(__IEC_DEBUG_FLAG|__IEC_FORCE_FLAG);\
            break;

#define __ResetDebugVariablesIterator_case_p(TYPENAME)\
        case TYPENAME##_P_ENUM :\
        case TYPENAME##_O_ENUM :\
            ((__IEC_##TYPENAME##_p *)varp)->flags &= ~(__IEC_DEBUG_FLAG|__IEC_FORCE_FLAG);\
            break;

void ResetDebugVariablesIterator(dbgvardsc_t *dsc)
{
    /* force debug flag to 0*/
    void *varp = dsc->ptr;
    switch(dsc->type){
        __ANY(__ResetDebugVariablesIterator_case_t)
        __ANY(__ResetDebugVariablesIterator_case_p)
    default:
        break;
    }
}

void ResetDebugVariables(void)
{
    __for_each_variable_do(ResetDebugVariablesIterator);
}

void FreeDebugData(void)
{
    /* atomically mark buffer as free */
    AtomicCompareExchange(
        &buffer_state,
        BUFFER_BUSY,
        BUFFER_FREE);
}
int WaitDebugData(unsigned long *tick);
/* Wait until debug data ready and return pointer to it */
int GetDebugData(unsigned long *tick, unsigned long *size, void **buffer){
    int wait_error = WaitDebugData(tick);
    if(!wait_error){
        *size = buffer_cursor - debug_buffer;
        *buffer = debug_buffer;
    }
    return wait_error;
}
#endif
#endif

