

#define __BOARD_C__

/* ------------------------------------------------------------------------ */

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#include "Lpuart_Lin_Ip.h"
#include "Lpuart_Uart_Ip.h"
#include "Lpuart_Uart_Ip_Irq.h"
#include "Clock_Ip.h"
#include "IntCtrl_Ip.h"
#include "Flexio_Mcl_Ip.h"
#include "Emios_Pwm_Ip.h"
#include "Emios_Mcl_Ip.h"
#include "Adc_Sar_Ip.h"
#include "FlexCAN_Ip.h"
#include "Siul2_Port_Ip.h"
#include "Siul2_Dio_Ip.h"
#include "Lpspi_Ip.h"
#include "Lpspi_Ip_BOARD_InitPeripherals_PBcfg.h"


#include "main.h"
#include "board.h"

#include "define.h"
#include "def_uds.h"
#include "uds.h"
#include "can.h"

#ifdef HW_LPI2C1
	#include "Lpi2c_Ip.h"
	#include "S32K344_SIUL2.h"
	#include "Lpi2c_Ip_Irq.h"
	#include "Lpi2c_Ip_BOARD_InitPeripherals_PBcfg.h"
	extern void LPI2C1_Master_Slave_IRQHandler(void);
	extern void LPI2C0_Master_Slave_IRQHandler(void);
#endif

extern void Adc_Sar_0_Isr(void);
extern void Adc_Sar_1_Isr(void);
extern void Adc_Sar_2_Isr(void);


/* ------------------------------------------------------------------------ */

u8	canfd_test_buf[64] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
						   0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
						   0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
						   0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F };

u8 hscan_test_buf[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};

uint8 rxBufferSlave[TRANSFER_SIZE] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
uint8 txBuffer[TRANSFER_SIZE] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7};

uint8 txBuffer_spi[10u] = {0,1,2,3,4,5,6,7,8,9};
uint8 rxBuffer_spi[10u];
uint16 numberOfBytes = 10u;
uint32 timeOut = 1000000u;
uint8 txBuff_lin[BUFFER_SIZE] = {0x01, 0x02, 0x03};
uint8 txBuff[BUFFER_SIZE] = {0x01, 0x02, 0x03};
volatile boolean isSend = FALSE;
/* ------------------------------------------------------------------------ */
uint64_t vcan_send_miss_message=0;

extern void CAN0_ORED_IRQHandler(void);
extern void CAN1_ORED_IRQHandler(void);
extern void CAN2_ORED_IRQHandler(void);
extern void CAN3_ORED_IRQHandler(void);
extern void CAN4_ORED_IRQHandler(void);
extern void CAN5_ORED_IRQHandler(void);

extern void CAN0_ORED_0_31_MB_IRQHandler(void);
extern void CAN1_ORED_0_31_MB_IRQHandler(void);
extern void CAN2_ORED_0_31_MB_IRQHandler(void);
extern void CAN3_ORED_0_31_MB_IRQHandler(void);
extern void CAN4_ORED_0_31_MB_IRQHandler(void);
extern void CAN5_ORED_0_31_MB_IRQHandler(void);

void setupCanTJA1153(int instance, Siul2_Dio_Ip_GpioType * const stb_port,Siul2_Dio_Ip_PinsChannelType stb_pin);

Flexcan_Ip_MsgBuffType can0_rxData[MAX_RX_MB];
Flexcan_Ip_MsgBuffType can1_rxData[MAX_RX_MB_1ch];
Flexcan_Ip_MsgBuffType can2_rxData[MAX_RX_MB];
Flexcan_Ip_MsgBuffType can3_rxData[MAX_RX_MB];
Flexcan_Ip_MsgBuffType can4_rxData[MAX_RX_MB];
Flexcan_Ip_MsgBuffType can5_rxData[MAX_RX_MB];

/* ------------------------------------------------------------------------ */

Flexcan_Ip_DataInfoType tx_info[6] = {
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	}


};

/* ------------------------------------------------------------------------ */

Flexcan_Ip_DataInfoType rx_info[6] = {
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	},
	{
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.data_length = 8u,
		.fd_enable = FALSE,
		.fd_padding = FALSE,
		.enable_brs = FALSE,
		.is_polling = FALSE,
		.is_remote = FALSE
	}

};
   const Flexcan_Ip_ConfigType FlexCAN_Config_500k  = {
    /* Number Of Message Buffer used .max_num_mb  */
    (uint8)24,
    /*Can Hw filter count* .num_id_filters*- aici exista variatna sa generez toate filtrele si sa referentiezi tu in cod */
    FLEXCAN_RX_FIFO_ID_FILTERS_8,
    /* Legacy FIFO ENABLED .is_rx_fifo_needed*/
    (boolean)FALSE,
#if (FEATURE_CAN_HAS_ENHANCED_RX_FIFO == STD_ON)
    /* The number of standard ID filter elements */
    0U,
    /* The number of extended ID filter elements */
    0U,
    /* The number of enhanced Rx FIFO watermark */
    0U,
    /* The Enhanced Rx FIFO feature is enabled or not. */
    (boolean)FALSE,
#endif
#if (FEATURE_CAN_HAS_HR_TIMER == STD_ON)
    /* TimeStamp Structure Configuration */
    {
        /* timeStampSurce Timer Source */
        FLEXCAN_CAN_CLK_TIMESTAMP_SRC,
        /* msgBuffTimeStampType Timestamp MB Type  */
        FLEXCAN_MSGBUFFTIMESTAMP_TIMER,
        /* hrConfigType Timestamp HR capture configuration */
        FLEXCAN_TIMESTAMPCAPTURE_DISABLE,
        /* hrSrc HT Timer Source */
        FLEXCAN_HRTIMERSRC_MAC,
    },
#endif
    FLEXCAN_NORMAL_MODE,
     /*ctrlOptions*/
    (uint32)(\
    CAN_BUSOFF_RECOVERY_U32 | \
    0U),
     /* Can FD RamBlock specified *//*.payload*/
    {
      FLEXCAN_PAYLOAD_SIZE_8,
      FLEXCAN_PAYLOAD_SIZE_8,
      FLEXCAN_PAYLOAD_SIZE_8
    },
        /*Can FD enabled .fd_enable*/
        (boolean)FALSE,
        /*Enhance CBT support . extCbtEnable*/
        (boolean)TRUE,
        /*BRS for FD .bitRateSwitch*/
        (boolean)FALSE,
        /*values for normal baudrate .bitrate*/
        {   /* Prop Seg */
            (20U),
            /* Phase Seg 1 */
            (41U),
            /* Phase Seg 2*/
            (15U),
            /* Pre Divider */
            (1U),
            /* Resync jump width */
            (14U)
        },
            /*values for FD baudrate .bitrate*/
        {   /* Prop Seg */
            (10U),
            /* Phase Seg 1 */
            (3U),
            /* Phase Seg 2*/
            (4U),
            /* Pre Divider */
            (1U),
            /* Resync jump width */
            (4U)
        },
        /*transfer_type*/
        FLEXCAN_RXFIFO_USING_INTERRUPTS,
#if (FEATURE_CAN_HAS_DMA_ENABLE == STD_ON)
     /* DMA channel number used for transfers. */
        0,
  #endif
    /* Controller Callback */
    // CAN4_Callback,
    /* Error Callback */
    // CAN4_ErrCallback
    };

/* ------------------------------------------------------------------------ */

   void
   pwm_init( u32 period )
   {
   	// deinit
   	Emios_Pwm_Ip_DeInitChannel(PWM_EMIOS_0,PWM_CH0);
   	Emios_Pwm_Ip_DeInitChannel(PWM_EMIOS_0,PWM_CH1);
   	Emios_Pwm_Ip_DeInitChannel(PWM_EMIOS_0,PWM_CH2);
   	Emios_Pwm_Ip_DeInitChannel(PWM_EMIOS_0,PWM_CH3);

   	Emios_Mcl_Ip_Deinit(PWM_EMIOS_0);

   	/* Initialize Emios_Mcl driver */
   	Emios_Mcl_Ip_Init(PWM_EMIOS_0, &Emios_Mcl_Ip_0_Config_BOARD_INITPERIPHERALS);

   	Emios_Mcl_Ip_SetCounterBusPeriod(PWM_EMIOS_0, Emios_Mcl_Ip_0_MasterBusConfig_BOARD_INITPERIPHERALS[0].hwChannel, period);

   	/* Initialize Emios_Pwm_Ip driver */
   	Emios_Pwm_Ip_InitChannel(EMIOS_PWM_IP_BOARD_InitPeripherals_I0_CH0_CFG, &Emios_Pwm_Ip_BOARD_InitPeripherals_I0_Ch0);
   	Emios_Pwm_Ip_InitChannel(EMIOS_PWM_IP_BOARD_InitPeripherals_I0_CH1_CFG, &Emios_Pwm_Ip_BOARD_InitPeripherals_I0_Ch1);
   	Emios_Pwm_Ip_InitChannel(EMIOS_PWM_IP_BOARD_InitPeripherals_I0_CH2_CFG, &Emios_Pwm_Ip_BOARD_InitPeripherals_I0_Ch2);
   	Emios_Pwm_Ip_InitChannel(EMIOS_PWM_IP_BOARD_InitPeripherals_I0_CH3_CFG, &Emios_Pwm_Ip_BOARD_InitPeripherals_I0_Ch3);



   }
   void
   Set_PWM_Duty( u32 ch, float ratio )
   {
   	u32	val;
   	//ratio 0 ~ 100 = 0% ~ 100%

   	if(ratio >= 100)	val = gb.pwm_max_tick;
   	else if(ratio <= 0)	val = 0;
   	else				val = (u32)(((float)gb.pwm_max_tick * ratio) / 100.0);

   	gb.pwm_duty[ch] = ratio;


   	switch(ch)
   	{
   		case 0: Emios_Pwm_Ip_SetDutyCycle(PWM_EMIOS_0, PWM_CH0, val);		break;
   		case 1: Emios_Pwm_Ip_SetDutyCycle(PWM_EMIOS_0, PWM_CH1, val);		break;
   		case 2: Emios_Pwm_Ip_SetDutyCycle(PWM_EMIOS_0, PWM_CH2, val);		break;
   		case 3: Emios_Pwm_Ip_SetDutyCycle(PWM_EMIOS_0, PWM_CH3, val);		break;

   	}

   }

/* ------------------------------------------------------------------------ */
uint8 passed;
uint8 init_ret;
uint8 trans_ret;
void SPI_init( void )
{

	init_ret=Lpspi_Ip_Init(&Lpspi_Ip_PhyUnitConfig_SpiPhyUnit_0_BOARD_InitPeripherals);
}

void SPI_test(void)
{
	uint8 count;

	passed = true;
    trans_ret=Lpspi_Ip_SyncTransmit(&Lpspi_Ip_DeviceAttributes_SpiExternalDevice_0_BOARD_InitPeripherals, txBuffer_spi, rxBuffer_spi, numberOfBytes, timeOut);

    for(count = 0; count < 10; count++)
    {
        if(txBuffer_spi[count] != rxBuffer_spi[count]) passed = FALSE;
    }
}
/* ------------------------------------------------------------------------ */

void Lin_init(void)
{
	IntCtrl_Ip_EnableIrq(LPUART1_IRQn);
	// IntCtrl_Ip_InstallHandler(LPUART1_IRQn, LPI2C1_Master_Slave_IRQHandler, NULL_PTR);

	IntCtrl_Ip_EnableIrq(LPUART9_IRQn);
	// IntCtrl_Ip_InstallHandler(LPUART9_IRQn, LPI2C1_Master_Slave_IRQHandler, NULL_PTR);
	/* Init lpuart lin */
	debug_printf("start\r\n");
	Lpuart_Lin_Ip_Init(LIN_INSTANCE_1, &Lpuart_Lin_Ip_pHwConfigPB_0_BOARD_INITPERIPHERALS);
	Lpuart_Lin_Ip_Init(LIN_INSTANCE_2, &Lpuart_Lin_Ip_pHwConfigPB_1_BOARD_INITPERIPHERALS);
	debug_printf("end\r\n");
}
void Lin1callback(uint32 instance, Lpuart_Lin_Ip_StateStructType *lpuartStateStruct)
{

    switch (lpuartStateStruct->currentEventId)
    {
        /* Header transmission ok */
        case LPUART_LIN_IP_PID_OK:
            isSend = TRUE;
            if (lpuartStateStruct->currentId == ID_1)
            {
                Lpuart_Lin_Ip_AsyncSendFrameData(instance, txBuff_lin, BUFFER_SIZE);
            }

            break;

        default:
        /* do nothing */
        break;
    }
}
void Lin2callback(uint32 instance, Lpuart_Lin_Ip_StateStructType *lpuartStateStruct)
{

    switch (lpuartStateStruct->currentEventId)
    {
        /* Header transmission ok */
        case LPUART_LIN_IP_PID_OK:
            isSend = TRUE;
            if (lpuartStateStruct->currentId == ID_2)
            {
                Lpuart_Lin_Ip_AsyncSendFrameData(instance, txBuff_lin, BUFFER_SIZE);
            }

            break;

        default:
        /* do nothing */
        break;
    }
}

void Lin_tx_test(uint8 instance)
{
	volatile uint32 timeoutValue = 0;
	uint8 bytesRemaining[BUFFER_SIZE];
    volatile Lpuart_Lin_Ip_StatusType transmissionStatus = LPUART_LIN_IP_STATUS_ERROR;


   /* Master start send header */
    Lpuart_Lin_Ip_MasterSendHeader(instance, ID_1);

    /* Wait for the transmission done */
    timeoutValue = 4*T_LIN_TIME_OUT;

    while (isSend == FALSE);

    if (isSend)
    {
        do
        {
            transmissionStatus = Lpuart_Lin_Ip_GetTransmitStatus(instance, bytesRemaining);
        }
        while ((0U != timeoutValue--) && (LPUART_LIN_IP_STATUS_SUCCESS != transmissionStatus));
    }


}


void
i2c0_init( void )
{
	IntCtrl_Ip_EnableIrq(LPI2C0_IRQn);
	IntCtrl_Ip_InstallHandler(LPI2C0_IRQn, LPI2C0_Master_Slave_IRQHandler, NULL_PTR);

	/* LPI2C0_SDA - PTD 13 */
	SIUL2->MSCR[109] =  SIUL2_MSCR_OBE(1)|SIUL2_MSCR_IBE(1)|SIUL2_MSCR_SSS_0(0)|SIUL2_MSCR_SSS_1(0)|SIUL2_MSCR_SSS_2(1);
	SIUL2->IMCR[214] = 2;

	/* LPI2C0_SCL PTD 14 */
	SIUL2->MSCR[110] =  SIUL2_MSCR_OBE(1)|SIUL2_MSCR_IBE(1)|SIUL2_MSCR_SSS_0(0)|SIUL2_MSCR_SSS_1(0)|SIUL2_MSCR_SSS_2(1);
	SIUL2->IMCR[212] = 2;

	/* Init slave module */
	Lpi2c_Ip_SlaveInit(I2C_SLAVE, &I2c_Lpi2cSlaveChannel1_BOARD_InitPeripherals);


}

/* ------------------------------------------------------------------------ */

void
i2c1_init( void )
{
#ifdef HW_LPI2C1
	u32	i;

	IntCtrl_Ip_EnableIrq(LPI2C1_IRQn);
	IntCtrl_Ip_InstallHandler(LPI2C1_IRQn, LPI2C1_Master_Slave_IRQHandler, NULL_PTR);

	/* LPI2C1_SDA - PTD 08 */
	SIUL2->MSCR[104] =  SIUL2_MSCR_OBE(1)|SIUL2_MSCR_IBE(1)|SIUL2_MSCR_SSS_0(0)|SIUL2_MSCR_SSS_1(1)|SIUL2_MSCR_SSS_2(0);
	SIUL2->IMCR[219] = 1;

	/* LPI2C1_SCL PTD 09 */
	SIUL2->MSCR[105] =  SIUL2_MSCR_OBE(1)|SIUL2_MSCR_IBE(1)|SIUL2_MSCR_SSS_0(0)|SIUL2_MSCR_SSS_1(1)|SIUL2_MSCR_SSS_2(0);
	SIUL2->IMCR[217] = 2;

	/* Init master module */
	Lpi2c_Ip_MasterInit(I2C_MASTER, &I2c_Lpi2cMasterChannel0_BOARD_InitPeripherals);
#else
	sda_out();
	I2C_SDA(APP_HIGH);
	I2C_SCL(APP_HIGH);
#endif
}




