/*==================================================================================================
*   Project              : RTD AUTOSAR 4.4
*   Platform             : CORTEXM
*   Peripheral           : S32K3XX
*   Dependencies         : none
*
*   Autosar Version      : 4.4.0
*   Autosar Revision     : ASR_REL_4_4_REV_0000
*   Autosar Conf.Variant :
*   SW Version           : 1.0.0
*   Build Version        : S32K3_RTD_1_0_0_D2110_ASR_REL_4_4_REV_0000_20211007
*
*   (c) Copyright 2020 - 2021 NXP Semiconductors
*   All Rights Reserved.
*
*   NXP Confidential. This software is owned or controlled by NXP and may only be
*   used strictly in accordance with the applicable license terms. By expressly
*   accepting such terms or by downloading, installing, activating and/or otherwise
*   using the software, you are agreeing that you have read, and that you agree to
*   comply with and are bound by, such license terms. If you do not agree to be
*   bound by the applicable license terms, then you may not retain, install,
*   activate or otherwise use the software.
==================================================================================================*/

/**
*   @file main.c
*
*   @addtogroup main_module main module documentation
*   @{
*/


/* Including necessary configuration files. */
#include "Mcal.h"
#include "CAN.h"
#include "SchM_Can.h"
#include "Mcu.h"
#include "Mcl.h"
#include "Port.h"
#include "Dio.h"
#include "Uart.h"
#include "Platform.h"
#include "Lpuart_Uart_Ip_Irq.h"
#include "Flexio_Uart_Ip_Irq.h"

//extern ISR(CAN0_ORED_IRQHandler);
//extern ISR(CAN0_ORED_0_31_MB_IRQHandler);
//extern ISR(CAN0_ORED_32_63_MB_IRQHandler);
//extern ISR(CAN0_ORED_64_95_MB_IRQHandler);
//extern ISR(CAN1_ORED_IRQHandler);
//extern ISR(CAN1_ORED_0_31_MB_IRQHandler);
//extern ISR(CAN1_ORED_32_63_MB_IRQHandler);






/* User includes */

#include <string.h>


#define UART_LPUART0_RS232  0
#define UART_LPUART1_WIFI  1
#define UART_LPUART2_BT  2
#define FLEXIO_RX  3
#define FLEXIO_TX  4

//#define UART_LPUART6_RS485  3


/* Welcome messages displayed at the console */
#define WELCOME_MSG_1 "abcdefghijk?\r\n"
#define WELCOME_MSG_2 "123345678\r\n"
#define WELCOME_MSG_3 "\r\nThis example is an simple echo using LPUART\r\n\
		it will send back any character you send to it.\r\n\
		The board will greet you if you send 'Hello Board'\r\
		\nNow you can begin typing:\r\n"


/* Error message displayed at the console, in case data is received erroneously */
#define ERROR_MSG "An error occurred! The application will stop!\r\n"

/* Length of the message to be received from the console */
#define MSG_LEN  50U
#define TJA1153_START_ID   (uint32_t)(0x555u)
#define TJA1153_CONFIG_ID  (uint32_t)(0x18DA00F1u)

#include "Dma_Ip.h"
#include "Dma_Ip_Irq.h"
#include "Lpuart_Uart_Ip.h"

#define BUFFER_SIZE 500
#define DMA_SIZE 20
/*the Rx buffer need to be put in non cacheable section when cache enabled*/
uint8_t __attribute__ ((section(".non_cacheable_data"))) RX_Buffer[UART_CH_MAX_CONFIG][BUFFER_SIZE];

/*==================================================================================================
*                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/


/*==================================================================================================
*                                       LOCAL MACROS
==================================================================================================*/


/*==================================================================================================
*                                      LOCAL CONSTANTS
==================================================================================================*/


/*==================================================================================================
*                                      LOCAL VARIABLES
==================================================================================================*/


/*==================================================================================================
*                                      GLOBAL CONSTANTS
==================================================================================================*/

uint8 Can_au8Sdu8bytes[8U] = {0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08};
volatile uint8 pinValue = STD_LOW;
uint8 dummyData[64] = {1,2,3,4,5,6,7,8};