void i2c_test(void)
{

	uint32 mastertimeout = 0xFFFF;
	uint32 slavetimeout = 0xFFFF;
	uint8 checkOk=true;
	uint8 i;

	/* Set slave buffer */
	Lpi2c_Ip_SlaveSetBuffer(I2C_SLAVE, rxBufferSlave, TRANSFER_SIZE);
	
	/* Send data non-blocking */
	Lpi2c_Ip_MasterSendData(I2C_MASTER, txBuffer, TRANSFER_SIZE, TRUE);

	/* Wait master transfer to finish */
	while(((Lpi2c_Ip_MasterGetTransferStatus(I2C_MASTER, NULL_PTR)) == STATUS_LPI2C_IP_BUSY) && (mastertimeout > 0))
	{
		mastertimeout--;
	}
	
	/* Wait slave module to finish */
	while(((Lpi2c_Ip_SlaveGetTransferStatus(I2C_SLAVE, NULL_PTR)) == STATUS_LPI2C_IP_BUSY) && (slavetimeout > 0))
	{
		slavetimeout--;
	}


	//master -> slave
    /* Verify data received */
    for (i = 0; i < TRANSFER_SIZE; i ++)
    {
        if( txBuffer[i] != rxBufferSlave[i])
        {
        	checkOk = FALSE;
			// debug_printf("transfer_fail\r\n");
        }
		else
		{
			txBuffer[i]++;
		}
    }

}


/* ------------------------------------------------------------------------ */

void
sda_in( void )
{
#ifndef I2C_CROSS
	SIUL2->MSCR[32] =  SIUL2_MSCR_OBE(0)|SIUL2_MSCR_IBE(1)|SIUL2_MSCR_SSS_0(0)|SIUL2_MSCR_SSS_1(0)|SIUL2_MSCR_SSS_2(0);
	i2c_delay(I2C_DELAY);
#else
	SIUL2->MSCR[33] =  SIUL2_MSCR_OBE(0)|SIUL2_MSCR_IBE(1)|SIUL2_MSCR_SSS_0(0)|SIUL2_MSCR_SSS_1(0)|SIUL2_MSCR_SSS_2(0);
	i2c_delay(I2C_DELAY);
#endif
}

/* ------------------------------------------------------------------------ */

void
sda_out( void )
{
#ifndef I2C_CROSS
	SIUL2->MSCR[32] =  SIUL2_MSCR_OBE(1)|SIUL2_MSCR_IBE(1)|SIUL2_MSCR_SSS_0(0)|SIUL2_MSCR_SSS_1(0)|SIUL2_MSCR_SSS_2(0);
	i2c_delay(I2C_DELAY);
#else
	SIUL2->MSCR[33] =  SIUL2_MSCR_OBE(1)|SIUL2_MSCR_IBE(1)|SIUL2_MSCR_SSS_0(0)|SIUL2_MSCR_SSS_1(0)|SIUL2_MSCR_SSS_2(0);
	i2c_delay(I2C_DELAY);
#endif
}

/* ------------------------------------------------------------------------ */

void
i2c_delay( u32 tick )
{
	volatile u32	time;

	time = tick;
	while(time--);
}


/* ------------------------------------------------------------------------ */

void
CAN0_Callback( uint8_t instance, Flexcan_Ip_EventType eventType, uint32 buffIdx, const struct FlexCANState *driverState )
{

	u32	idx, i;


	(void)instance;
	(void)eventType;
	(void)buffIdx;
	(void)driverState;
	if(eventType == FLEXCAN_EVENT_RX_COMPLETE)
	{
		FlexCAN_Ip_Receive(CAN_INST_0, buffIdx, &can0_rxData[buffIdx], FALSE);
		idx = gb.can[instance].tail;
		gb.can[instance].msgId[idx] = can0_rxData[buffIdx].msgId;
		gb.can[instance].len[idx] = can0_rxData[buffIdx].dataLen;
		for(i=0; i<gb.can[instance].len[idx]; i++)	gb.can[instance].data[idx][i] = can0_rxData[buffIdx].data[i];
		gb.can[instance].tail = (gb.can[instance].tail + 1) % MAX_RX_RING;
		gb.can[instance].error = APP_FALSE;
	}

	else if(eventType == FLEXCAN_EVENT_TX_COMPLETE)
	{

	}
}

/* ------------------------------------------------------------------------ */

void
CAN0_ErrCallback( uint8 instance, Flexcan_Ip_EventType eventType, uint32 u32ErrStatus, const struct FlexCANState *driverState)
{
	(void)instance;
	(void)eventType;
	(void)u32ErrStatus;
	(void)driverState;

	if(eventType == FLEXCAN_EVENT_BUSOFF)
	{
		gb.can[0].bus_off = APP_TRUE;
		debug_printf("CAN0 bus off detected : %d\n", eventType);
		if(gb.can[0].bus_off_callback)	gb.can[0].bus_off_callback(gb.can[0].param);
		FlexCAN_Ip_Deinit(instance);
	}
	else
	{
		if(gb.can[0].error != APP_TRUE)
		{
			gb.can[0].error = APP_TRUE;
			debug_printf("CAN0-BUS error detected : %d\n\r", eventType);
		}
	}
}

/* ------------------------------------------------------------------------ */

void
CAN1_Callback( uint8_t instance, Flexcan_Ip_EventType eventType, uint32 buffIdx, const struct FlexCANState *driverState )
{
	u32	idx, i;

	(void)instance;
	(void)eventType;
	(void)buffIdx;
	(void)driverState;

	if(eventType == FLEXCAN_EVENT_RX_COMPLETE)
	{
		FlexCAN_Ip_Receive(CAN_INST_1, buffIdx, &can1_rxData[buffIdx], FALSE);
		idx = gb.can[instance].tail;
		gb.can[instance].msgId[idx] = can1_rxData[buffIdx].msgId;
		gb.can[instance].len[idx] = can1_rxData[buffIdx].dataLen;
		for(i=0; i<gb.can[instance].len[idx]; i++)	gb.can[instance].data[idx][i] = can1_rxData[buffIdx].data[i];
		gb.can[instance].tail = (gb.can[instance].tail + 1) % MAX_RX_RING;
		gb.can[instance].error = APP_FALSE;
	}

	else if(eventType == FLEXCAN_EVENT_TX_COMPLETE)
	{

	}

}

/* ------------------------------------------------------------------------ */

void
CAN1_ErrCallback( uint8 instance, Flexcan_Ip_EventType eventType, uint32 u32ErrStatus, const struct FlexCANState *driverState)
{
	(void)instance;
	(void)eventType;
	(void)u32ErrStatus;
	(void)driverState;

	if(eventType == FLEXCAN_EVENT_BUSOFF)
	{
		gb.can[1].bus_off = APP_TRUE;
		debug_printf("CAN1 bus off detected : %d\n", eventType);
		if(gb.can[1].bus_off_callback)	gb.can[1].bus_off_callback(gb.can[1].param);
		FlexCAN_Ip_Deinit(instance);
	}
	else
	{
		if(gb.can[1].error != APP_TRUE)
		{
			gb.can[1].error = APP_TRUE;
			//debug_printf("CAN1-BUS error detected : %d\n", eventType);
		}
	}
}

/* ------------------------------------------------------------------------ */

void
CAN2_Callback( uint8_t instance, Flexcan_Ip_EventType eventType, uint32 buffIdx, const struct FlexCANState *driverState )
{
	u32	idx, i;

	(void)instance;
	(void)eventType;
	(void)buffIdx;
	(void)driverState;
//	debug_printf("CAN2 : %d, %d\n", eventType, buffIdx);
	if(eventType == FLEXCAN_EVENT_RX_COMPLETE)
	{
		FlexCAN_Ip_Receive(CAN_INST_2, buffIdx, &can2_rxData[buffIdx], FALSE);
		idx = gb.can[instance].tail;
		gb.can[instance].msgId[idx] = can2_rxData[buffIdx].msgId;
		gb.can[instance].len[idx] = can2_rxData[buffIdx].dataLen;
		for(i=0; i<gb.can[instance].len[idx]; i++)	gb.can[instance].data[idx][i] = can2_rxData[buffIdx].data[i];
		gb.can[instance].tail = (gb.can[instance].tail + 1) % MAX_RX_RING;
		gb.can[instance].error = APP_FALSE;
	}
	else if(eventType == FLEXCAN_EVENT_TX_COMPLETE)
	{

	}
}

/* ------------------------------------------------------------------------ */

void
CAN2_ErrCallback( uint8 instance, Flexcan_Ip_EventType eventType, uint32 u32ErrStatus, const struct FlexCANState *driverState)
{
	(void)instance;
	(void)eventType;
	(void)u32ErrStatus;
	(void)driverState;

	if(eventType == FLEXCAN_EVENT_BUSOFF)
	{
		gb.can[2].bus_off = APP_TRUE;
		debug_printf("CAN2 bus off detected : %d\n", eventType);
		if(gb.can[2].bus_off_callback)	gb.can[2].bus_off_callback(gb.can[2].param);
		FlexCAN_Ip_Deinit(instance);
	}
	else
	{
		if(gb.can[2].error != APP_TRUE)
		{
			gb.can[2].error = APP_TRUE;
			debug_printf("CAN2-BUS error detected : %d\n", eventType);
		}
	}
}

/* ------------------------------------------------------------------------ */
void
CAN3_Callback( uint8_t instance, Flexcan_Ip_EventType eventType, uint32 buffIdx, const struct FlexCANState *driverState )
{
	u32	idx, i;

	(void)instance;
	(void)eventType;
	(void)buffIdx;
	(void)driverState;
	if(eventType == FLEXCAN_EVENT_RX_COMPLETE)
	{
		FlexCAN_Ip_Receive(CAN_INST_3, buffIdx, &can3_rxData[buffIdx], FALSE);
		idx = gb.can[instance].tail;
		gb.can[instance].msgId[idx] = can3_rxData[buffIdx].msgId;
		gb.can[instance].len[idx] = can3_rxData[buffIdx].dataLen;
		for(i=0; i<gb.can[instance].len[idx]; i++)	gb.can[instance].data[idx][i] = can3_rxData[buffIdx].data[i];
		gb.can[instance].tail = (gb.can[instance].tail + 1) % MAX_RX_RING;
		gb.can[instance].error = APP_FALSE;
	}
	else if(eventType == FLEXCAN_EVENT_TX_COMPLETE)
	{

	}
}

/* ------------------------------------------------------------------------ */

void
CAN3_ErrCallback( uint8 instance, Flexcan_Ip_EventType eventType, uint32 u32ErrStatus, const struct FlexCANState *driverState)
{
	(void)instance;
	(void)eventType;
	(void)u32ErrStatus;
	(void)driverState;

	if(eventType == FLEXCAN_EVENT_BUSOFF)
	{
		gb.can[instance].bus_off = APP_TRUE;
		debug_printf("CAN3 bus off detected : %d\n", eventType);
		if(gb.can[instance].bus_off_callback)	gb.can[instance].bus_off_callback(gb.can[instance].param);
		FlexCAN_Ip_Deinit(instance);
	}
	else
	{
		if(gb.can[instance].error != APP_TRUE)
		{
			gb.can[instance].error = APP_TRUE;
			debug_printf("CAN3-BUS error detected : %d\n\r", eventType);
		}
	}
}

/* ------------------------------------------------------------------------ */

void
CAN4_Callback( uint8_t instance, Flexcan_Ip_EventType eventType, uint32 buffIdx, const struct FlexCANState *driverState )
{
	u32	idx, i;

	(void)instance;
	(void)eventType;
	(void)buffIdx;
	(void)driverState;
	if(eventType == FLEXCAN_EVENT_RX_COMPLETE)
	{
		FlexCAN_Ip_Receive(CAN_INST_4, buffIdx, &can4_rxData[buffIdx], FALSE);
		idx = gb.can[instance].tail;
		gb.can[instance].msgId[idx] = can4_rxData[buffIdx].msgId;
		gb.can[instance].len[idx] = can4_rxData[buffIdx].dataLen;
		for(i=0; i<gb.can[instance].len[idx]; i++)	gb.can[instance].data[idx][i] = can4_rxData[buffIdx].data[i];
		gb.can[instance].tail = (gb.can[instance].tail + 1) % MAX_RX_RING;
		gb.can[instance].error = APP_FALSE;
	}
	else if(eventType == FLEXCAN_EVENT_TX_COMPLETE)
	{

	}
}

/* ------------------------------------------------------------------------ */

void
CAN4_ErrCallback( uint8 instance, Flexcan_Ip_EventType eventType, uint32 u32ErrStatus, const struct FlexCANState *driverState)
{
	(void)instance;
	(void)eventType;
	(void)u32ErrStatus;
	(void)driverState;

	if(eventType == FLEXCAN_EVENT_BUSOFF)
	{
		gb.can[instance].bus_off = APP_TRUE;
		debug_printf("CAN4 bus off detected : %d\n", eventType);
		if(gb.can[instance].bus_off_callback)	gb.can[instance].bus_off_callback(gb.can[instance].param);
		FlexCAN_Ip_Deinit(instance);
	}
	else
	{
		if(gb.can[instance].error != APP_TRUE)
		{
			gb.can[instance].error = APP_TRUE;
			debug_printf("CAN4-BUS error detected : %d\n\r", eventType);
		}
	}
}

/* ------------------------------------------------------------------------ */

void
CAN5_Callback( uint8_t instance, Flexcan_Ip_EventType eventType, uint32 buffIdx, const struct FlexCANState *driverState )
{
	u32	idx, i;

	(void)instance;
	(void)eventType;
	(void)buffIdx;
	(void)driverState;
	if(eventType == FLEXCAN_EVENT_RX_COMPLETE)
	{
		FlexCAN_Ip_Receive(CAN_INST_5, buffIdx, &can5_rxData[buffIdx], FALSE);
		idx = gb.can[instance].tail;
		gb.can[instance].msgId[idx] = can5_rxData[buffIdx].msgId;
		gb.can[instance].len[idx] = can5_rxData[buffIdx].dataLen;
		for(i=0; i<gb.can[instance].len[idx]; i++)	gb.can[instance].data[idx][i] = can5_rxData[buffIdx].data[i];
		gb.can[instance].tail = (gb.can[instance].tail + 1) % MAX_RX_RING;
		gb.can[instance].error = APP_FALSE;
	}
	else if(eventType == FLEXCAN_EVENT_TX_COMPLETE)
	{

	}
}

/* ------------------------------------------------------------------------ */

void
CAN5_ErrCallback( uint8 instance, Flexcan_Ip_EventType eventType, uint32 u32ErrStatus, const struct FlexCANState *driverState)
{
	(void)instance;
	(void)eventType;
	(void)u32ErrStatus;
	(void)driverState;

	if(eventType == FLEXCAN_EVENT_BUSOFF)
	{
		gb.can[instance].bus_off = APP_TRUE;
		debug_printf("CAN5 bus off detected : %d\n", eventType);
		if(gb.can[instance].bus_off_callback)	gb.can[instance].bus_off_callback(gb.can[instance].param);
		FlexCAN_Ip_Deinit(instance);
	}
	else
	{
		if(gb.can[instance].error != APP_TRUE)
		{
			gb.can[instance].error = APP_TRUE;
			debug_printf("CAN5-BUS error detected : %d\n\r", eventType);
		}
	}
}

/* ------------------------------------------------------------------------ */

int
get_can_data( u32 ch )
{
	if(gb.can[ch].head == gb.can[ch].tail)	return(APP_FALSE);

	return(APP_TRUE);
}

/* ------------------------------------------------------------------------ */

void
can_main_ECU3( void )
{
	u8 i;
	u32	idx;
	u8 ch_idx;

	//Can RX 
	for(uint8_t j=0;j<MAX_CAN_INST;j++){
		if(get_can_data(j) == APP_TRUE)
		{
			
			idx = gb.can[j].head;
			for(i=0;i<gb.can[j].len[idx];i++) {
				CAN_ch[j].rx.buf[i]	= gb.can[j].data[idx][i];
			}
			
			CAN_ch[j].rx.len = gb.can[j].len[idx];
			CAN_ch[j].rx.id = gb.can[j].msgId[idx];
			CAN_ch[j].rx.xreq	= TRUE;

			gb.can[j].head = (gb.can[j].head + 1) % MAX_RX_RING;
		}
	}


	if(CAN_ch[CAN_INST_0].rx.xreq == TRUE)
	{
		CAN_ch[CAN_INST_0].rx.xreq = FALSE;
		// // 2023 5 31 uds
		// if((CAN_ch[CAN_INST_0].rx.id == ID_UDS_RX) || (CAN_ch[CAN_INST_0].rx.id == ID_UDS_TP)){	

		// 	uds.rx.id = CAN_ch[CAN_INST_0].rx.id;	
		// 	uds.can_length = CAN_ch[CAN_INST_0].rx.len;
		// 	uds_logic_interrupt(CAN_ch[CAN_INST_0].rx.buf);
		// }
		switch (CAN_ch[CAN_INST_0].rx.id)
		{

		case ECU3_CH0_BCM_VCU_Signal1:
			Receive_BCM_VCU_Signal1_CH0_0x570();

			break;
		case ECU3_CH0_BCM_VCU_Signal2:
			Receive_BCM_VCU_Signal2_CH0_0x580();
//			GV_CH0_0x580_CNT++;
			break;
		case ECU3_CH0_BCM_VCU_Signal3:
			Receive_BCM_VCU_Signal3_CH0_0x590();
//			GV_CH0_0x590_CNT++;
			break;
		case ECU3_CH0_BCM_VCU_Signal4:
			Receive_BCM_VCU_Signal4_CH0_0x595();
//			GV_CH0_0x595_CNT++;
			break;
		case ECU3_CH0_BCM_VCU_Signal5:
			Receive_BCM_VCU_Signal5_CH0_0x585();
//			GV_CH0_0x585_CNT++;
			break;
		case ECU3_CH0_MCU_VCU_Signals1:
			Receive_MCU_VCU_Signals1_CH0_0x300();
//			GV_CH0_0x300_CNT++;
			break;
		case ECU3_CH0_MCU_VCU_Signals2:
			Receive_MCU_VCU_Signals2_CH0_0x301();
//			GV_CH0_0x301_CNT++;
			break;
		case ECU3_CH0_RC_VCU_Signal1:
			Receive_RC_VCU_Signal1_CH0_0x040();
			break;
		case ECU3_CH0_RC_VCU_Signal2:
			Receive_RC_VCU_Signal2_CH0_0x041();
			break;
		case ECU3_CH0_RX_IMU_TX1:
			Receive_IMU_TX1_CH0_0x174();
			break;
		case ECU3_CH0_RX_IMU_TX2:
			Receive_IMU_TX1_CH0_0x178();
			break;
		case ECU3_CH0_RX_IMU_TX3:
			Receive_IMU_TX1_CH0_0x17C();
			break;
		case ECU3_RC_VCU_BCM_Signal_1:
			Receive_RC_VCU_BCM_Signal_1_CH0_0x155();
			break;
		case ECU3_EPAM_VCU:
			Receive_EPAM_VCU_CH0_0x221();
			break;
		case ECU3_Receive_Debugging:
			Receive_Debugging_CH0_0x777();
			break;
		case ECU3_RC_VCU_Fault_Flag:
			Receive_RC_VCU_Fault_Flag_CH0_0x042();
			break;
		}
	}
	if(CAN_ch[CAN_INST_1].rx.xreq == TRUE)
	{
		CAN_ch[CAN_INST_1].rx.xreq = FALSE;

		switch (CAN_ch[CAN_INST_1].rx.id)
		{
		case ECU3_CH1_ACU_VCU_Signal1:
			Receive_ACU_VCU_Signal1_CH1_0x091();
			break;
		case ECU3_CH1_ACU_VCU_Signal2:
			Receive_ACU_VCU_Signal2_CH1_0x092();
			break;
		case ECU3_CH1_ACU_VCU_Signal3:
			Receive_ACU_VCU_Signal3_CH1_0x093();
			break;

		case ECU3_CH1_ACU_BCM_Signal_1://
			Receive_ACU_BCM_Signal_1_CH1_0x151();//
			break;//240227 異붽�


		}
	}
	if(CAN_ch[CAN_INST_2].rx.xreq == TRUE)
	{
		CAN_ch[CAN_INST_2].rx.xreq = FALSE;

		switch (CAN_ch[CAN_INST_2].rx.id)
		{

		case ECU3_CH2_IDB_BrakeStatus1:
			Receive_IDB_BrakeStatus1_CH2_0x09A();
			break;
		case ECU3_CH2_IDB_BrakeStatus2:
			Receive_IDB_BrakeStatus2_CH2_0x0C8();
			break;
		case ECU3_CH2_IDB_PressureStatus:
			Receive_IDB_PressureStatus_CH2_0x0A0();
			break;
		case ECU3_CH2_IDB_RegenTcsRequest:
			Receive_IDB_RegenTcsRequest_CH2_0x082();
			break;
		case ECU3_CH2_IDB_Status:
			Receive_IDB_Status_CH2_0x092();
			break;
		case ECU3_CH2_IDB_TireSlipStatus:
			Receive_IDB_TireSlipStatus_CH2_0x096();
			break;
		case ECU3_CH2_IDB_UdsResponse:
			Receive_IDB_UdsResponse_CH2_0x798();
			break;
		case ECU3_CH2_IDB_WheelStatus:
			Receive_IDB_WheelStatus_CH2_0x08C();
			break;
		case ECU3_CH2_RWA_Status1:
			Receive_RWA_Status1_CH2_0x072();
			break;
		case ECU3_CH2_RWA_Status2:
			Receive_RWA_Status2_CH2_0x073();
			break;
		case ECU3_CH2_RWA_Status3:
			Receive_RWA_Status3_CH2_0x0AA();
			break;
		}
	}
	if(CAN_ch[CAN_INST_3].rx.xreq == TRUE)
	{
		CAN_ch[CAN_INST_3].rx.xreq = FALSE;

		switch (CAN_ch[CAN_INST_3].rx.id)
		{

		case ECU3_CH3_RX_RCU_BrakeStatus1:
			Receive_RCU_BrakeStatus1_CH3_0x09B();
			break;
		case ECU3_CH3_RX_RCU_BrakeStatus2:
			Receive_RCU_BrakeStatus2_CH3_0x0C9();
			break;
		case ECU3_CH3_RX_RCU_PressureStatus:
			Receive_RCU_PressureStatus_CH3_0x0A1();
			break;
		case ECU3_CH3_RX_RWA_Status1:
			Receive_RWA_Status1_CH3_0x072();
			break;
		case ECU3_CH3_RX_RWA_Status2:
			Receive_RWA_Status2_CH3_0x073();
			break;
		case ECU3_CH3_RX_RWA_Status3:
			Receive_RWA_Status3_CH3_0x0AA();
			break;
		case ECU3_CH3_RX_RCU_TireSlipStatus:
			Receive_RCU_TireSlipStatus_CH3_0x097();
			break;
		case ECU3_CH3_RX_RCU_WheelStatus:
			Receive_RCU_WheelStatus_CH3_0x08D();
			break;
		case ECU3_CH3_RX_RCU_Status:
			Receive_RCU_Status_CH3_0x093();
			break;
		case ECU3_CH3_RX_RCU_UdsResponse:
			Receive_RCU_UdsResponse_CH3_0x799();
			break;
		}
	}
	if(CAN_ch[CAN_INST_4].rx.xreq == TRUE)
	{
		CAN_ch[CAN_INST_4].rx.xreq = FALSE;

		switch (CAN_ch[CAN_INST_4].rx.id)
		{

		case ECU3_CH4_RX_RWS_VCU_Rack_AngleFbk:
			Receive_RWS_VCU_Rack_AngleFbk_CH4_0x073();
			break;
		case ECU3_CH4_RX_RWS_VCU_stat_Signal:
			Receive_RWS_VCU_stat_Signal_CH4_0x072();
			break;

		}
	}
	if(CAN_ch[CAN_INST_5].rx.xreq == TRUE)
	{
		CAN_ch[CAN_INST_5].rx.xreq = FALSE;

		switch (CAN_ch[CAN_INST_5].rx.id)
		{

		case ECU3_CH5_RWS_VCU_Rack_AngleFbk:
			Receive_RWS_VCU_Rack_AngleFbk_CH5_0x073();
			break;
		case ECU3_CH5_RWS_VCU_stat_Signal:
			Receive_RWS_VCU_stat_Signal_CH5_0x072();
			break;

		}
	}
}

/* ------------------------------------------------------------------------ */



int
Can_Init_ECU3( int ch )
{

	uint8 idx;
	uint8 ret;

	if(ch == 0)
	{

		//CAN 0,
	
		// CAN0 error
		IntCtrl_Ip_EnableIrq(FlexCAN0_0_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN0_0_IRQn, CAN0_ORED_IRQHandler, NULL_PTR);

		// CAN0 receive
		IntCtrl_Ip_EnableIrq(FlexCAN0_1_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN0_1_IRQn, CAN0_ORED_0_31_MB_IRQHandler, NULL_PTR);

		//CAN0_IC_EN
		Siul2_Dio_Ip_WritePin(CAN0_EN_PORT, CAN0_EN_PIN, APP_HIGH);
		Siul2_Dio_Ip_WritePin(CAN0_STB_N_PORT, CAN0_STB_N_PIN, APP_HIGH);

		FlexCAN_Ip_Init(CAN_INST_0, &FlexCAN_State0, &FlexCAN_Config0);


		FlexCAN_Ip_SetRxMaskType_Privileged(INST_FLEXCAN_0,FLEXCAN_RX_MASK_INDIVIDUAL);
		FlexCAN_Ip_SetRxIndividualMask_Privileged(INST_FLEXCAN_0,RX_MB_IDX,0x000);
		FlexCAN_Ip_SetStartMode(INST_FLEXCAN_0);

		FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_0, RX_MB_IDX, &rx_info[ch], 0x000);
		FlexCAN_Ip_Receive(CAN_INST_0, RX_MB_IDX, &can0_rxData[RX_MB_IDX], FALSE);

		ECU3_Data_Init();
		clear_tx_buf(ch);
		gb.can[ch].bus_off = APP_FALSE;
		gb.can[ch].error = APP_FALSE;
	}


	if(ch == 1)
	{

		// CAN 1
		
		// CAN1 error
		IntCtrl_Ip_EnableIrq(FlexCAN1_0_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN1_0_IRQn, CAN1_ORED_IRQHandler, NULL_PTR);

		// CAN1 receive
		IntCtrl_Ip_EnableIrq(FlexCAN1_1_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN1_1_IRQn, CAN1_ORED_0_31_MB_IRQHandler, NULL_PTR);

		//CAN1_IC_EN
		Siul2_Dio_Ip_WritePin(CAN1_EN_PORT, CAN1_EN_PIN, APP_HIGH);
		Siul2_Dio_Ip_WritePin(CAN1_STB_N_PORT, CAN1_STB_N_PIN, APP_HIGH);


		

		FlexCAN_Ip_Init(CAN_INST_1, &FlexCAN_State1, &FlexCAN_Config1);
		FlexCAN_Ip_SetStartMode(CAN_INST_1);



		// ================= RXID Setting (RX_MB 4~23) MAX 20ea
		idx = 0;

		for(uint8_t i=0;i<NUMBER_OF_ECU3_CH1_RX_MESSAGE;i++)
		{
			FlexCAN_Ip_ConfigRxMb(CAN_INST_1, RX_MB_IDX_1ch+idx, &rx_info[ch], g_messageObjectConf_ECU3_1ch_RX[i].messageId);
			FlexCAN_Ip_Receive(CAN_INST_1, RX_MB_IDX_1ch+idx, &can1_rxData[RX_MB_IDX_1ch+idx], FALSE);
			idx++;
		}
	
		// ================= RXID Setting finish


		gb.can[ch].bus_off = APP_FALSE;
		gb.can[ch].error = APP_FALSE;
	}
	if(ch == 2)
	{

		// CAN 2
		
		// CAN2 error
		IntCtrl_Ip_EnableIrq(FlexCAN2_0_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN2_0_IRQn, CAN2_ORED_IRQHandler, NULL_PTR);

		// CAN2 receive
		IntCtrl_Ip_EnableIrq(FlexCAN2_1_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN2_1_IRQn, CAN2_ORED_0_31_MB_IRQHandler, NULL_PTR);

		//CAN2_IC_EN
		Siul2_Dio_Ip_WritePin(CAN2_EN_PORT, CAN2_EN_PIN, APP_HIGH);
		Siul2_Dio_Ip_WritePin(CAN2_STB_N_PORT, CAN2_STB_N_PIN, APP_HIGH);


		

		FlexCAN_Ip_Init(CAN_INST_2, &FlexCAN_State2, &FlexCAN_Config2);
		FlexCAN_Ip_SetStartMode(CAN_INST_2);



		// ================= RXID Setting (RX_MB 4~23) MAX 20ea
		idx = 0;

		for(uint8_t i=0;i<NUMBER_OF_ECU3_CH2_RX_MESSAGE;i++)
		{
			FlexCAN_Ip_ConfigRxMb(CAN_INST_2, RX_MB_IDX+idx, &rx_info[ch], g_messageObjectConf_ECU3_2ch_RX[i].messageId);
			FlexCAN_Ip_Receive(CAN_INST_2, RX_MB_IDX+idx, &can2_rxData[RX_MB_IDX+idx], FALSE);
			idx++;
		}
	
		// ================= RXID Setting finish


		gb.can[ch].bus_off = APP_FALSE;
		gb.can[ch].error = APP_FALSE;
	}

	if(ch == 3)
	{

		// CAN 3
		
		// CAN1 error
		IntCtrl_Ip_EnableIrq(FlexCAN3_0_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN3_0_IRQn, CAN3_ORED_IRQHandler, NULL_PTR);

		// CAN1 receive
		IntCtrl_Ip_EnableIrq(FlexCAN3_1_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN3_1_IRQn, CAN3_ORED_0_31_MB_IRQHandler, NULL_PTR);

		//CAN1_IC_EN
		Siul2_Dio_Ip_WritePin(CAN3_EN_PORT, CAN3_EN_PIN, APP_HIGH);
		Siul2_Dio_Ip_WritePin(CAN3_STB_N_PORT, CAN3_STB_N_PIN, APP_HIGH);


		

		FlexCAN_Ip_Init(CAN_INST_3, &FlexCAN_State3, &FlexCAN_Config3);
		FlexCAN_Ip_SetStartMode(CAN_INST_3);



		// ================= RXID Setting (RX_MB 4~23) MAX 20ea
		idx = 0;

		for(uint8_t i=0;i<NUMBER_OF_ECU3_CH3_RX_MESSAGE;i++)
		{
			FlexCAN_Ip_ConfigRxMb(CAN_INST_3, RX_MB_IDX+idx, &rx_info[ch], g_messageObjectConf_ECU3_3ch_RX[i].messageId);
			FlexCAN_Ip_Receive(CAN_INST_3, RX_MB_IDX+idx, &can3_rxData[RX_MB_IDX+idx], FALSE);
			idx++;
		}
	
		// ================= RXID Setting finish


		gb.can[ch].bus_off = APP_FALSE;
		gb.can[ch].error = APP_FALSE;
	}

	if(ch == 4)
	{

		// CAN 4
		
		// CAN4 error
		IntCtrl_Ip_EnableIrq(FlexCAN4_0_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN4_0_IRQn, CAN4_ORED_IRQHandler, NULL_PTR);

		// CAN4 receive
		IntCtrl_Ip_EnableIrq(FlexCAN4_1_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN4_1_IRQn, CAN4_ORED_0_31_MB_IRQHandler, NULL_PTR);

		//CAN1_IC_EN
		Siul2_Dio_Ip_WritePin(CAN4_EN_PORT, CAN4_EN_PIN, APP_HIGH);
		Siul2_Dio_Ip_WritePin(CAN4_STB_N_PORT, CAN4_STB_N_PIN, APP_HIGH);

		#if(BOARD_TYPE == EVB_BOARD)
		FlexCAN_Ip_Init(CAN_INST_4, &FlexCAN_State4, &FlexCAN_Config_500k);
		FlexCAN_Ip_SetStartMode(CAN_INST_4);
		
		setupCanTJA1153(ch,CAN4_STB_N_PORT,CAN4_STB_N_PIN);
		#endif


		FlexCAN_Ip_Init(CAN_INST_4, &FlexCAN_State4, &FlexCAN_Config4);
		FlexCAN_Ip_SetStartMode(CAN_INST_4);
		// setupCanTJA1153(ch,CAN4_STB_N_PORT,CAN4_STB_N_PIN);


		// ================= RXID Setting (RX_MB 4~23) MAX 20ea
		idx = 0;

		for(uint8_t i=0;i<NUMBER_OF_ECU3_CH4_RX_MESSAGE;i++)
		{
			FlexCAN_Ip_ConfigRxMb(CAN_INST_4, RX_MB_IDX+idx, &rx_info[ch], g_messageObjectConf_ECU3_4ch_RX[i].messageId);
			FlexCAN_Ip_Receive(CAN_INST_4, RX_MB_IDX+idx, &can4_rxData[RX_MB_IDX+idx], FALSE);
			idx++;
		}
	
		// ================= RXID Setting finish


		gb.can[ch].bus_off = APP_FALSE;
		gb.can[ch].error = APP_FALSE;
	}

	if(ch == 5)
	{

		// CAN 5
		
		// CAN5 error
		IntCtrl_Ip_EnableIrq(FlexCAN5_0_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN5_0_IRQn, CAN5_ORED_IRQHandler, NULL_PTR);

		// CAN5 receive
		IntCtrl_Ip_EnableIrq(FlexCAN5_1_IRQn);
		IntCtrl_Ip_InstallHandler(FlexCAN5_1_IRQn, CAN5_ORED_0_31_MB_IRQHandler, NULL_PTR);

		//CAN5_IC_EN
		Siul2_Dio_Ip_WritePin(CAN5_EN_PORT, CAN5_EN_PIN, APP_HIGH);
		Siul2_Dio_Ip_WritePin(CAN5_STB_N_PORT, CAN5_STB_N_PIN, APP_HIGH);


		
		#if(BOARD_TYPE == EVB_BOARD)
		FlexCAN_Ip_Init(CAN_INST_5, &FlexCAN_State5, &FlexCAN_Config_500k);
		FlexCAN_Ip_SetStartMode(CAN_INST_5);
		
		setupCanTJA1153(ch,CAN5_STB_N_PORT,CAN5_STB_N_PIN);
		#endif


		FlexCAN_Ip_Init(CAN_INST_5, &FlexCAN_State5, &FlexCAN_Config5);
		FlexCAN_Ip_SetStartMode(CAN_INST_5);


		// ================= RXID Setting (RX_MB 4~23) MAX 20ea
		idx = 0;

		for(uint8_t i=0;i<NUMBER_OF_ECU3_CH5_RX_MESSAGE;i++)
		{
			FlexCAN_Ip_ConfigRxMb(CAN_INST_5, RX_MB_IDX+idx, &rx_info[ch], g_messageObjectConf_ECU3_5ch_RX[i].messageId);
			FlexCAN_Ip_Receive(CAN_INST_5, RX_MB_IDX+idx, &can5_rxData[RX_MB_IDX+idx], FALSE);
			idx++;
		}
	
		// ================= RXID Setting finish


		gb.can[ch].bus_off = APP_FALSE;
		gb.can[ch].error = APP_FALSE;
	}



	CAN_ch[ch].p_rd = 0;
	CAN_ch[ch].p_wr = 0;
	for(uint8_t i=0;i<MAX_TX_RING;i++)
	{
		CAN_ch[ch].tx_ring[i].xreq = 0;
	}

	return(APP_TRUE);
}