/*==================================================================================================
*                                      GLOBAL VARIABLES
==================================================================================================*/
uint8 CanIf_u8TxConfirmCnt = 0U;
boolean CanIf_bTxFlag = FALSE;
uint8 CanIf_u8RxIndicationCnt = 0U;
boolean CanIf_bRxFlag = FALSE;

#if 1
static const Flexcan_Ip_DataInfoType CAN_TJA1153_MB_Config_1 = {
		.data_length = 0u,
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.is_polling  = true
};

/* Configure TJA1153 sproofing protection, 0x10 command byte */
static const Flexcan_Ip_DataInfoType TJA1153_SpoofingProtect_Config_Form = {
		.data_length = 6u,
		.msg_id_type = FLEXCAN_MSG_ID_EXT,
		.is_polling  = true
};

/* Configure TJA1153 flooding and tamper protection, 0x40 command byte */
static const Flexcan_Ip_DataInfoType TJA1153_FloodTamperProt_Config_Form = {
		.data_length = 2u,
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.is_polling  = true
};

/* Configure bit time, secure mode timeout, blacklist, etc. 0x50 command byte */
static const Flexcan_Ip_DataInfoType TJA1153_BitTimeLength_Config_Form = {
		.data_length = 3u,
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.is_polling  = true
};

/* Configure TJA1153 command message id, 0x60 command byte */
static const Flexcan_Ip_DataInfoType TJA1153_CommandMessageID_Config_Form = {
		.data_length = 5u,
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.is_polling  = true
};

/* Configure TJA1153 leaving configuration mode message format, 0x71, 0x72, 0x74 command byte */
static const Flexcan_Ip_DataInfoType TJA1153_LeaveConfigMode_Config_Form = {
		.data_length = 8u,
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.is_polling  = true
};

/* Configure TJA1153 verification of configure message, 0xF0 command byte */
static const Flexcan_Ip_DataInfoType TJA1153_ConfigVerify_Config_Form = {
		.data_length = 3u,
		.msg_id_type = FLEXCAN_MSG_ID_STD,
		.is_polling  = true
};
#endif
/*==================================================================================================
*                                   LOCAL FUNCTION PROTOTYPES
==================================================================================================*/
void TestDelay(uint32 delay);

/*==================================================================================================
*                                       LOCAL FUNCTIONS
==================================================================================================*/


/*==================================================================================================
*                                       GLOBAL FUNCTIONS
==================================================================================================*/
#if 1
typedef enum
{
    CAN_STANDARD_ID_TYPE            =  0x00, /**< * -00b CAN message with Standard CAN ID  */
	CANFD_STANDARD_ID_TYPE  		=  0x01, /**< * -01b CAN FD frame with Standard CAN ID  */
	CAN_EXTENDED_ID_TYPE            =  0x02, /**< * -10b CAN message with Extended CAN ID  */
	CANFD_EXTENDED_ID_TYPE       	=  0x03, /**< * -11b CAN FD frame with Extended CAN ID  */
} CAN_IdFrameType;

typedef struct
{
    Can_IdType id;

    CAN_IdFrameType idFrame;

    uint8 length; /**< @brief DLC = Data Length Code (part of L-PDU that describes
                                            the SDU length). */
    uint8 * sdu; /**< @brief CAN L-SDU = Link Layer Service Data
                                                          Unit. Data that is transported inside
                                                          the L-PDU. */
} Can_MsgType;


Can_MsgType canRxMsg_Buff[100];

Can_PduType Can_CreatePduInfo(Can_IdType id,CAN_IdFrameType idFrame, PduIdType swPduHandle, uint8 length, uint8* sdu)
{
    Can_PduType PduInfo;
    switch(idFrame)
    {
    case CAN_STANDARD_ID_TYPE:
    	break;
    case CANFD_STANDARD_ID_TYPE:
    	id = id | 0x40000000;
    	break;
    case CAN_EXTENDED_ID_TYPE:
    	id = id | 0x80000000;
    	break;
    case CANFD_EXTENDED_ID_TYPE:
    	id = id | 0xC0000000;
    	break;
    default:
    	break;

    }
    PduInfo.id = id;
    PduInfo.swPduHandle = swPduHandle;
    PduInfo.length = length;
    PduInfo.sdu = sdu;

    return PduInfo;
}

Can_MsgType Can_GetMsgInfo(Can_IdType id, uint8 length, uint8* sdu)
{
	Can_MsgType CanMsgInfo;

	CanMsgInfo.id = id&0x7FFFFFFF;
	CanMsgInfo.idFrame = (CAN_IdFrameType)((id>>30) &0x03);
	CanMsgInfo.length = length;
	CanMsgInfo.sdu = sdu;

    return CanMsgInfo;
}

void CanIf_ControllerBusOff(uint8 ControllerId)
{
    (void)ControllerId;
}

void CanIf_ControllerModeIndication(uint8 ControllerId, Can_ControllerStateType ControllerMode )
{
    (void)ControllerId;
    (void)ControllerMode;
}
void CanIf_TxConfirmation(PduIdType CanTxPduId)
{
    CanIf_u8TxConfirmCnt++;
    CanIf_bTxFlag = TRUE;
    (void)CanTxPduId;
}

void CanIf_RxIndication(const Can_HwType* Mailbox, const PduInfoType* PduInfoPtr )
{

    CanIf_bRxFlag = TRUE;
    (void)Mailbox;
    (void)PduInfoPtr;
    canRxMsg_Buff[CanIf_u8RxIndicationCnt] = Can_GetMsgInfo(Mailbox->CanId,PduInfoPtr->SduLength,PduInfoPtr->SduDataPtr);
    CanIf_u8RxIndicationCnt++;
}

void CanIf_CurrentIcomConfiguration( uint8 ControllerId, IcomConfigIdType  ConfigurationId, IcomSwitch_ErrorType Error)
{
	(void)ControllerId;
	(void)ConfigurationId;
	(void)Error;
}

void Can_DummyDelay(uint32 loops)
{
    VAR( volatile uint32, CAN_VAR) data = 0xAA55AA55;
    VAR( volatile uint32, CAN_VAR) contor1 = 0;
    VAR( volatile uint32, CAN_VAR) contor2 = loops;

    do
    {
        for (contor1 = 0; contor1 < 0x2FF; contor1++)
        {
            data ^= (1 << contor1) | (0xAAAAAA | contor2);
        }
        contor2--;
    } while( contor2 > 0);
}




#endif


void TestDelay(uint32 delay)
{
    static volatile uint32 DelayTimer = 0;
    while(DelayTimer<delay)
    {
        DelayTimer++;
    }
    DelayTimer=0;
}