void ECU3_Data_Init( void )
{
	//---------------------------------------- CH0 RX ----------------------------------------//
	//    ECU3.RX.CH0_CAR_STAT_CH0_0x012.CAR_ARC = 0;

	ECU3.RX.CH0_RC_VCU_Signal1_0x040.RC_BrakeTorqueCommand		= 0;
    ECU3.RX.CH0_RC_VCU_Signal1_0x040.RC_RWA_RackAngleCommand	= 33250;
    ECU3.RX.CH0_RC_VCU_Signal1_0x040.RC_Drive_ACC_Cmd			= 0;
    ECU3.RX.CH0_RC_VCU_Signal1_0x040.RC_Vx_Command  			= 0;
    ECU3.RX.CH0_RC_VCU_Signal1_0x040.RC_VCU_counter1 	 		= 0;
    ECU3.RX.CH0_RC_VCU_Signal1_0x040.RC_VCU_CRC1				= 0;

    ECU3.RX.CH0_RC_VCU_Signal2_0x041.RC_Drive_Mode 		 	= 0;
    ECU3.RX.CH0_RC_VCU_Signal2_0x041.RC_GearSelStat 		= 0;
    ECU3.RX.CH0_RC_VCU_Signal2_0x041.RC_ParkBrake_Cmd 	 	= 0;
    ECU3.RX.CH0_RC_VCU_Signal2_0x041.RC_Emergency_Stop 	 	= 0;
    ECU3.RX.CH0_RC_VCU_Signal2_0x041.RC_VCU_long_Ctl_mode	= 0;
    ECU3.RX.CH0_RC_VCU_Signal2_0x041.RC_VCU_ARC 		 	= 0;
//    ECU3.RX.CH0_RC_VCU_Signal2_0x041.RC_VCU_CRC2 			 = 0;

    ECU3.RX.CH0_RX_RC_VCU_Fault_Flag_0x042.ACU_Fault_Flag			= 0;
    ECU3.RX.CH0_RX_RC_VCU_Fault_Flag_0x042.MCU_Actuator_Fault_Flag	= 0;
    ECU3.RX.CH0_RX_RC_VCU_Fault_Flag_0x042.RWA_Actuator_Fault_Flag	= 0;

    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Lamp_BRAKE_CMD 	= 0;
    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Lamp_Hazard_CMD 	= 0;
    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Lamp_HBEAM_CMD 	= 0;
    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Lamp_Head_CMD 	= 0;
    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Lamp_LTRN_CMD 	= 0;
    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Lamp_Reverse_CMD  = 0;
    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Lamp_RTRN_CMD 	= 0;
    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Lamp_Position_CMD	= 0;
    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Lamp_DRL_CMD 	 	= 0;
    ECU3.RX.CH0_RC_VCU_BCM_Signal_1_CH0_0x155.Wiper_CMD 		= 0;

    ECU3.RX.CH0_RX_EPAM_VCU_0x221.EPAM_driveSensor 	 	 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.EPAM_parkSensor 	 		= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.EPAM_parkLock 	 		= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.EPAM_ParkRequestStatus 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.EPAM_Voltage 	 		 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.EPAM_Current  			= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.EPAM_Temperature 	 	 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.EPAM_HallPosition 		= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_MotStallMiddle    = 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_MotStallUnPark 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_MotStallPark 	 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_MotOpen 		    = 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_MotFail 		 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.EPAM_State 		 		= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_CommErr 		 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_HallSenErr 		= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_OT_ECU 		 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_CANErr 		 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_HallPaternError 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_HallTimeOut 		= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_DCBusUnderVoltage	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_DCBusOverVoltage 	= 0;
    ECU3.RX.CH0_RX_EPAM_VCU_0x221.ErrEPAM_DCBusOverCurrent 	= 0;

	ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_Ready 		= 0;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_Controlable	= 0;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_Flt 			= 0;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_Interlock 	= 0;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_CurGearSta 	= 0;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_GearStaInv 	= 0;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_Derating 	= 0;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_SvrFlt 		= 0;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_MtrTemp 		= 50;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_InvTemp		= 0;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_EstSpd		= 32768;
    ECU3.RX.CH0_MCU_VCU_Signals1_0x300.MCU_EstTrq		= 20000;

    ECU3.RX.CH0_MCU_VCU_Signals2_0x301.FaultMessage1 = 0;
    ECU3.RX.CH0_MCU_VCU_Signals2_0x301.FaultMessage2 = 0;

	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Lamp_RTRN  		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Lamp_Reverse  	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Lamp_LTRN  		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Lamp_Head  		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Lamp_HBEAM  		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Lamp_Hazard		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Lamp_BRAKE  		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Status_Wiper  	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.BCM_CE1_STA		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.BCM_CE2_STA 		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.BCM_CE3_STA 		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.BCM_CE4_STA 		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.BCM_CE5_STA 		= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.BCM_MAINSW_STA 	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Battery_Voltage	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Lamp_DRL			= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.Lamp_Position 	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.BCM_VCU_counter1	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal1_0x570.BCM_VCU_CRC1		= 0;

    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.ChargingStatus 	= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.BCM_ChgeCon_DTD 	= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.BMS_HVOn_STA		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.IntLckSta_OBC 	= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.IntLckSta_BMS 	= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.BMS_SOC 			= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.BMS_SOH 			= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.CommSta_OBC 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.CommSta_VCU 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.CommSta_BMS 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.CommSta_LDC 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.CommSta_TMS 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.BMS_SOH_INV 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.BMS_SOC_INV 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.Bms_Soc_Wrng		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.Bms_SoH_Wrng 	 	= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.BCM_VCU_counter2	= 0;
    ECU3.RX.CH0_BCM_VCU_Signal2_0x580.BCM_VCU_CRC2		= 0;

    ECU3.RX.CH0_BCM_VCU_Signal5_0x585.OBC_FltSta       	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal5_0x585.BMS_FltSta       	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal5_0x585.LDC_FltSta       	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal5_0x585.BCM_FltSta       	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal5_0x585.BMS_TEMP_FAULT   	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal5_0x585.LDC_TEMP_FAULT   	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal5_0x585.OBC_TEMP_FAULT   	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal5_0x585.BCM_VCU_counter5	= 0;
	ECU3.RX.CH0_BCM_VCU_Signal5_0x585.BCM_VCU_CRC5     	= 0;

    ECU3.RX.CH0_BCM_VCU_Signal3_0x590.Bms_PackVolt 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal3_0x590.Bms_PackCur 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal3_0x590.Bms_PackPwr 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal3_0x590.BCM_VCU_counter3 	= 0;
    ECU3.RX.CH0_BCM_VCU_Signal3_0x590.BCM_VCU_CRC3 		= 0;

    ECU3.RX.CH0_BCM_VCU_Signal4_0x595.LDC_ACTL_CUR 		= 0;
    ECU3.RX.CH0_BCM_VCU_Signal4_0x595.LDC_INP_VOLT    	= 0;



    //---------------------------------------- CH1 RX ----------------------------------------//
    ECU3.RX.CH1_ACU_VCU_Signal1_0x091.ACU_Vx_Command 	 		= 0;
    ECU3.RX.CH1_ACU_VCU_Signal1_0x091.ACU_Drive_ACC_Cmd		 	= 0;
    ECU3.RX.CH1_ACU_VCU_Signal1_0x091.ACU_BrakeTorqueCommand	= 0;
    ECU3.RX.CH1_ACU_VCU_Signal1_0x091.ACU_VCU_counter1	 		= 0;
    ECU3.RX.CH1_ACU_VCU_Signal1_0x091.ACU_VCU_CRC1		 		= 0;

    ECU3.RX.CH1_ACU_VCU_Signal2_0x092.ACU_RWA_cmd_deg	= 0;
    ECU3.RX.CH1_ACU_VCU_Signal2_0x092.ACU_RWS_cmd_deg 	= 0;
    ECU3.RX.CH1_ACU_VCU_Signal2_0x092.ACU_VCU_counter2	= 0;
    ECU3.RX.CH1_ACU_VCU_Signal2_0x092.ACU_VCU_CRC2 		= 0;

    ECU3.RX.CH1_ACU_VCU_Signal3_0x093.ACU_Drive_mode 	 	= 0;
    ECU3.RX.CH1_ACU_VCU_Signal3_0x093.ACU_long_Ctl_mode 	= 0;
    ECU3.RX.CH1_ACU_VCU_Signal3_0x093.ACU_EPAM_req 	 		= 0;
    ECU3.RX.CH1_ACU_VCU_Signal3_0x093.ACU_VCU_GearPos  		= 0;
    ECU3.RX.CH1_ACU_VCU_Signal3_0x093.ACU_Emergency_Stop	= 0;
    ECU3.RX.CH1_ACU_VCU_Signal3_0x093.ACU_VCU_counter3 		= 0;
    ECU3.RX.CH1_ACU_VCU_Signal3_0x093.ACU_VCU_CRC3 			= 0;

	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Lamp_BRAKE_CMD 	 	= 0; //
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Lamp_Hazard_CMD 	 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Lamp_HBEAM_CMD 	 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Lamp_Head_CMD 	 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Lamp_LTRN_CMD 	 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Lamp_Reverse_CMD  	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Lamp_RTRN_CMD 	 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Lamp_Position_CMD	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Lamp_DRL_CMD 	 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Wiper_CMD 		 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.LDC_ACT_CMD 		 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.HV_ON_CMD 		 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.CE_ON_CMD 		 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.LDC_TRGT_CUR 	 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Vcu_OperMode 	 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.Vcu_SysMode 		 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.ACU_VCU_counter 	 	= 0;
	ECU3.RX.CH1_ACU_BCM_Signal_1_0x151.ACU_VCU_CRC 		 	= 0;



	//---------------------------------------- CH2 RX ----------------------------------------//
    ECU3.RX.CH2_RWA_Status1_0x072.Arc 					 = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.Crc 					 = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.EcuPowerMode 			 = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.EcuRole 				 = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.EcuStatus 			 = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.MaxMotorOutput 		 = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.MaxMotorOutputValid 	 = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.RackAngleSpeedFbk 	 = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.RackAngleSpeedFbkValid = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.SysInfo 				 = 0;
    ECU3.RX.CH2_RWA_Status1_0x072.WarningLamp 			 = 0;

    ECU3.RX.CH2_RWA_Status2_0x073.Arc 				= 0;
    ECU3.RX.CH2_RWA_Status2_0x073.Crc 				= 0;
    ECU3.RX.CH2_RWA_Status2_0x073.RackAngleFbk 		= 0;
    ECU3.RX.CH2_RWA_Status2_0x073.RackAngleFbkValid = 0;
    ECU3.RX.CH2_RWA_Status2_0x073.RackForceFbk 		= 0;
    ECU3.RX.CH2_RWA_Status2_0x073.RackForceFbkValid = 0;

	ECU3.RX.CH2_IDB_RegenTcsRequest_0x082.Arc 					= 0;
    ECU3.RX.CH2_IDB_RegenTcsRequest_0x082.Crc 					= 0;
    ECU3.RX.CH2_IDB_RegenTcsRequest_0x082.RbcTargetRegenTorque 	= 0;
    ECU3.RX.CH2_IDB_RegenTcsRequest_0x082.TcsTorqueCmd 			= 0;

    ECU3.RX.CH2_IDB_WheelStatus_0x08C.Arc 							= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.Crc 							= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.FrontLeftWheelDirection 		= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.FrontLeftWheelPulse 			= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.FrontLeftWheelPulseValidity 	= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.FrontLeftWssFault 			= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.FrontRightWheelDirection 		= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.FrontRightWheelPulse 			= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.FrontRightWheelPulseValidity 	= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.FrontRightWssFault 			= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.RearLeftWheelDirection 		= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.RearLeftWheelPulse 			= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.RearLeftWheelPulseValidity 	= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.RearLeftWssFault 				= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.RearRightWheelDirection 		= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.RearRightWheelPulse 			= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.RearRightWheelPulseValidity 	= 0;
    ECU3.RX.CH2_IDB_WheelStatus_0x08C.RearRightWssFault 			= 0;

    ECU3.RX.CH2_IDB_Status_0x092.AbsFault 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.AbsState 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.Arc 							= 0;
    ECU3.RX.CH2_IDB_Status_0x092.BbsFault 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.BbsState 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.CanCommunicationFault 			= 0;
    ECU3.RX.CH2_IDB_Status_0x092.Crc 							= 0;
    ECU3.RX.CH2_IDB_Status_0x092.EbdFault 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.EbdState 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.EpbFault 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.EpbState 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.EpbTransition 					= 0;
    ECU3.RX.CH2_IDB_Status_0x092.EscFault 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.EscState 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.EscYawRateThreshold 			= 0;
    ECU3.RX.CH2_IDB_Status_0x092.InternalCanCommunicationFault	= 0;
    ECU3.RX.CH2_IDB_Status_0x092.RbcFault 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.RbcState 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.RopFault 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.RopState 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.SplitMuDetection 				= 0;
    ECU3.RX.CH2_IDB_Status_0x092.SsmFault 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.SsmState 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.TcsFault 						= 0;
    ECU3.RX.CH2_IDB_Status_0x092.TcsState 						= 0;

    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.Arc 						= 0;
    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.Crc 						= 0;
    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.FrontLeftTireSlipRatio 	= 0;
    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.FrontLeftWheelSlipStatus 	= 0;
    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.FrontRightTireSlipRatio 	= 0;
    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.FrontRightWheelSlipStatus	= 0;
    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.RearLeftTireSlipRatio 		= 0;
    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.RearLeftWheelSlipStatus 	= 0;
    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.RearRightTireSlipRatio 	= 0;
    ECU3.RX.CH2_IDB_TireSlipStatus_0x096.RearRightWheelSlipStatus 	= 0;

	ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.Arc 							= 0;
    ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.Crc 							= 0;
    ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.EcuRole 						= 0;
    ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.EcuStatus 					= 0;
    ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.EstimatedVehicleSpeed		= 303;
    ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.IsControllingEcu 			= 0;
    ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.MasterCylinderPressure 		= 0;
    ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.RoadFrictionCoefficient 		= 0;
    ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.RoadFrictionCoefficientValid	= 0;
    ECU3.RX.CH2_IDB_BrakeStatus1_0x09A.VehicleSpeedValidity 		= 0;

    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.Arc 								= 0;
    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.Crc 								= 0;
    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.FrontLeftEstimatedPressure 		= 0;
    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.FrontLeftEstimatedPressureValid 	= 0;
    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.FrontRightEstimatedPressure 		= 0;
    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.FrontRightEstimatedPressureValid	= 0;
    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.RearLeftEstimatedPressure 			= 0;
    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.RearLeftEstimatedPressureValid 	= 0;
    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.RearRightEstimatedPressure 		= 0;
    ECU3.RX.CH2_IDB_PressureStatus_0x0A0.RearRightEstimatedPressureValid 	= 0;

    ECU3.RX.CH2_RWA_Status3_0x0AA.Arc 				= 0;
    ECU3.RX.CH2_RWA_Status3_0x0AA.Crc 				= 0;
    ECU3.RX.CH2_RWA_Status3_0x0AA.PolFault 			= 1;
    ECU3.RX.CH2_RWA_Status3_0x0AA.PolLimiterFlag 	= 0;
    ECU3.RX.CH2_RWA_Status3_0x0AA.PolStatus 		= 0;
    ECU3.RX.CH2_RWA_Status3_0x0AA.PolValue 			= 0;
    ECU3.RX.CH2_RWA_Status3_0x0AA.SysBatteryVoltage = 0;
    ECU3.RX.CH2_RWA_Status3_0x0AA.SysIqCurrent 		= 0;

    ECU3.RX.CH2_IDB_UdsResponse_0x798.UdsResponse 		= 0;
	ECU3.RX.CH2_IDB_UdsResponse_0x798.UdsResponse_MSB 	= 0;
	ECU3.RX.CH2_IDB_UdsResponse_0x798.UdsResponse_LSB 	= 0;



    //---------------------------------------- CH3 RX ----------------------------------------//
    ECU3.RX.CH3_RWA_Status1_0x072.Arc  						= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.Crc  						= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.EcuPowerMode  			= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.EcuRole  					= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.EcuStatus  				= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.MaxMotorOutput  			= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.MaxMotorOutputValid  		= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.RackAngleSpeedFbk  		= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.RackAngleSpeedFbkValid  	= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.SysInfo 					= 0;
    ECU3.RX.CH3_RWA_Status1_0x072.WarningLamp 				= 0;

    ECU3.RX.CH3_RWA_Status2_0x073.Arc 				= 0;
    ECU3.RX.CH3_RWA_Status2_0x073.Crc 				= 0;
    ECU3.RX.CH3_RWA_Status2_0x073.RackAngleFbk 		= 0;
    ECU3.RX.CH3_RWA_Status2_0x073.RackAngleFbkValid = 0;
    ECU3.RX.CH3_RWA_Status2_0x073.RackForceFbk 		= 0;
    ECU3.RX.CH3_RWA_Status2_0x073.RackForceFbkValid = 0;

    ECU3.RX.CH3_RCU_WheelStatus_0x08D.Arc 							= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.Crc 							= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.FrontLeftWheelDirection 		= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.FrontLeftWheelPulse 			= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.FrontLeftWheelPulseValidity 	= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.FrontLeftWssFault 			= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.FrontRightWheelDirection 		= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.FrontRightWheelPulse 			= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.FrontRightWheelPulseValidity 	= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.FrontRightWssFault 			= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.RearLeftWheelDirection 		= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.RearLeftWheelPulse 			= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.RearLeftWheelPulseValidity 	= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.RearLeftWssFault 				= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.RearRightWheelDirection 		= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.RearRightWheelPulse 			= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.RearRightWheelPulseValidity 	= 0;
    ECU3.RX.CH3_RCU_WheelStatus_0x08D.RearRightWssFault 			= 0;

    ECU3.RX.CH3_RCU_Status_0x093.AbsFault   				    = 0;
    ECU3.RX.CH3_RCU_Status_0x093.AbsState   				    = 0;
    ECU3.RX.CH3_RCU_Status_0x093.Arc   					      	= 0;
    ECU3.RX.CH3_RCU_Status_0x093.BbsFault   				    = 0;
    ECU3.RX.CH3_RCU_Status_0x093.BbsState   				    = 0;
    ECU3.RX.CH3_RCU_Status_0x093.CanCommunicationFault   	    = 0;
    ECU3.RX.CH3_RCU_Status_0x093.Crc   					      	= 0;
    ECU3.RX.CH3_RCU_Status_0x093.EpbFault   				    = 0;
    ECU3.RX.CH3_RCU_Status_0x093.EpbState   				    = 0;
    ECU3.RX.CH3_RCU_Status_0x093.EpbTransition  			    = 0;
    ECU3.RX.CH3_RCU_Status_0x093.EscFault  				      	= 0;
    ECU3.RX.CH3_RCU_Status_0x093.EscState  				      	= 0;
    ECU3.RX.CH3_RCU_Status_0x093.EscYawRateThreshold  	      	= 0;
    ECU3.RX.CH3_RCU_Status_0x093.InternalCanCommunicationFault	= 0;
    ECU3.RX.CH3_RCU_Status_0x093.SplitMuDetSsmFaultection  	  	= 0;
    ECU3.RX.CH3_RCU_Status_0x093.SsmFault  					  	= 0;
    ECU3.RX.CH3_RCU_Status_0x093.SsmState  					  	= 0;

    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.Arc  						= 0;
    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.Crc  						= 0;
    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.FrontLeftTireSlipRatio  	= 0;
    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.FrontLeftWheelSlipStatus  	= 0;
    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.FrontRightTireSlipRatio  	= 0;
    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.FrontRightWheelSlipStatus	= 0;
    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.RearLeftTireSlipRatio  	= 0;
    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.RearLeftWheelSlipStatus  	= 0;
    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.RearRightTireSlipRatio  	= 0;
    ECU3.RX.CH3_RCU_TireSlipStatus_0x097.RearRightWheelSlipStatus 	= 0;

	ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.Arc 							= 0;
    ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.Crc 							= 0;
    ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.EcuRole 						= 0;
    ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.EcuStatus 					= 0;
    ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.EstimatedVehicleSpeed 		= 303;
    ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.IsControllingEcu 			= 0;
    ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.MasterCylinderPressure 		= 0;
    ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.RoadFrictionCoefficient 		= 0;
    ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.RoadFrictionCoefficientValid = 0;
    ECU3.RX.CH3_RCU_BrakeStatus1_0x09B.VehicleSpeedValidity 		= 0;

    ECU3.RX.CH3_RCU_PressureStatus_0x0A1.Arc 								= 0;
    ECU3.RX.CH3_RCU_PressureStatus_0x0A1.Crc 								= 0;
    ECU3.RX.CH3_RCU_PressureStatus_0x0A1.FrontLeftEstimatedPressure 		= 0;
    ECU3.RX.CH3_RCU_PressureStatus_0x0A1.FrontLeftEstimatedPressureValid 	= 0;
    ECU3.RX.CH3_RCU_PressureStatus_0x0A1.FrontRightEstimatedPressure 		= 0;
    ECU3.RX.CH3_RCU_PressureStatus_0x0A1.FrontRightEstimatedPressureValid 	= 0;

    ECU3.RX.CH3_RWA_Status3_0x0AA.Arc 				= 0;
    ECU3.RX.CH3_RWA_Status3_0x0AA.Crc 				= 0;
    ECU3.RX.CH3_RWA_Status3_0x0AA.PolFault 			= 1;
    ECU3.RX.CH3_RWA_Status3_0x0AA.PolLimiterFlag 	= 0;
    ECU3.RX.CH3_RWA_Status3_0x0AA.PolStatus 		= 0;
    ECU3.RX.CH3_RWA_Status3_0x0AA.PolValue 			= 0;
    ECU3.RX.CH3_RWA_Status3_0x0AA.SysBatteryVoltage = 0;
    ECU3.RX.CH3_RWA_Status3_0x0AA.SysIqCurrent 		= 0;

    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.Arc  					= 0;
    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.BrakeFluidState  		= 0;
    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.Crc  					= 0;
    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.FrontLeftBrakePadState  	= 0;
    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.FrontRightBrakePadState  = 0;
    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.MotorTemperatureWarning	= 0;
    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.Reserved3 				= 0;
    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.Reserved4 				= 0;
    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.Reserved5 				= 0;
    ECU3.RX.CH3_RCU_BrakeStatus2_0x0C9.Reserved6 				= 0;

    ECU3.RX.CH3_RCU_UdsResponse_0x799.UdsResponse = 0;



    //---------------------------------------- CH4 RX ----------------------------------------//
    ECU3.RX.CH4_RWS_VCU_stat_Signal_0x072.RWS_EcuStatus1 			= 0;
    ECU3.RX.CH4_RWS_VCU_stat_Signal_0x072.RWS_RackAngleSpeedFbk1	= 0;

    ECU3.RX.CH4_RWS_VCU_Rack_AngleFbk_0x073.RWS_RackAngleFbk1 = 0;



    //---------------------------------------- CH5 RX ----------------------------------------//
    ECU3.RX.CH5_RWS_VCU_stat_Signal_0x072.RWS_EcuStatus2 			= 0;
    ECU3.RX.CH5_RWS_VCU_stat_Signal_0x072.RWS_RackAngleSpeedFbk2	= 0;

    ECU3.RX.CH5_RWS_VCU_Rack_AngleFbk_0x073.RWS_RackAngleFbk2 = 0;



    //---------------------------------------- CH0 TX ----------------------------------------//
    ECU3.TX.CH0_VCU_RC_Signals1_0x010.VCU_MCU_EstTrq 		= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x010.VCU_RWA_Rack_Fbk 		= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x010.VCU_Brk_Pressure_Fbk	= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x010.VCU_Vx_Fbk 			= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x010.VCU_RC_counter1 		= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x010.VCU_RC_CRC1 			= 0;

    ECU3.TX.CH0_VCU_RC_Signals1_0x011.VCU_RC_BMS_SOC 		= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x011.VCU_RC_long_Ctl_mode  = 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x011.VCU_RC_Emergency_Stop = 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x011.VCU_GearSelStat 		= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x011.VCU_Drive_Mode 		= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x011.VCU_ParkBrake_Fbk 	= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x011.VCU_Acc_Fbk 	 		= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x011.VCU_Acc_Limit 	 	= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x011.CAR_ChargingStatus 	= 0;
    ECU3.TX.CH0_VCU_RC_Signals1_0x011.CAR_BMS_HVOn_STA 		= 0;

    ECU3.TX.CH0_CAR_STAT_CH0_0x012.CAR_Bms_PackVolt 	= 0;
    ECU3.TX.CH0_CAR_STAT_CH0_0x012.CAR_Bms_PackCur 		= 0;
    ECU3.TX.CH0_CAR_STAT_CH0_0x012.CAR_Battery_Voltage	= 0;
    ECU3.TX.CH0_CAR_STAT_CH0_0x012.CAR_LDC_ACTL_CUR 	= 0;
    ECU3.TX.CH0_CAR_STAT_CH0_0x012.CAR_LDC_ACTL_VOLT 	= 0;
//    ECU3.TX.CH0_CAR_STAT_CH0_0x012.CAR_ChargingStatus   = 0;
//    ECU3.TX.CH0_CAR_STAT_CH0_0x012.CAR_BMS_HVOn_STA 	= 0;
//    ECU3.TX.CH0_CAR_STAT_CH0_0x012.CAR_ARC 				= 0;

    ECU3.TX.CH0_VCU_RC_Fault_Flag_0x013.ACU_Fault_Flag			= 0;
	ECU3.TX.CH0_VCU_RC_Fault_Flag_0x013.MCU_Actuator_Fault_Flag	= 0;
	ECU3.TX.CH0_VCU_RC_Fault_Flag_0x013.IDB_ECU_Fault_Flag		= 0;
	ECU3.TX.CH0_VCU_RC_Fault_Flag_0x013.RCU_ECU_Fault_Flag		= 0;
	ECU3.TX.CH0_VCU_RC_Fault_Flag_0x013.RWA1_ECU_Fault_Flag		= 0;
	ECU3.TX.CH0_VCU_RC_Fault_Flag_0x013.RWA2_ECU_Fault_Flag		= 0;
	ECU3.TX.CH0_VCU_RC_Fault_Flag_0x013.RWA_Actuator_Fault_Flag	= 0;
	ECU3.TX.CH0_VCU_RC_Fault_Flag_0x013.ACU_ECU_Fault_Flag		= 0;

    ECU3.TX.CH0_Debug_VCU_Signal_1_CH0_0x017.VCU_IDB_BrakeTorqueCommand 	= 0;
	ECU3.TX.CH0_Debug_VCU_Signal_1_CH0_0x017.VCU_RWA1_RackAngleCommand 		= 0;
	ECU3.TX.CH0_Debug_VCU_Signal_1_CH0_0x017.VCU_RWS1_RackAngleCommand   	= 0;
	ECU3.TX.CH0_Debug_VCU_Signal_1_CH0_0x017.VCU_MCU_TorqCommand  		  	= 0;

	ECU3.TX.CH0_Debug_VCU_Signal_2_CH0_0x018.VCU_RCU_BrakeTorqueCommand 	= 0;
	ECU3.TX.CH0_Debug_VCU_Signal_2_CH0_0x018.VCU_RWA2_RackAngleCommand 		= 0;
	ECU3.TX.CH0_Debug_VCU_Signal_2_CH0_0x018.VCU_RWS2_RackAngleCommand   	= 0;

    ECU3.TX.CH0_RWA_RackAngleFbk1_0x050.RWA_RackAngleFbk1 		= 0;
    ECU3.TX.CH0_RWA_RackAngleFbk1_0x050.RWA_RackAngleSpeedFbk1 	= 0;
    ECU3.TX.CH0_RWA_RackAngleFbk1_0x050.RWA_VCU_RC_counter1 	= 0;
    ECU3.TX.CH0_RWA_RackAngleFbk1_0x050.RWA_VCU_RC_CRC1 		= 0;
    ECU3.TX.CH0_RWA_RackAngleFbk1_0x050.CAR_ARC 				= 0;
    
    ECU3.TX.CH0_RWA_VCU_RC_Signal2_0x051.RWA_RackAngleFbk2 		= 0;
    ECU3.TX.CH0_RWA_VCU_RC_Signal2_0x051.RWA_RackAngleSpeedFbk2	= 0;
    ECU3.TX.CH0_RWA_VCU_RC_Signal2_0x051.RWA_VCU_RC_counter2 	= 0;
    ECU3.TX.CH0_RWA_VCU_RC_Signal2_0x051.RWA_VCU_RC_CRC2 		= 0;

    ECU3.TX.CH0_RWS_VCU_RC_Signal1_0x060.RWS_RackAngleFbk1 		= 0;
    ECU3.TX.CH0_RWS_VCU_RC_Signal1_0x060.RWS_RackAngleSpeedFbk1 = 0;
    ECU3.TX.CH0_RWS_VCU_RC_Signal1_0x060.RWS_VCU_RC_counter1 	= 0;
    ECU3.TX.CH0_RWS_VCU_RC_Signal1_0x060.RWS_VCU_RC_CRC1 		= 0;

    ECU3.TX.CH0_RWA_VCU_RC_Signal2_0x061.RWS_RackAngleFbk2 		= 0;
    ECU3.TX.CH0_RWA_VCU_RC_Signal2_0x061.RWS_RackAngleSpeedFbk2 = 0;
    ECU3.TX.CH0_RWA_VCU_RC_Signal2_0x061.RWS_VCU_RC_counter2 	= 0;
    ECU3.TX.CH0_RWA_VCU_RC_Signal2_0x061.RWS_VCU_RC_CRC2 		= 0;

    ECU3.TX.CH0_SW_VER_0x100.YEAR 	 	= 0;
    ECU3.TX.CH0_SW_VER_0x100.Month   	= 0;
    ECU3.TX.CH0_SW_VER_0x100.Day 		= 0;
    ECU3.TX.CH0_SW_VER_0x100.Ver  	 	= 0;
    ECU3.TX.CH0_SW_VER_0x100.CAR_NUM	= 0;

    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Lamp_BRAKE_CMD 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Lamp_Hazard_CMD 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Lamp_HBEAM_CMD 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Lamp_Head_CMD 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Lamp_LTRN_CMD 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Lamp_Reverse_CMD = 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Lamp_RTRN_CMD 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Lamp_Position_CMD = 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Lamp_DRL_CMD 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Wiper_CMD 		= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.LDC_ACT_CMD 		= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.HV_ON_CMD 		= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.CE_ON_CMD 		= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.LDC_TRGT_CUR 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Vcu_OperMode 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.Vcu_SysMode 		= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.VCU_BCM_counter 	= 0;
    ECU3.TX.CH0_VCU_BCM_Signal_1_0x151.VCU_BCM_CRC 		= 0;

    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_TorqueContol = 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_Ready 		= 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_ControlMode 	= 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_PwrEnable 	= 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_GearCmd 		= 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_MtrDir 		= 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_BmsFlt 		= 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_BmsHvSt 		= 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_PosTrqLimit 	= 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_NegTrqLimit 	= 0;
    ECU3.TX.CH0_VCU_MCU_Signals1_0x250.VCU_TrqCmd 		= 0;



	//---------------------------------------- CH1 TX ----------------------------------------//
    ECU3.TX.CH1_VCU_ACU_Signal1_0x013.VCU_ACU_MCU_EstTrq  		= 0 ;
    ECU3.TX.CH1_VCU_ACU_Signal1_0x013.VCU_ACU_RWA_Rack_Fbk		= 0 ;
    ECU3.TX.CH1_VCU_ACU_Signal1_0x013.VCU_ACU_Brk_Pressure_Fbk  = 0 ;
    ECU3.TX.CH1_VCU_ACU_Signal1_0x013.VCU_ACU_long_Ctl_mode 	= 0 ;
    ECU3.TX.CH1_VCU_ACU_Signal1_0x013.VCU_ACU_GearPos 			= 0 ;
    ECU3.TX.CH1_VCU_ACU_Signal1_0x013.VCU_ACU_ParkBrake_Fbk 	= 0 ;
    ECU3.TX.CH1_VCU_ACU_Signal1_0x013.VCU_ACU_Emergency_Stop 	= 0 ;

    ECU3.TX.CH1_VCU_ACU_Signal2_0x014.RWA_Flt				= 0;
    ECU3.TX.CH1_VCU_ACU_Signal2_0x014.RWS_Flt				= 0;
    ECU3.TX.CH1_VCU_ACU_Signal2_0x014.IDB_Flt				= 0;
    ECU3.TX.CH1_VCU_ACU_Signal2_0x014.MCU_Flt				= 0;
    ECU3.TX.CH1_VCU_ACU_Signal2_0x014.Drive_Mode			= 0;
    ECU3.TX.CH1_VCU_ACU_Signal2_0x014.VCU_IGN_SIG			= 0;
    ECU3.TX.CH1_VCU_ACU_Signal2_0x014.VCU_ACU_RC_BMS_SOC	= 0;
    ECU3.TX.CH1_VCU_ACU_Signal2_0x014.VCU_ACU_counter2		= 0;
    ECU3.TX.CH1_VCU_ACU_Signal2_0x014.VCU_ACU_CRC2			= 0;

    ECU3.TX.CH1_VCU_ACU_Fault_Flag_0x017.ACU_Fault_Flag				= 0;
	ECU3.TX.CH1_VCU_ACU_Fault_Flag_0x017.MCU_Actuator_Fault_Flag	= 0;
	ECU3.TX.CH1_VCU_ACU_Fault_Flag_0x017.IDB_ECU_Fault_Flag			= 0;
	ECU3.TX.CH1_VCU_ACU_Fault_Flag_0x017.RCU_ECU_Fault_Flag			= 0;
	ECU3.TX.CH1_VCU_ACU_Fault_Flag_0x017.RWA1_ECU_Fault_Flag		= 0;
	ECU3.TX.CH1_VCU_ACU_Fault_Flag_0x017.RWA2_ECU_Fault_Flag		= 0;
	ECU3.TX.CH1_VCU_ACU_Fault_Flag_0x017.RWA_Actuator_Fault_Flag	= 0;
	ECU3.TX.CH1_VCU_ACU_Fault_Flag_0x017.ACU_ECU_Fault_Flag			= 0;

    ECU3.TX.CH1_RWA_VCU_ACU_Signal1_0x050.RWA_RackAngleFbk 		= 0;
    ECU3.TX.CH1_RWA_VCU_ACU_Signal1_0x050.RWA_RackAngleSpeedFbk	= 0;
    ECU3.TX.CH1_RWA_VCU_ACU_Signal1_0x050.RWA_VCU_ACU_counter1 	= 0;
    ECU3.TX.CH1_RWA_VCU_ACU_Signal1_0x050.RWA_VCU_ACU_CRC1 		= 0;

    ECU3.TX.CH1_RWA_VCU_ACU_Signal2_0x051.RWA_RackAngleFbk 		= 0;
    ECU3.TX.CH1_RWA_VCU_ACU_Signal2_0x051.RWA_RackAngleSpeedFbk	= 0;
    ECU3.TX.CH1_RWA_VCU_ACU_Signal2_0x051.RWA_VCU_ACU_counter2 	= 0;
    ECU3.TX.CH1_RWA_VCU_ACU_Signal2_0x051.RWA_VCU_ACU_CRC2 		= 0;

    ECU3.TX.CH1_RWS_VCU_ACU_Signal1_0x060.RWS_RackAngleFbk 		= 0;
    ECU3.TX.CH1_RWS_VCU_ACU_Signal1_0x060.RWS_RackAngleSpeedFbk	= 0;
    ECU3.TX.CH1_RWS_VCU_ACU_Signal1_0x060.RWS_VCU_ACU_counter1 	= 0;
    ECU3.TX.CH1_RWS_VCU_ACU_Signal1_0x060.RWS_VCU_ACU_CRC1 		= 0;

    ECU3.TX.CH1_RWS_VCU_ACU_Signal2_0x061.RWS_RackAngleFbk 		= 0;
    ECU3.TX.CH1_RWS_VCU_ACU_Signal2_0x061.RWS_RackAngleSpeedFbk	= 0;
    ECU3.TX.CH1_RWS_VCU_ACU_Signal2_0x061.RWS_VCU_ACU_counter2 	= 0;
    ECU3.TX.CH1_RWS_VCU_ACU_Signal2_0x061.RWS_VCU_ACU_CRC2 		= 0;

    ECU3.TX.CH1_VCU_245h_0x245.VCU_Ready		= 1;
	ECU3.TX.CH1_VCU_245h_0x245.DrivingPosition	= 0;

	ECU3.TX.CH1_ICM_303h_0x303.Speed_Combi = 0;

	ECU3.TX.CH1_CGW_372h_0x372.WelcomeSoundCmd = 0;
	ECU3.TX.CH1_CGW_372h_0x372.GoodbyeSoundCmd = 0;

	ECU3.TX.CH1_VCU_3ACh_0x3AC.Charging_Sts_IND = 0;

    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.Lamp_RTRN 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.Lamp_Reverse 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.Lamp_LTRN 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.Lamp_Head 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.Lamp_HBEAM 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.Lamp_Hazard 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.Lamp_BRAKE 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.Status_Wiper 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.BCM_CE1_STA 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.BCM_CE2_STA 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.BCM_CE3_STA 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.BCM_CE4_STA 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.BCM_CE5_STA 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.BCM_MAINSW_STA 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal1_0x570.Battery_Voltage	= 0;

    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.ChargingStatus 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.BCM_ChgeCon_DTD 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.BMS_HVOn_STA 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.IntLckSta_OBC 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.IntLckSta_BMS 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.BMS_SOC 			= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.BMS_SOH 			= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.CommSta_OBC 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.CommSta_VCU 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.CommSta_BMS 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.CommSta_LDC 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.CommSta_TMS 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.BMS_SOH_INV 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.BMS_SOC_INV 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.Bms_Soc_Wrng 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.Bms_SoH_Wrng 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.BCM_VCU_counter2 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal2_0x580.BCM_VCU_CRC2 		= 0;

    ECU3.TX.CH1_BCM_VCU_ACU_Signal5_0x585.OBC_FltSta 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal5_0x585.BMS_FltSta 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal5_0x585.LDC_FltSta 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal5_0x585.BCM_FltSta 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal5_0x585.BMS_TEMP_FAULT 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal5_0x585.LDC_TEMP_FAULT 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal5_0x585.OBC_TEMP_FAULT 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal5_0x585.BCM_VCU_counter5	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal5_0x585.BCM_VCU_CRC5 		= 0;

	ECU3.TX.CH1_CGW_588h_VC_0x588.VC_DOM = 0;

    ECU3.TX.CH1_BCM_VCU_ACU_Signal3_0x590.Bms_PackVolt 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal3_0x590.Bms_PackCur 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal3_0x590.Bms_PackPwr 		= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal3_0x590.BCM_VCU_counter3 	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal3_0x590.BCM_VCU_CRC3 		= 0;

    ECU3.TX.CH1_BCM_VCU_ACU_Signal4_0x595.LDC_ACTL_CUR	= 0;
    ECU3.TX.CH1_BCM_VCU_ACU_Signal4_0x595.LDC_INP_VOLT 	= 0;



	//---------------------------------------- CH2 TX ----------------------------------------//
    ECU3.TX.CH2_BSC_IDB_StartupCommand_0x032.Arc 			= 0;
    ECU3.TX.CH2_BSC_IDB_StartupCommand_0x032.Crc 			= 0;
    ECU3.TX.CH2_BSC_IDB_StartupCommand_0x032.WakeUpCommand	= 0;

    ECU3.TX.CH2_BSC_RWA_RackCommand_0x040.Arc 				= 0;
	ECU3.TX.CH2_BSC_RWA_RackCommand_0x040.Crc 				= 0;
	ECU3.TX.CH2_BSC_RWA_RackCommand_0x040.RackAngleCmd 		= 0;
	ECU3.TX.CH2_BSC_RWA_RackCommand_0x040.RackAngleCmdValid = 0;

    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.Arc 						= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.BrakeHoldRequest 		= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.BrakeTorqueCommand		= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.Crc 						= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.DriveTorqueCommand 		= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.DriveTorqueCommandValid	= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.EscActivation 			= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.GearPosition 			= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.ParkBrakeRequest 		= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.PowertrainMode 			= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.RbcActivation 			= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.Reserved1 				= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.Reserved2 				= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.RopActivation 			= 0;
    ECU3.TX.CH2_BSC_IDB_BrakeCommand_0x064.TcsActivation 			= 0;

    ECU3.TX.CH2_BSC_RegenCommand_0x06A.ActualMotorTorque 			= 0;
    ECU3.TX.CH2_BSC_RegenCommand_0x06A.ActualMotorTorqueValid 		= 0;
    ECU3.TX.CH2_BSC_RegenCommand_0x06A.Arc 							= 0;
    ECU3.TX.CH2_BSC_RegenCommand_0x06A.Crc 							= 0;
    ECU3.TX.CH2_BSC_RegenCommand_0x06A.MaxAvailableRegenTorque 		= 0;
    ECU3.TX.CH2_BSC_RegenCommand_0x06A.MaxAvailableRegenTorqueValid = 0;
    ECU3.TX.CH2_BSC_RegenCommand_0x06A.TractionMotorFault 			= 0;

    ECU3.TX.CH2_BSC_IMU_0x070.Arc 							= 0;
    ECU3.TX.CH2_BSC_IMU_0x070.Crc 							= 0;
    ECU3.TX.CH2_BSC_IMU_0x070.LateralAcceleration 			= 0;
    ECU3.TX.CH2_BSC_IMU_0x070.LateralAccelerationValid 		= 0;
    ECU3.TX.CH2_BSC_IMU_0x070.LongitudinalAcceleration 		= 0;
    ECU3.TX.CH2_BSC_IMU_0x070.LongitudinalAccelerationValid = 0;
    ECU3.TX.CH2_BSC_IMU_0x070.VehicleSpeed 					= 0;
    ECU3.TX.CH2_BSC_IMU_0x070.VehicleSpeedValid 			= 0;
    ECU3.TX.CH2_BSC_IMU_0x070.VehicleYawRate 				= 0;
    ECU3.TX.CH2_BSC_IMU_0x070.VehicleYawRateValid 			= 0;

    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.Arc 							= 0;
    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.Crc 							= 0;
    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.FrontLeftWheelSpeed 			= 0;
    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.FrontLeftWheelSpeedValid 	= 0;
    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.FrontRightWheelSpeed 		= 0;
    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.FrontRightWheelSpeedValid	= 0;
    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.RearLeftWheelSpeed 			= 0;
    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.RearLeftWheelSpeedValid 		= 0;
    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.RearRightWheelSpeed 			= 0;
    ECU3.TX.CH2_IDB_WheelSpeedStatus_0x088.RearRightWheelSpeedValid 	= 0;

    ECU3.TX.CH2_BSC_RWA_StartupCommand_0x310.Arc 			= 0;
    ECU3.TX.CH2_BSC_RWA_StartupCommand_0x310.Crc 			= 0;
    ECU3.TX.CH2_BSC_RWA_StartupCommand_0x310.ModeCommand 	= 0;
    ECU3.TX.CH2_BSC_RWA_StartupCommand_0x310.WakeUpCommand	= 0;

    ECU3.TX.CH2_BSC_RWA_Sister_0x350.Arc 			= 0;
    ECU3.TX.CH2_BSC_RWA_Sister_0x350.Crc 			= 0;
    ECU3.TX.CH2_BSC_RWA_Sister_0x350.EcuPowerMode	= 0;
    ECU3.TX.CH2_BSC_RWA_Sister_0x350.EcuRole 		= 0;
    ECU3.TX.CH2_BSC_RWA_Sister_0x350.EcuStatus 	 	= 0;

    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.Arc 							= 0;
    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.Crc 							= 0;
    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.EnvironmentTemperature 		= 0;
    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.EnvironmentTemperatureValid	= 0;
    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.TimestampDay 				 	= 0;
    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.TimestampHour 				 	= 0;
    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.TimestampMinute 				= 0;
    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.TimestampMonth 				= 0;
    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.TimestampSecond 				= 0;
    ECU3.TX.CH2_BSC_VehicleEnvironment_0x384.TimestampYear 				 	= 0;

    ECU3.TX.CH2_BSC_IDB_UdsRequest_0x796.UdsRequest = 0;



    //---------------------------------------- CH3 TX ----------------------------------------//
    ECU3.TX.CH3_BSC_RCU_StartupCommand_0x033.Arc 			= 0;
    ECU3.TX.CH3_BSC_RCU_StartupCommand_0x033.Crc 			= 0;
    ECU3.TX.CH3_BSC_RCU_StartupCommand_0x033.WakeUpCommand 	= 0;

    ECU3.TX.CH3_BSC_RWA_RackCommand_0x040.Arc 				= 0;
    ECU3.TX.CH3_BSC_RWA_RackCommand_0x040.Crc 				= 0;
    ECU3.TX.CH3_BSC_RWA_RackCommand_0x040.RackAngleCmd 		= 0;
    ECU3.TX.CH3_BSC_RWA_RackCommand_0x040.RackAngleCmdValid	= 0;

    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.Arc 					= 0;
    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.BrakeHoldRequest 	= 0;
    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.BrakeTorqueCommand 	= 0;
    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.Crc 					= 0;
    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.EscActivation 		= 0;
    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.GearPosition 		= 0;
    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.ParkBrakeRequest 	= 0;
    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.PowertrainMode 		= 0;
    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.Reserved1 			= 0;
    ECU3.TX.CH3_BSC_RCU_BrakeCommand_0x065.Reserved2 			= 0;

    ECU3.TX.CH3_BSC_IMU_0x071.Arc 							= 0;
    ECU3.TX.CH3_BSC_IMU_0x071.Crc 							= 0;
    ECU3.TX.CH3_BSC_IMU_0x071.LateralAcceleration 			= 0;
    ECU3.TX.CH3_BSC_IMU_0x071.LateralAccelerationValid 		= 0;
    ECU3.TX.CH3_BSC_IMU_0x071.LongitudinalAcceleration 		= 0;
    ECU3.TX.CH3_BSC_IMU_0x071.LongitudinalAccelerationValid = 0;
    ECU3.TX.CH3_BSC_IMU_0x071.VehicleSpeed 					= 0;
    ECU3.TX.CH3_BSC_IMU_0x071.VehicleSpeedValid 			= 0;
    ECU3.TX.CH3_BSC_IMU_0x071.VehicleYawRate 				= 0;
    ECU3.TX.CH3_BSC_IMU_0x071.VehicleYawRateValid 			= 0;

    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.Arc  						= 0;
    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.Crc  						= 0;
    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.FrontLeftWheelSpeed  		= 0;
    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.FrontLeftWheelSpeedValid  	= 0;
    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.FrontRightWheelSpeed  		= 0;
    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.FrontRightWheelSpeedValid	= 0;
    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.RearLeftWheelSpeed  			= 0;
    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.RearLeftWheelSpeedValid  	= 0;
    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.RearRightWheelSpeed  		= 0;
    ECU3.TX.CH3_RCU_WheelSpeedStatus_0x089.RearRightWheelSpeedValid 	= 0;

    ECU3.TX.CH3_BSC_RWA_StartupCommand_0x310.Arc 			= 0;
    ECU3.TX.CH3_BSC_RWA_StartupCommand_0x310.Crc 			= 0;
    ECU3.TX.CH3_BSC_RWA_StartupCommand_0x310.ModeCommand 	= 0;
    ECU3.TX.CH3_BSC_RWA_StartupCommand_0x310.WakeUpCommand	= 0;

    ECU3.TX.CH3_BSC_RWA_Sister_0x350.Arc 			= 0;
    ECU3.TX.CH3_BSC_RWA_Sister_0x350.Crc 			= 0;
    ECU3.TX.CH3_BSC_RWA_Sister_0x350.EcuPowerMode	= 0;
    ECU3.TX.CH3_BSC_RWA_Sister_0x350.EcuRole 		= 0;
    ECU3.TX.CH3_BSC_RWA_Sister_0x350.EcuStatus 	 	= 0;

    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.Arc 							= 0;
    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.Crc 							= 0;
    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.EnvironmentTemperature 		= 0;
    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.EnvironmentTemperatureValid	= 0;
    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.TimestampDay 					= 0;
    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.TimestampHour 					= 0;
    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.TimestampMinute 				= 0;
    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.TimestampMonth 				= 0;
    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.TimestampSecond 				= 0;
    ECU3.TX.CH3_BSC_VehicleEnvironment_0x385.TimestampYear 					= 0;

    ECU3.TX.CH3_BSC_RCU_UdsRequest_0x797.UdsRequest = 0;



    //---------------------------------------- CH4 TX ----------------------------------------//
    ECU3.TX.CH4_VCU_RWS_Rack_Cmd_0x040.Arc = 0;
    ECU3.TX.CH4_VCU_RWS_Rack_Cmd_0x040.Crc = 0;
    ECU3.TX.CH4_VCU_RWS_Rack_Cmd_0x040.RackAngleCmd1 = 0;
    ECU3.TX.CH4_VCU_RWS_Rack_Cmd_0x040.RackAngleCmdValid1 = 0;

    ECU3.TX.CH4_VCU_RWS_StartupCommand_0x310.RWS_ModeCommand1   = 0;
    ECU3.TX.CH4_VCU_RWS_StartupCommand_0x310.RWS_WakeUpCommand1 = 0;

    ECU3.TX.CH4_VCU_RWS_Sister_0x350.Arc = 0;
    ECU3.TX.CH4_VCU_RWS_Sister_0x350.Crc = 0;
    ECU3.TX.CH4_VCU_RWS_Sister_0x350.EcuPowerMode1 = 0;
    ECU3.TX.CH4_VCU_RWS_Sister_0x350.EcuStatus1 = 0;
    ECU3.TX.CH4_VCU_RWS_Sister_0x350.EcuRole1 = 0;



    //---------------------------------------- CH5 TX ----------------------------------------//
    ECU3.TX.CH5_VCU_RWS_Rack_Cmd_0x040.Arc = 0;
    ECU3.TX.CH5_VCU_RWS_Rack_Cmd_0x040.Crc = 0;
    ECU3.TX.CH5_VCU_RWS_Rack_Cmd_0x040.RackAngleCmd2 = 0;
    ECU3.TX.CH5_VCU_RWS_Rack_Cmd_0x040.RackAngleCmdValid2 = 0;

    ECU3.TX.CH5_VCU_RWS_StartupCommand_0x310.RWS_ModeCommand2   = 0;
    ECU3.TX.CH5_VCU_RWS_StartupCommand_0x310.RWS_WakeUpCommand2 = 0;
}