//boolean User_Str_Cmp(const uint8 * pBuffer1, const uint8 * pBuffer2, const uint32 length)
//{
//    uint32 idx = 0;
//    for (idx = 0; idx < length; idx++)
//    {
//        if(pBuffer1[idx] != pBuffer2[idx])
//        {
//            return FALSE;
//        }
//    }
//    return TRUE;
//}




Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8* pBuffer,  uint32 sendLength, uint8* RxBuffer, uint32 T_timeout)
{
    volatile Std_ReturnType R_Uart_Status;
    volatile Std_ReturnType T_Uart_Status;
    volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
    volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
    uint32 T_bytesRemaining;
    uint32 timeout = T_timeout;
    uint32 retVal = E_NOT_OK;
//    uint8 Rx_Buffer[MSG_LEN];


    /* Uart_AsyncReceive transmit data */
//    IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(0);

   	Uart_SetBuffer(recvChannel,&RX_Buffer[recvChannel][0],DMA_SIZE,UART_RECEIVE);
   	R_Uart_Status = Uart_AsyncReceive(recvChannel, RxBuffer, DMA_SIZE);
   	if (E_OK != T_Uart_Status)
   	{
   		Uart_Abort(recvChannel,UART_RECEIVE);
   		return E_NOT_OK;
   	}


    /* Uart_AsyncSend transmit data */
    Uart_SetBuffer(transChannel,pBuffer,sendLength,UART_SEND);
    T_Uart_Status = Uart_AsyncSend(transChannel, pBuffer, sendLength);
    if (E_OK != T_Uart_Status)
    {
    	Uart_Abort(transChannel,UART_SEND);
        return E_NOT_OK;
    }


    /* Check for no on-going transmission */
    do
    {
        Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
        Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &T_bytesRemaining, UART_RECEIVE);
    } while ((UART_STATUS_NO_ERROR != Uart_TransmitStatus && UART_STATUS_NO_ERROR != Uart_ReceiveStatus && 0 < --timeout));

    if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
	{
    	Uart_Abort(transChannel,UART_SEND);
//    	IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
    	retVal = E_NOT_OK;
	}
    else
    {
    	retVal = E_OK;
    }

    if((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
    {
    	Uart_Abort(recvChannel,UART_RECEIVE);
//    	IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
    	retVal = E_NOT_OK;
    }
    else
    {
    	retVal = E_OK;
    }
    return retVal;
}

Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8* pBuffer,  uint32 sendLength, uint32 T_timeout)
{

    volatile Std_ReturnType T_Uart_Status;
    volatile Uart_StatusType Uart_TransmitStatus = UART_STATUS_TIMEOUT;
    uint32 T_bytesRemaining;
    uint32 timeout = T_timeout;
    uint32 retVal = E_NOT_OK;
//    uint8 Rx_Buffer[MSG_LEN];


    /* Uart_AsyncSend transmit data */
    Uart_SetBuffer(transChannel,pBuffer,sendLength,UART_SEND);
    T_Uart_Status = Uart_AsyncSend(transChannel, pBuffer, sendLength);
    if (E_OK != T_Uart_Status)
    {
    	Uart_Abort(transChannel,UART_SEND);
        return E_NOT_OK;
    }

    /* Check for no on-going transmission */
    do
    {
        Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
    } while ((UART_STATUS_NO_ERROR != Uart_TransmitStatus && 0 < --timeout));

    if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
	{
    	Uart_Abort(transChannel,UART_SEND);
    	retVal = E_NOT_OK;
	}
    else
    {
    	retVal = E_OK;
    }
    return retVal;
}

uint32 UART_Receive_Data(uint8 recvChannel, uint8* RxBuffer, uint32 T_timeout)
{
    volatile Std_ReturnType R_Uart_Status;
    volatile Uart_StatusType Uart_ReceiveStatus = UART_STATUS_TIMEOUT;
    uint32 T_bytesRemaining;
    uint32 timeout = T_timeout;
    uint32 retVal = E_NOT_OK;
//    uint8 Rx_Buffer[MSG_LEN];


    /* Uart_AsyncReceive transmit data */
   	Uart_SetBuffer(recvChannel,&RX_Buffer[recvChannel][0],DMA_SIZE,UART_RECEIVE);
   	R_Uart_Status = Uart_AsyncReceive(recvChannel, RxBuffer, DMA_SIZE);
   	if (E_OK != R_Uart_Status)
   	{
   		Uart_Abort(recvChannel,UART_RECEIVE);
   		return E_NOT_OK;
   	}

    /* Check for no on-going transmission */
    do
    {
        Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &T_bytesRemaining, UART_RECEIVE);
    } while ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus && 0 < --timeout));


    if((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
    {
    	Uart_Abort(recvChannel,UART_RECEIVE);
    	retVal = E_NOT_OK;
    }
    else
    {
    	retVal = E_OK;
    }
    return retVal;
}



uint32_t bufferIdx;
/* User includes */


void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event, void *userData)
{

#if 1
    /* Unused parameters */
//    (void)driverState;
    (void)userData;
    uint32_t temp;


    /* Check the event type */
    if (event == LPUART_UART_IP_EVENT_RX_FULL)
    {
        /* The reception stops when receiving idle is detected or the buffer is full */
        if (bufferIdx <= (BUFFER_SIZE - DMA_SIZE))
        {
            /* Update the buffer index and the rx buffer */
        	bufferIdx += DMA_SIZE;
        	Uart_SetBuffer(hwInstance,&RX_Buffer[hwInstance][bufferIdx],DMA_SIZE,UART_RECEIVE);
            //Lpuart_Uart_Ip_SetRxBuffer(hwInstance, &RX_Buffer[bufferIdx], DMA_SIZE);
        }
    }
    if (event == LPUART_UART_IP_EVENT_ERROR)
    {
    	/*Get the transfered data size. DMA Channel 1 is used for LPUART DMA receiving, please modify accordingly.*/
    	temp = DMA_SIZE - (uint32_t)IP_DMA->TCD->CITER.ELINKNO;
    	/*Add the remaining data size to the sum of the received size*/
    	bufferIdx += temp;
        /*Abort the receiving after detecting IDLE receiving*/
    	Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
    }
#endif
}
/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
    /* Write your code here */
	volatile Std_ReturnType T_Uart_Status1;
	volatile Std_ReturnType T_Uart_Status2;
	volatile Std_ReturnType T_Uart_Status3;
	volatile Std_ReturnType R_Uart_Status1;
	volatile Std_ReturnType R_Uart_Status2;
	static Can_PduType Can_PduInfo;
	static Can_PduType Can_PduInfo1;
	volatile Std_ReturnType CAN_Write_Status;
	uint8 rxBuffer[100];

	uint8 u8TimeOut = 100U;
	CanIf_bTxFlag = FALSE;
	CanIf_bRxFlag = FALSE;



    /* Initialize the Mcu driver */