/* ------------------------------------------------------------------------ */

void clear_tx_buf(uint8_t ch)
{
	CAN_ch[ch].tx.id = 0;
	CAN_ch[ch].tx.len = 0;
	for(uint8_t i=0; i<MAX_CAN_BUFFER;i++) CAN_ch[ch].tx.buf[i] = 0;
}

/* ------------------------------------------------------------------------ */

void clear_tx_ring(uint8_t ch)
{
	CAN_ch[ch].tx_ring[P_RD(ch)].len = 0;
	CAN_ch[ch].tx_ring[P_RD(ch)].id = 0;
	for(uint8_t j=0;j<MAX_CAN_BUFFER;j++) CAN_ch[ch].tx_ring[P_RD(ch)].buf[j] = 0;
}

/* ------------------------------------------------------------------------ */

void can_tx_check(void)
{
	for(uint8_t i=0;i<MAX_CAN_INST;i++)
	{
		if(CAN_ch[i].tx_ring[P_RD(i)].xreq == TRUE)
		{
			can_transmit_txring(i);
		}	
	}
}

/* ------------------------------------------------------------------------ */

void can_send_txring(uint8_t ch, uint32_t id, uint8_t *buf, uint8_t len)
{
	uint8_t i;
	if(tx_info[ch].data_length>64) return;

	// if((ch == 0) && (len > 64))	return;
	// if((ch == 1) && (len > 64))	return;
	// if((ch == 2) && (len > 64))	return;
	// if((ch == 3) && (len > 8))	return;
	// if((ch == 4) && (len > 8))	return;
	// if((ch == 5) && (len > 8))	return;
	if(gb.can[ch].bus_off == APP_TRUE)	return; // 버스 OFF 될 가능성 있음

	

	for(i=0;i<len;i++) 
	{
		CAN_ch[ch].tx_ring[P_WR(ch)].buf[i] = buf[i];
	}
	clear_tx_buf(ch); // 이거 한번 없애보고 ㄱㄱ
	CAN_ch[ch].tx_ring[P_WR(ch)].id = id;
	CAN_ch[ch].tx_ring[P_WR(ch)].len = len;
	CAN_ch[ch].tx_ring[P_WR(ch)].xreq = TRUE;
	P_WR(ch) = (P_WR(ch)+1) % MAX_TX_RING;
}