#if (MCU_PRECOMPILE_SUPPORT == STD_ON)
    Mcu_Init(NULL_PTR);
#elif (MCU_PRECOMPILE_SUPPORT == STD_OFF)
    Mcu_Init(&Mcu_Config_VS_0);
#endif /* (MCU_PRECOMPILE_SUPPORT == STD_ON) */

	Mcu_InitClock(McuClockSettingConfig_0);

	/* Wait until PLL is locked */
	//while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
	{
		/* Busy wait until the System PLL is locked */
	}
	//Mcu_DistributePllClock();
	/* Initialize Mcl module */
	Mcl_Init(NULL_PTR);

	Mcu_SetMode(McuModeSettingConf_0);
	OsIf_Init(NULL_PTR);
	Platform_Init(NULL_PTR);
    Platform_InstallIrqHandler(LPUART0_RxTx_IRQn, LPUART_UART_IP_0_IRQHandler, NULL_PTR);
    Platform_InstallIrqHandler(LPUART1_RxTx_IRQn, LPUART_UART_IP_1_IRQHandler, NULL_PTR);
    Platform_InstallIrqHandler(LPUART2_RxTx_IRQn, LPUART_UART_IP_2_IRQHandler, NULL_PTR);
    Platform_InstallIrqHandler(FLEXIO_IRQn, MCL_FLEXIO_ISR, NULL_PTR);
    Platform_InstallIrqHandler(DMA0_IRQn,Dma0_Ch0_IRQHandler,NULL_PTR);
    Platform_InstallIrqHandler(DMA1_IRQn,Dma0_Ch1_IRQHandler,NULL_PTR);
    Platform_InstallIrqHandler(DMA2_IRQn,Dma0_Ch2_IRQHandler,NULL_PTR);
    Platform_InstallIrqHandler(DMA3_IRQn,Dma0_Ch3_IRQHandler,NULL_PTR);
    Platform_InstallIrqHandler(DMA4_IRQn,Dma0_Ch4_IRQHandler,NULL_PTR);
    Platform_InstallIrqHandler(DMA5_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);

//    Platform_InstallIrqHandler(CAN0_ORed_IRQn,IRQHandler,NULL_PTR);
//    Platform_InstallIrqHandler(CAN0_Error_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
//    Platform_InstallIrqHandler(CAN0_Wake_Up_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
//    Platform_InstallIrqHandler(CAN0_ORed_0_15_MB_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);
//    Platform_InstallIrqHandler(CAN0_ORed_16_31_MB_IRQn,Dma0_Ch5_IRQHandler,NULL_PTR);

	/* Initialize all pins*/