/* ------------------------------------------------------------------------ */

void can_transmit_txring(uint8_t ch)
{

	uint8_t can_ret;
	
	if(CAN_ch[ch].tx_ring[P_RD(ch)].len<=8)	{
		tx_info[ch].data_length = 8;
	}
	else if(CAN_ch[ch].tx_ring[P_RD(ch)].len<=16){
		tx_info[ch].data_length = 16;
	}
	else if(CAN_ch[ch].tx_ring[P_RD(ch)].len<=24){
		tx_info[ch].data_length = 24;
	}
	else if(CAN_ch[ch].tx_ring[P_RD(ch)].len<=32){
		tx_info[ch].data_length = 32;
	}
	else if(CAN_ch[ch].tx_ring[P_RD(ch)].len<=64){
		tx_info[ch].data_length = 64;
	}
	can_ret = FlexCAN_Ip_Send(ch,CAN_ch[ch].tx_mb_idx ,&tx_info[ch],CAN_ch[ch].tx_ring[P_RD(ch)].id,CAN_ch[ch].tx_ring[P_RD(ch)].buf);
	// debug_printf("ch : %d, ret : %d, mb = %d\r\n",ch,can_ret,CAN_ch[ch].tx_mb_idx);

	switch(ch)
	{
		case 1:
			CAN_ch[ch].tx_mb_idx = ((CAN_ch[ch].tx_mb_idx+1) % MAX_TX_MB_1ch);
			break;
		default:
			CAN_ch[ch].tx_mb_idx = ((CAN_ch[ch].tx_mb_idx+1) % MAX_TX_MB);
			break;
	}

	switch (can_ret)
	{
	case FLEXCAN_STATUS_SUCCESS:
		clear_tx_ring(ch);
		CAN_ch[ch].tx_ring[P_RD(ch)].xreq = FALSE;
		P_RD(ch) = (P_RD(ch)+1) % MAX_TX_RING;
		
		break;
	case FLEXCAN_STATUS_BUSY:
		clear_tx_ring(ch);
		CAN_ch[ch].tx_ring[P_RD(ch)].xreq = FALSE;
		P_RD(ch) = (P_RD(ch)+1) % MAX_TX_RING;
		vcan_send_miss_message++;
		break;
	default:
		break;
	}

}