#if(PORT_PRECOMPILE_SUPPORT == STD_ON)
	Port_Init(NULL_PTR);
#elif(PORT_PRECOMPILE_SUPPORT == STD_OFF)
	Port_Init(&Port_Config_VS_0);
#endif

	/* Initializes an UART driver*/
#if (UART_PRECOMPILE_SUPPORT == STD_ON)
	Uart_Init(NULL_PTR);
#elif(UART_PRECOMPILE_SUPPORT == STD_OFF)
	Uart_Init(&Uart_xConfig_VS_0);
#endif



#if 1	/* Initialize Platform driver */


#if (CAN_PRECOMPILE_SUPPORT == STD_ON)
	Can_Init(NULL_PTR);
#elif(CAN_PRECOMPILE_SUPPORT == STD_OFF)
	Can_Init(&Can_Config_VS_0);
#endif


#endif
#if 0
	Platform_InstallIrqHandler(FlexCAN0_0_IRQn, CAN0_ORED_IRQHandler, NULL);
	Platform_SetIrq(FlexCAN0_0_IRQn, TRUE);
	Platform_InstallIrqHandler(FlexCAN0_1_IRQn, CAN0_ORED_0_15_MB_IRQHandler, NULL);
	Platform_SetIrq(FlexCAN0_1_IRQn, TRUE);
	Platform_InstallIrqHandler(FlexCAN0_2_IRQn, CAN0_ORED_16_31_MB_IRQHandler, NULL);
	Platform_SetIrq(FlexCAN0_2_IRQn, TRUE);


//	Platform_InstallIrqHandler(FlexCAN1_0_IRQn, CAN1_ORED_IRQHandler, NULL);
//	Platform_SetIrq(FlexCAN1_0_IRQn, TRUE);
//	Platform_InstallIrqHandler(FlexCAN0_1_IRQn, CAN1_ORED_0_31_MB_IRQHandler, NULL);
//	Platform_SetIrq(FlexCAN1_1_IRQn, TRUE);
//	Platform_InstallIrqHandler(FlexCAN1_2_IRQn, CAN1_ORED_32_63_MB_IRQHandler, NULL);
//	Platform_SetIrq(FlexCAN1_2_IRQn, TRUE);
#endif


	//Dio_WriteChannel(DioConf_DioChannel_LED, STD_HIGH);

	//Dio_WriteChannel(DioConf_DioChannel_DIO_TEST, value);
	/* Send greeting string 1 from Flexio_0_Tx */
	//T_Uart_Status1 = Send_Data(UART_LPUART0_INTERNAL_CHANNEL, (const uint8 *)WELCOME_MSG_1, strlen(WELCOME_MSG_1));

	/* Send greeting string 2 from Flexio_0_Tx */
	//T_Uart_Status2 = Send_Data(UART_LPUART0_INTERNAL_CHANNEL, (const uint8 *)WELCOME_MSG_2, strlen(WELCOME_MSG_2));

	/* Can_CreatePduInfo(id, swPduHandle,length, sdu) */
	Can_PduInfo = Can_CreatePduInfo(0x55U, CAN_EXTENDED_ID_TYPE, 0U, 8U, Can_au8Sdu8bytes);
//	Can_PduInfo1 = Can_CreatePduInfo(0x66U, 0U, 2U, Can_au8Sdu8bytes);
	  /* Initilize Can driver */

	//Can_Init(&Can_Config_VS_0);
	Can_SetControllerMode(CanController_0, CAN_CS_STARTED);
//	Can_SetControllerMode(CanController_1, CAN_CS_STARTED);
//	Dio_WriteChannel(DioConf_DioChannel_PTE4_GPIO_OUT_MCU_4G_POW_EN,STD_ON);  //使能power
//	Dio_WriteChannel(DioConf_DioChannel_PTB20_GPIO_OUT_MCU_4G_PWRKEY,STD_ON); //正向脉冲使其开机
	//TestDelay(5000000);
	//Dio_WriteChannel(DioConf_DioChannel_PTB20_GPIO_OUT_MCU_4G_PWRKEY,STD_OFF);