/* ------------------------------------------------------------------------ */

void DIN_TEST(void)
{ //DIN GPIO 3.3V
	din_test = Siul2_Dio_Ip_ReadPin(DIN_1_PORT,DIN_1_PIN);
}

void Digital_Write(uint8_t DOUT_No,uint8_t Value)
{
	if(Value > ON) Value = ON;

	switch (DOUT_No)
	{
	case DOUT_0:
		Siul2_Dio_Ip_WritePin(DOUT_0_PORT, DOUT_0_PIN, Value);
		break;		
	case DOUT_1:
		Siul2_Dio_Ip_WritePin(DOUT_1_PORT, DOUT_1_PIN, Value);
		break;
	case DOUT_2:
		Siul2_Dio_Ip_WritePin(DOUT_2_PORT, DOUT_2_PIN, Value);
		break;
	case DOUT_3:
		Siul2_Dio_Ip_WritePin(DOUT_3_PORT, DOUT_3_PIN, Value);
		break;
	case DOUT_4:
		Siul2_Dio_Ip_WritePin(DOUT_4_PORT, DOUT_4_PIN, Value);
		break;
	case DOUT_5:
		Siul2_Dio_Ip_WritePin(DOUT_5_PORT, DOUT_5_PIN, Value);
		break;
	case DOUT_6:
		Siul2_Dio_Ip_WritePin(DOUT_6_PORT, DOUT_6_PIN, Value);
		break;
	case DOUT_7:
		Siul2_Dio_Ip_WritePin(DOUT_7_PORT, DOUT_7_PIN, Value);
		break;

	default:
		break;
	}
}

uint8_t Digital_Read(uint8_t DIN_No)
{
	uint8_t ret;
	switch (DIN_No)
	{
	case DIN_0:
		ret = Siul2_Dio_Ip_ReadPin(DIN_0_PORT,DIN_0_PIN);
		break;
	case DIN_1:
		ret = Siul2_Dio_Ip_ReadPin(DIN_1_PORT,DIN_1_PIN);
		break;
	case DIN_2:
		ret = Siul2_Dio_Ip_ReadPin(DIN_2_PORT,DIN_2_PIN);
		break;
	case DIN_3:
		ret = Siul2_Dio_Ip_ReadPin(DIN_3_PORT,DIN_3_PIN);
		break;
	case DIN_4:
		ret = Siul2_Dio_Ip_ReadPin(DIN_4_PORT,DIN_4_PIN);
		break;
	case DIN_5:
		ret = Siul2_Dio_Ip_ReadPin(DIN_5_PORT,DIN_5_PIN);
		break;
	case DIN_6:
		ret = Siul2_Dio_Ip_ReadPin(DIN_6_PORT,DIN_6_PIN);
		break;
	case DIN_7:
		ret = Siul2_Dio_Ip_ReadPin(DIN_7_PORT,DIN_7_PIN);
		break;


	default:
		ret = 0xFF;
		break;
	}

	return ret;
}


/* ------------------------------------------------------------------------ */

void
led_onoff( int flag )
{
	if(flag == APP_ON)	Siul2_Dio_Ip_WritePin(TEST_LED_PORT, TEST_LED_PIN, 0U);
	else				Siul2_Dio_Ip_WritePin(TEST_LED_PORT, TEST_LED_PIN, 1U);

	gb.led_flag = flag;
}

/* ------------------------------------------------------------------------ */

void Adc_Init( void )
{
	uint8 retry;
	uint8 status;
	
	for(retry=0; retry<MAX_ADC_RETRY; retry++)
	{
		status = (StatusType) Adc_Sar_Ip_Init(ADC_INST_0, &AdcHwUnit_0_BOARD_INITPERIPHERALS);
		if(status == E_OK)	break;
	}
	if(retry >= MAX_ADC_RETRY)	debug_printf("ADC[%d] Init failed\n", ADC_INST_0);

	for(retry=0; retry<MAX_ADC_RETRY; retry++)
	{
		status = (StatusType) Adc_Sar_Ip_Init(ADC_INST_1, &AdcHwUnit_1_BOARD_INITPERIPHERALS);
		if(status == E_OK)	break;
	}
	if(retry >= MAX_ADC_RETRY)	debug_printf("ADC[%d] Init failed\n", ADC_INST_1);

	for(retry=0; retry<MAX_ADC_RETRY; retry++)
	{
		status = (StatusType) Adc_Sar_Ip_Init(ADC_INST_2, &AdcHwUnit_2_BOARD_INITPERIPHERALS);
		if(status == E_OK)	break;
	}
	if(retry >= MAX_ADC_RETRY)	debug_printf("ADC[%d] Init failed\n", ADC_INST_2);


	/* Install and enable interrupt handlers */
	IntCtrl_Ip_InstallHandler(ADC0_IRQn, Adc_Sar_0_Isr, NULL_PTR);
	IntCtrl_Ip_InstallHandler(ADC1_IRQn, Adc_Sar_1_Isr, NULL_PTR);
	IntCtrl_Ip_InstallHandler(ADC2_IRQn, Adc_Sar_2_Isr, NULL_PTR);
	IntCtrl_Ip_EnableIrq(ADC0_IRQn);
	IntCtrl_Ip_EnableIrq(ADC1_IRQn);
	IntCtrl_Ip_EnableIrq(ADC2_IRQn);

	/* Calibrate ADC */
	for(retry=0; retry<MAX_ADC_RETRY; retry++)
	{
		status = (StatusType) Adc_Sar_Ip_DoCalibration(ADC_INST_0);
		if(status == E_OK)	break;
	}
	if(retry >= MAX_ADC_RETRY)	debug_printf("ADC[%d] Calibration failed\n", ADC_INST_0);

	for(retry=0; retry<MAX_ADC_RETRY; retry++)
	{
		status = (StatusType) Adc_Sar_Ip_DoCalibration(ADC_INST_1);
		if(status == E_OK)	break;
	}
	if(retry >= MAX_ADC_RETRY)	debug_printf("ADC[%d] Calibration failed\n", ADC_INST_1);

	for(retry=0; retry<MAX_ADC_RETRY; retry++)
	{
		status = (StatusType) Adc_Sar_Ip_DoCalibration(ADC_INST_2);
		if(status == E_OK)	break;
	}
	if(retry >= MAX_ADC_RETRY)	debug_printf("ADC[%d] Calibration failed\n", ADC_INST_2);

	Adc_Sar_Ip_EnableNotifications(ADC_INST_0, ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN);
	Adc_Sar_Ip_EnableNotifications(ADC_INST_1, ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN);
	Adc_Sar_Ip_EnableNotifications(ADC_INST_2, ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN);


}









uint16_t ADC_Read(uint8_t ADC_No)
{
	uint16_t ret;

	//ADC Range 0 ~ 5V = 0 ~ 4095

	switch (ADC_No)
	{
	case ADC_0:
		ret = gb.ADC0;
		break;
	case ADC_1:
		ret = gb.ADC1;
		break;
	case ADC_2:
		ret = gb.ADC2;
		break;
	case ADC_3:
		ret = gb.ADC3;
		break;
	case ADC_4:
		ret = gb.ADC4;
		break;
	case AIN_BAT:
		ret = gb.AIN_bat;
		break;
		
	default:
		ret = 0xFF;
		break;
	}
	return ret;
}







void
Adc0EndOfChainNoti( void )
{
	gb.ADC0 = Adc_Sar_Ip_GetConvData(ADC_INST_0, ADC_AN_6); 
}

/* ------------------------------------------------------------------------ */

void
Adc1EndOfChainNoti( void )
{
	gb.ADC1 = Adc_Sar_Ip_GetConvData(ADC_INST_1, ADC_AN_2);	
	gb.AIN_bat = Adc_Sar_Ip_GetConvData(ADC_INST_1, ADC_AN_43);	
}

void
Adc2EndOfChainNoti( void )
{
	gb.ADC2 = Adc_Sar_Ip_GetConvData(ADC_INST_2, ADC_AN_3);	
	gb.ADC3 = Adc_Sar_Ip_GetConvData(ADC_INST_2, ADC_AN_4);	
	gb.ADC4 = Adc_Sar_Ip_GetConvData(ADC_INST_2, ADC_AN_5);	
}

/* ------------------------------------------------------------------------ */



/* ------------------------------------------------------------------------ */

void Adc_Read_ch(uint8_t ch)
{
	Adc_Sar_Ip_StartConversion(ch, ADC_SAR_IP_CONV_CHAIN_NORMAL);
}