//	Dio_WriteChannel(DioConf_DioChannel_PTB19_GPIO_OUT_MCU_4G_DTR,STD_ON); //DTR 拉低
//	TestDelay(80000000);
	//Dio_WriteChannel(DioConf_DioChannel_PTB19_GPIO_OUT_MCU_4G_DTR,STD_OFF); //DTR 拉低

	//Dio_WriteChannel(DioConf_DioChannel_PTB19_GPIO_OUT_MCU_4G_DTR,STD_ON);
	//Dio_WriteChannel(DioConf_DioChannel_PTB18_GPIO_OUT_MCU_4G_RESET,STD_ON);
	//TestDelay(100000);
	//Dio_WriteChannel(DioConf_DioChannel_PTB18_GPIO_OUT_MCU_4G_RESET,STD_OFF);
	//DioConf_DioChannel_PTB18_GPIO_OUT_MCU_4G_RESET
	//My_Tja1153_Init();
	while (1)
	  {
		//Can_MainFunction_Write();
		//Can_MainFunction_Read();
		 /* Toggle the LED when the Gpt notification is called */

		  pinValue = ~pinValue;
//		  Dio_WriteChannel(DioConf_DioChannel_PTA29_GPIO_OUT_MCU_LED3,pinValue);
//		  Dio_WriteChannel(DioConf_DioChannel_DioChannel_LED0,pinValue);
//		  Dio_WriteChannel(DioConf_DioChannel_DioChannel_LED1,pinValue);

		  CAN_Write_Status = Can_Write(Can0HardwareObject_TX, &Can_PduInfo);
//		  if(CAN_Write_Status == E_OK)
//		  {
//			  while((!CanIf_bTxFlag) && (u8TimeOut != 0U))
//			  {
					Can_MainFunction_Write();
//					Can_DummyDelay(100U);
//					u8TimeOut--;
//			  }
//		  }
//		  u8TimeOut = 100U;
//		  CanIf_bTxFlag = false;
					TestDelay(100000);
//		  while((!CanIf_bRxFlag) && (u8TimeOut != 0U))
//		  {
			  Can_MainFunction_Read();
//			  Can_DummyDelay(100U);
//			  u8TimeOut--;
//		  }
//		  u8TimeOut = 100U;
		  CanIf_bRxFlag = false;



		  TestDelay(100000);

//		  memset(RX_Buffer[UART_LPUART0_RS232],0,BUFFER_SIZE);
//		  bufferIdx = 0;
//		  /* Send greeting string 2 from Flexio_0_Tx */
//		  T_Uart_Status1 = UART_Query_Data(UART_LPUART0_RS232,UART_LPUART0_RS232, (const uint8 *)WELCOME_MSG_1,  strlen(WELCOME_MSG_1), RX_Buffer[UART_LPUART0_RS232], 100000);
//		  TestDelay(1000);
//
//		  memset(RX_Buffer[UART_LPUART0_RS232],0,BUFFER_SIZE);
//		  bufferIdx = 0;
//		  T_Uart_Status2 = UART_Query_Data(UART_LPUART0_RS232,UART_LPUART0_RS232, (const uint8 *)WELCOME_MSG_2,  strlen(WELCOME_MSG_2), RX_Buffer[UART_LPUART0_RS232], 100000);
//		  //TestDelay(1000);
////		  memset(rxBuffer,0,100);
////		  R_Uart_Status2 = Rece_Data(UART_LPUART0_RS232, rxBuffer, strlen(WELCOME_MSG_2),0xFFFF);
//		  //TestDelay(2000000);
//		  memset(RX_Buffer[UART_LPUART0_RS232],0,BUFFER_SIZE);
//		  bufferIdx = 0;
//		  T_Uart_Status3 = UART_Query_Data(UART_LPUART0_RS232,UART_LPUART0_RS232, (const uint8 *)WELCOME_MSG_3,  strlen(WELCOME_MSG_3), RX_Buffer[UART_LPUART0_RS232], 100000);

	 }


}

/** @} */