/* ------------------------------------------------------------------------ */

void
tmr_delay( u32 delay )
{
	volatile u64	start, elapse;

	start = gb.tmr_cnt;
	while(1)
	{
		elapse = gb.tmr_cnt - start;
		if(elapse > delay)	break;
	}
}

/* ------------------------------------------------------------------------ */

void
Pit_Callback( void )//500us
{
	u32	i;
	static uint8_t	t=0;
	if(t==0) {
		t=1;
		gb.x500us++;
	} else {//1ms
		uds_timer_interrupt();
		t=0;
		gb.x500us++;
		gb.tmr_cnt++;
	}

	task_500us();

}


/* ------------------------------------------------------------------------ */

void
board_init( void )
{

	
	led_onoff(APP_OFF);

}

/* ------------------------------------------------------------------------ */

void Uart_Init(void)
{
	IntCtrl_Ip_EnableIrq(LPUART0_IRQn);
	IntCtrl_Ip_InstallHandler(LPUART0_IRQn, LPUART_UART_IP_0_IRQHandler, NULL_PTR);

	IntCtrl_Ip_EnableIrq(LPUART2_IRQn);
	IntCtrl_Ip_InstallHandler(LPUART2_IRQn, LPUART_UART_IP_2_IRQHandler, NULL_PTR);

	IntCtrl_Ip_EnableIrq(LPUART10_IRQn);
	IntCtrl_Ip_InstallHandler(LPUART10_IRQn, LPUART_UART_IP_10_IRQHandler, NULL_PTR);

	IntCtrl_Ip_EnableIrq(LPUART13_IRQn);
	IntCtrl_Ip_InstallHandler(LPUART13_IRQn, LPUART_UART_IP_13_IRQHandler, NULL_PTR);




	/* Initializes an UART driver*/
	Lpuart_Uart_Ip_Init(LPUART_IP_0,  &Lpuart_Uart_Ip_pHwConfigPB_0_BOARD_INITPERIPHERALS);
	Lpuart_Uart_Ip_Init(LPUART_IP_2,  &Lpuart_Uart_Ip_pHwConfigPB_2_BOARD_INITPERIPHERALS);
	Lpuart_Uart_Ip_Init(LPUART_IP_10, &Lpuart_Uart_Ip_pHwConfigPB_10_BOARD_INITPERIPHERALS);
	Lpuart_Uart_Ip_Init(LPUART_IP_13, &Lpuart_Uart_Ip_pHwConfigPB_13_BOARD_INITPERIPHERALS);



	(void)Lpuart_Uart_Ip_AsyncReceive(LPUART_IP_0,  (uint8_t *)gb.utemp, 1);
	(void)Lpuart_Uart_Ip_AsyncReceive(LPUART_IP_2,  (uint8_t *)gb.btemp, 1);
	(void)Lpuart_Uart_Ip_AsyncReceive(LPUART_IP_10, (uint8_t *)gb.uart10_temp, 1);
	(void)Lpuart_Uart_Ip_AsyncReceive(LPUART_IP_13, (uint8_t *)gb.uart13_temp, 1);


}


void
UART0_RX_Callback( uint32 instance, void *driverState, Lpuart_Uart_Ip_EventType event, void *userData )
{
	(void)userData;
	(void)driverState;

	if(event == LPUART_UART_IP_EVENT_RX_FULL)
	{
		gb.ubuf[gb.ubuf_tail] = gb.utemp[0];
		gb.ubuf_tail = (gb.ubuf_tail + 1) % MAX_COMMAND_BUF;
		Lpuart_Uart_Ip_SetRxBuffer(instance, (uint8_t *)gb.utemp, 1);
		
	}
}

/* ------------------------------------------------------------------------ */

void
UART2_RX_Callback( uint32 instance, void *driverState, Lpuart_Uart_Ip_EventType event, void *userData )
{
	(void)userData;
	(void)driverState;

	if(event == LPUART_UART_IP_EVENT_RX_FULL)
	{
		gb.bbuf[gb.bbuf_tail] = gb.btemp[0];
		gb.bbuf_tail = (gb.bbuf_tail + 1) % MAX_COMMAND_BUF;
		Lpuart_Uart_Ip_SetRxBuffer(instance, (uint8_t *)gb.btemp, 1);
	}
}


/* ------------------------------------------------------------------------ */

void
UART10_RX_Callback( uint32 instance, void *driverState, Lpuart_Uart_Ip_EventType event, void *userData )
{
	(void)userData;
	(void)driverState;

	if(event == LPUART_UART_IP_EVENT_RX_FULL)
	{
		gb.uart10_buf[gb.uart10_buf_tail] = gb.uart10_temp[0];
		gb.uart10_buf_tail = (gb.uart10_buf_tail + 1) % MAX_COMMAND_BUF;
		Lpuart_Uart_Ip_SetRxBuffer(instance, (uint8_t *)gb.uart10_temp, 1);
	}
}

/* ------------------------------------------------------------------------ */

void
UART13_RX_Callback( uint32 instance, void *driverState, Lpuart_Uart_Ip_EventType event, void *userData )
{
	(void)userData;
	(void)driverState;

	if(event == LPUART_UART_IP_EVENT_RX_FULL)
	{
		gb.uart13_buf[gb.uart13_buf_tail] = gb.uart13_temp[0];
		gb.uart13_buf_tail = (gb.uart13_buf_tail + 1) % MAX_COMMAND_BUF;
		Lpuart_Uart_Ip_SetRxBuffer(instance, (uint8_t *)gb.uart13_temp, 1);
	}
}

/* ------------------------------------------------------------------------ */

void
UART1_RX_Callback( uint32 instance, void *driverState, Lpuart_Uart_Ip_EventType event, void *userData )
{
	(void)userData;
	(void)driverState;

	if(event == LPUART_UART_IP_EVENT_RX_FULL)
	{
		gb.uart1_buf[gb.uart1_buf_tail] = gb.uart1_temp[0];
		gb.uart1_buf_tail = (gb.uart1_buf_tail + 1) % MAX_COMMAND_BUF;
		Lpuart_Uart_Ip_SetRxBuffer(instance, (uint8_t *)gb.uart1_temp, 1);
	}
}

/* ------------------------------------------------------------------------ */

void
UART9_RX_Callback( uint32 instance, void *driverState, Lpuart_Uart_Ip_EventType event, void *userData )
{
	(void)userData;
	(void)driverState;

	if(event == LPUART_UART_IP_EVENT_RX_FULL)
	{
		gb.uart9_buf[gb.uart9_buf_tail] = gb.uart9_temp[0];
		gb.uart9_buf_tail = (gb.uart9_buf_tail + 1) % MAX_COMMAND_BUF;
		Lpuart_Uart_Ip_SetRxBuffer(instance, (uint8_t *)gb.uart9_temp, 1);
	}
}



/* ------------------------------------------------------------------------ */

void
Gvar_init( void )
{
	u32	i;

	gb.ubuf_head = 0;
	gb.ubuf_tail = 0;

	for(i=0; i<MAX_CAN_INST; i++)
		gb.can[i].bus_off = APP_FALSE;

	for(i=0; i<MAX_CAN_INST; i++)	gb.can[i].bus_off_callback = NULL;


	gb.pwm_freq = PWM_FREQ;	// default 50KHz
	gb.pwm_max_tick = PWM_INIT_MAX_TICK;
}

/* ------------------------------------------------------------------------ */

void
register_bus_off_callback( int ch, user_callback fp, int param )
{
	gb.can[ch].bus_off_callback = fp;
	gb.can[ch].param = param;
}


/* ------------------------------------------------------------------------ */

int
get_char( char *ch )
{
	if(gb.ubuf_head == gb.ubuf_tail)    return(APP_FALSE);

	*ch = gb.ubuf[gb.ubuf_head];
	gb.ubuf_head = (gb.ubuf_head + 1) % MAX_COMMAND_BUF;

	return(APP_TRUE);
}

/* ------------------------------------------------------------------------ */

void
put_char( char ch )
{
	Lpuart_Uart_Ip_SyncSend(LPUART_IP_0, (uint8_t *)&ch, 1);
}

/* ------------------------------------------------------------------------ */

int
get_line( u32 max_len )
{
	if((get_char(&(gb.cmd_buf[gb.cmd_idx])))== APP_FALSE)  return(APP_FALSE);

	switch(gb.cmd_buf[gb.cmd_idx])
	{
		case '\n':
		case '\r':
			debug_printf("\r\n");
			gb.cmd_buf[gb.cmd_idx] = NULL;
			gb.cmd_idx = 0;
			return(APP_TRUE);

		case '\b':
			if(gb.cmd_idx > 0)
			{
				gb.cmd_idx--;
				debug_printf("\b \b");
			}
			break;

		default:
			if((u8)(gb.cmd_buf[gb.cmd_idx]) >= 0x20 && (u8)(gb.cmd_buf[gb.cmd_idx]) <= 0x7e)
			{
				put_char(gb.cmd_buf[gb.cmd_idx]);
				gb.cmd_buf_no[gb.cmd_idx] = gb.cmd_buf[gb.cmd_idx] - 48;
				gb.cmd_idx++;
			}
			break;
	}

	if(gb.cmd_idx >= max_len)
	{
		gb.cmd_buf[max_len-1] = NULL;
		gb.cmd_idx = 0;
		return(APP_TRUE);
	}

	return(APP_FALSE);
}

/* ------------------------------------------------------------------------ */

void UART0_get_cmd(void)
{
	int ret;

	ret = get_line(128);

	if(ret == APP_TRUE)
	{
		if(gb.cmd_buf[0] == '\0')
		{
			return;
		}
		else if (!strcmp(gb.cmd_buf,"test1"))
		{
			debug_printf("test1\r\n");
		}

#ifdef DEBUG_TEST
		else if(gb.cmd_buf[0] == '0') gb.Debug_test_No = 0;

		else if(gb.cmd_buf[0] == '1') //Digital Output
		{
			gb.Debug_test_No = 1; 
			Digital_Write(gb.cmd_buf_no[1],gb.cmd_buf_no[2]); //131 -> Digital Output, 3ch, Write 1
			debug_printf ("Ditital Output CH : %d, Value : %d\r\n\n",gb.cmd_buf_no[1],gb.cmd_buf_no[2]);
		}
		else if(gb.cmd_buf[0] == '2') //Digital Input
		{
			gb.Debug_test_No = (gb.cmd_buf_no[0] * 10) + gb.cmd_buf_no[1]; //21 -> Digital Input 1ch
			debug_printf("Digital Input CH : %d\r\n\n",gb.cmd_buf_no[1]);
		}
		else if(gb.cmd_buf[0] == '3') //Analog Input
		{
			gb.Debug_test_No = (gb.cmd_buf_no[0] * 10) + gb.cmd_buf_no[1]; //31 -> Analog Input 1ch
			debug_printf("Analog Input CH : %d\r\n\n",gb.cmd_buf_no[1]);
		}
		else if(gb.cmd_buf[0] == '4') //PWM Output
		{
			gb.Debug_test_No = 4;
			Set_PWM_Duty(gb.cmd_buf_no[1],gb.cmd_buf_no[2]*10 + gb.cmd_buf_no[3]); //4150 -> PWM Output 1ch Duty50%
			
			debug_printf("PWM Output CH : %d, Duty : %d%%\r\n\n",gb.cmd_buf_no[1],
						(gb.cmd_buf_no[2] * 10) + (gb.cmd_buf_no[3] * 1));
		}
		else if(gb.cmd_buf[0] == '5') //UART Test
		{
			gb.Debug_test_No = 5;
			Lpuart_Uart_Ip_SyncSend(LPUART_IP_10, &gb.Debug_test_No, 1);
			Lpuart_Uart_Ip_SyncSend(LPUART_IP_13, &gb.Debug_test_No, 1);

		}
		else if(gb.cmd_buf[0] == '6') //I2C Test
		{
			gb.Debug_test_No = 6;

		}

		


#endif

		else
		{
			debug_printf("Command not found : %s\r\n",gb.cmd_buf);
		}
		
	}
}

void
debug_printf( char *msg, ... )
{
	char        str[256];
	va_list     argptr;
	u8          i, len;

	va_start(argptr, msg);
	vsprintf(str, msg, argptr);
	va_end(argptr);

	len = strlen(str);
	for(i=0 ; i<len ; i++)  put_char(str[i]);
}
/** ========================================================================
 	 CAN4 & CAN5 have a TJA1153 transceiver that needs to be initialized 
	if(can->isTJA1153) {
		setupCanTJA1153(ch,stb_port,stb_pin);
	}

=========================================================================== */
void setupCanTJA1153(int instance, Siul2_Dio_Ip_GpioType * const stb_port,Siul2_Dio_Ip_PinsChannelType stb_pin)
{
	Flexcan_Ip_DataInfoType tx_info = {
			.msg_id_type = FLEXCAN_MSG_ID_STD,
			.data_length = 8u,
			.fd_enable = FALSE,
			.fd_padding = FALSE,
			.enable_brs = FALSE,
			.is_polling = FALSE,
			.is_remote = FALSE
	};
	/**
	 * The TJA1153 transceiver does not come ready to use as most CAN transceivers
	 * It enters configuration mode initially if it has not been configured before,
	 * in this initial state, it is ready for receiving additional security
	 * setups such as an ID blocklist for example.
	 *
	 * In this example, the ID being transmitted is added to the CAN0 transceiver's
	 * passlist, other configurations are left as default.
	 *
	 * Refer to the NXP's TJA1153 data sheet for further detail.
	 *
	 */
#define TJA1153_START_ID   (uint32_t)(0x555u)
#define TJA1153_CONFIG_ID  (uint32_t)(0x18DA00F1u)

	uint8 sendData[8]={0,0,0,0,0,0,0,0};


	/* Allow configuration from local host via TXD pin for CAN transceiver */
	Siul2_Dio_Ip_WritePin(stb_port, stb_pin, 0U);

	/* Auto bit rate detection initial CAN Classic frame with ID 0x555 for CAN0 */
	tx_info.is_polling = TRUE;
	tx_info.msg_id_type = FLEXCAN_MSG_ID_STD;
	tx_info.data_length=0;
	FlexCAN_Ip_SendBlocking(instance, TX_MB_IDX, &tx_info, TJA1153_START_ID, sendData, 100);

	sendData[0]= 0x10;
	sendData[1]= 0x00;
	sendData[2]= 0x50;
	sendData[3]= 0x00;
	sendData[4]= 0x07;
	sendData[5]= 0xFF;

	tx_info.msg_id_type = FLEXCAN_MSG_ID_EXT;
	tx_info.data_length = 6;
	FlexCAN_Ip_SendBlocking(instance, TX_MB_IDX, &tx_info, TJA1153_CONFIG_ID, sendData, 100);

	sendData[0]= 0x10;
	sendData[1]= 0x01;
	sendData[2]= 0x9f;
	sendData[3]= 0xff;
	sendData[4]= 0xff;
	sendData[5]= 0xff;

	tx_info.msg_id_type = FLEXCAN_MSG_ID_EXT;
	tx_info.data_length = 6;

	FlexCAN_Ip_SendBlocking(instance, TX_MB_IDX, &tx_info, TJA1153_CONFIG_ID, sendData, 100);

	sendData[0]= 0x10;
	sendData[1]= 0x02;
	sendData[2]= 0xc0;
	sendData[3]= 0x00;
	sendData[4]= 0x00;
	sendData[5]= 0x00;

	tx_info.msg_id_type = FLEXCAN_MSG_ID_EXT;
	tx_info.data_length = 6;

	FlexCAN_Ip_SendBlocking(instance, TX_MB_IDX, &tx_info, TJA1153_CONFIG_ID, sendData, 100);

	sendData[0]= 0x71;
	sendData[1]= 0x02;
	sendData[2]= 0x03;
	sendData[3]= 0x04;
	sendData[4]= 0x05;
	sendData[5]= 0x06;
	sendData[6]= 0x07;
	sendData[7]= 0x08;

	tx_info.msg_id_type = FLEXCAN_MSG_ID_EXT;
	tx_info.data_length=8;

	FlexCAN_Ip_SendBlocking(instance, TX_MB_IDX, &tx_info, TJA1153_CONFIG_ID, sendData, 100);

	// vTaskDelay(pdMS_TO_TICKS(10));
	tmr_delay(10);

	/* After the last frame, the transceiver exits configuration mode and goes to standby mode, exit
	 * to normal operation mode is done by setting the STB pin of CAN transceiver to HIGH (pin is negated) */
	Siul2_Dio_Ip_WritePin(stb_port, stb_pin, 1U);
}
