refactor: Update MCAL and ECU layers for UART and synchronize RTE layer
- Fixed the MCAL and ECU layers to handle multiple UART configurations. - Updated the RTE layer to align with changes in UART layers for improved compatibility and functionality.stable
parent
c28008621c
commit
a6d7b58f3d
|
|
@ -74,7 +74,8 @@ typedef enum
|
|||
{
|
||||
mcalUART_PORT1 = 0,
|
||||
mcalUART_PORT2,
|
||||
mcalUART_PORT3
|
||||
mcalUART_PORT3,
|
||||
mcalUART_PORT_MAX
|
||||
}McalUartPortNumber_e;
|
||||
#define IVEC_MCAL_GNSS_UART mcalUART_PORT3
|
||||
typedef enum
|
||||
|
|
@ -90,7 +91,7 @@ typedef struct
|
|||
McalUartConfig_s xUartConfig;
|
||||
char* buffer;
|
||||
uint16_t u16len;
|
||||
void (*pvUartRecvCallback)(IVEC_McalUartEvents_e , char *,uint32_t);
|
||||
void (*pvUartRecvCallback)(McalUartPortNumber_e, IVEC_McalUartEvents_e , char *,uint32_t);
|
||||
}McalUartHandle_s;
|
||||
|
||||
#define IVEC_MCAL_UART_MAX_PORT 3
|
||||
|
|
|
|||
|
|
@ -8,41 +8,41 @@
|
|||
|
||||
McalUartHandle_s* g_pxUartHandles[IVEC_MCAL_UART_MAX_PORT] = { 0 };
|
||||
static uint32_t __gprv_u32DataCount = 0;
|
||||
static volatile uint8_t u8rxbuffer1=0;
|
||||
static volatile uint8_t u8rxbuffer1 = 0;
|
||||
static McalUartPortNumber_e GetUartPort(UART_Regs* pxUartInstance);
|
||||
|
||||
|
||||
void UART_ReadCallback(UART_Regs *uart, uint8_t *buf, bool status)
|
||||
void UART_ReadCallback(UART_Regs* uart, uint8_t* buf, bool status)
|
||||
{
|
||||
if(status == true)
|
||||
if (status == true)
|
||||
{
|
||||
__gprv_u32DataCount += 1;
|
||||
|
||||
IVEC_MCAL_LOG(LOG_STRING, "Uart Recv Callback:%d", ind_type);
|
||||
for (int i = 0;i < IVEC_MCAL_UART_MAX_PORT; i++)
|
||||
{
|
||||
if (g_pxUartHandles[i] != NULL )
|
||||
if (g_pxUartHandles[i] != NULL)
|
||||
{
|
||||
if (g_pxUartHandles[i]->pvUartRecvCallback != NULL)
|
||||
g_pxUartHandles[i]->pvUartRecvCallback(IVEC_MCAL_UART_EVENT_RX_ARRIVED, (char *)buf, 1);
|
||||
g_pxUartHandles[i]->pvUartRecvCallback(GetUartPort(uart), IVEC_MCAL_UART_EVENT_RX_ARRIVED, (char*)buf, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _prv_vrxcallback(UART_Regs *pxUartInstance, uint32_t event)
|
||||
void _prv_vrxcallback(UART_Regs* pxUartInstance, uint32_t event)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case DL_UART_MAIN_IIDX_RX:
|
||||
{
|
||||
uint8_t l_pu8Buffer[64] = {0}; // Adjust size as needed
|
||||
uint8_t l_pu8Buffer[64] = { 0 }; // Adjust size as needed
|
||||
uint32_t bytesRead;
|
||||
|
||||
// Drain the RX FIFO and store the data in buffer
|
||||
bytesRead = DL_UART_drainRXFIFO(pxUartInstance, l_pu8Buffer, sizeof(l_pu8Buffer));
|
||||
DL_UART_clearInterruptStatus(pxUartInstance, DL_UART_MAIN_IIDX_RX);
|
||||
for( int ijk = 0; ijk < bytesRead; ijk++ )
|
||||
for (int ijk = 0; ijk < bytesRead; ijk++)
|
||||
UART_ReadCallback(pxUartInstance, &l_pu8Buffer[ijk], true);
|
||||
break;
|
||||
}
|
||||
|
|
@ -107,7 +107,20 @@ static UART_Regs* GetUartInstance(McalUartPortNumber_e eUartPortNumber)
|
|||
return NULL; // Invalid UART port
|
||||
}
|
||||
}
|
||||
|
||||
static McalUartPortNumber_e GetUartPort(UART_Regs* pxUartInstance)
|
||||
{
|
||||
switch ((uint32_t)pxUartInstance)
|
||||
{
|
||||
case (uint32_t)UART0:
|
||||
return mcalUART_PORT1;
|
||||
case (uint32_t)UART1:
|
||||
return mcalUART_PORT2;
|
||||
case (uint32_t)UART2:
|
||||
return mcalUART_PORT3;
|
||||
default:
|
||||
return mcalUART_PORT_MAX; // Invalid UART port
|
||||
}
|
||||
}
|
||||
|
||||
static xCoreStatus_t uart_deinit(McalUartHandle_s* pxUartHandle)
|
||||
{
|
||||
|
|
@ -211,7 +224,7 @@ static xCoreStatus_t uart_read(McalUartHandle_s* pxUartHandle, unsigned char* pu
|
|||
|
||||
//*pucData = DL_UART_receiveData(uart_inst);
|
||||
|
||||
if(status == false)
|
||||
if (status == false)
|
||||
{
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
|
@ -250,22 +263,22 @@ exit:
|
|||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
static xCoreStatus_t uart_transmit(McalUartHandle_s* pxUartHandle, uint8_t *u8txdata, uint32_t u32size)
|
||||
static xCoreStatus_t uart_transmit(McalUartHandle_s* pxUartHandle, uint8_t* u8txdata, uint32_t u32size)
|
||||
{
|
||||
// Get the UART instance based on the port number in the handle
|
||||
UART_Regs* uart_inst = GetUartInstance(pxUartHandle->eUartPortNumber);
|
||||
|
||||
// Check if the UART instance is valid
|
||||
if (uart_inst == NULL || u32size==0)
|
||||
if (uart_inst == NULL || u32size == 0)
|
||||
{
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
uint32_t l_u32Tick = i32MCAL_getTicks();
|
||||
for(int j=0; j<u32size; j++)
|
||||
for (int j = 0; j < u32size; j++)
|
||||
{
|
||||
DL_UART_transmitData(uart_inst,u8txdata[j]);
|
||||
while(DL_UART_isTXFIFOFull(uart_inst) && ((i32MCAL_getTicks() - l_u32Tick) < 100));
|
||||
DL_UART_transmitData(uart_inst, u8txdata[j]);
|
||||
while (DL_UART_isTXFIFOFull(uart_inst) && ((i32MCAL_getTicks() - l_u32Tick) < 100));
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
|
@ -306,21 +319,24 @@ exit:
|
|||
static xCoreStatus_t uart_init(McalUartHandle_s* pxUartHandle, McalUartBaudRate_e xBaud)
|
||||
{
|
||||
|
||||
#if UART_PIN_SELECTION == 1
|
||||
if (pxUartHandle->eUartPortNumber== mcalUART_PORT2)
|
||||
{
|
||||
DL_UART_Main_reset(UART1);
|
||||
DL_UART_Main_enablePower(UART1);
|
||||
DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM19, IOMUX_PINCM19_PF_UART1_TX);
|
||||
DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM20, IOMUX_PINCM20_PF_UART1_RX);
|
||||
}
|
||||
|
||||
else if (pxUartHandle->eUartPortNumber== mcalUART_PORT3)
|
||||
{
|
||||
DL_UART_Main_reset(UART2);
|
||||
DL_UART_Main_enablePower(UART2);
|
||||
DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM32, IOMUX_PINCM32_PF_UART2_TX);
|
||||
DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM33, IOMUX_PINCM33_PF_UART2_RX);
|
||||
|
||||
#elif UART_PIN_SELECTION == 2
|
||||
DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM19, IOMUX_PINCM19_PF_UART1_TX);
|
||||
DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM20, IOMUX_PINCM20_PF_UART1_RX);
|
||||
|
||||
#elif UART_PIN_SELECTION == 3
|
||||
DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM19, IOMUX_PINCM19_PF_UART1_TX);
|
||||
DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM20, IOMUX_PINCM20_PF_UART1_RX);
|
||||
// DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM32, IOMUX_PINCM32_PF_UART2_TX);
|
||||
// DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM33, IOMUX_PINCM33_PF_UART2_RX);
|
||||
}
|
||||
|
||||
#endif
|
||||
// Get the UART instance based on the port number in the handle
|
||||
UART_Regs* uart_inst = GetUartInstance(pxUartHandle->eUartPortNumber);
|
||||
|
||||
|
|
@ -336,37 +352,37 @@ static xCoreStatus_t uart_init(McalUartHandle_s* pxUartHandle, McalUartBaudRate_
|
|||
|
||||
//xprvUartConfig.wordLength = pxUartHandle->xUartConfig.eUartDataBit;
|
||||
uint8_t datalength = pxUartHandle->xUartConfig.eUartDataBit;
|
||||
if(datalength == mcalUART_DATABIT_7)
|
||||
if (datalength == mcalUART_DATABIT_7)
|
||||
{
|
||||
xprvUartConfig.wordLength = DL_UART_WORD_LENGTH_7_BITS;
|
||||
}
|
||||
else if(datalength == mcalUART_DATABIT_8)
|
||||
else if (datalength == mcalUART_DATABIT_8)
|
||||
{
|
||||
xprvUartConfig.wordLength = DL_UART_WORD_LENGTH_8_BITS;
|
||||
}
|
||||
|
||||
//xprvUartConfig.stopBits = pxUartHandle->xUartConfig.eUartStopBit;
|
||||
uint8_t stopbit = pxUartHandle->xUartConfig.eUartStopBit;
|
||||
if(stopbit == mcalUART_STOP_1)
|
||||
if (stopbit == mcalUART_STOP_1)
|
||||
{
|
||||
xprvUartConfig.stopBits = DL_UART_STOP_BITS_ONE;
|
||||
}
|
||||
else if(stopbit == mcalUART_STOP_2)
|
||||
else if (stopbit == mcalUART_STOP_2)
|
||||
{
|
||||
xprvUartConfig.stopBits = DL_UART_STOP_BITS_TWO;
|
||||
}
|
||||
|
||||
//xprvUartConfig.parity = pxUartHandle->xUartConfig.eUartParityBit;
|
||||
uint8_t paritybit = pxUartHandle->xUartConfig.eUartParityBit;
|
||||
if(paritybit == mcalUART_PARITY_NONE)
|
||||
if (paritybit == mcalUART_PARITY_NONE)
|
||||
{
|
||||
xprvUartConfig.parity = DL_UART_PARITY_NONE;
|
||||
}
|
||||
else if(paritybit == mcalUART_PARITY_ODD)
|
||||
else if (paritybit == mcalUART_PARITY_ODD)
|
||||
{
|
||||
xprvUartConfig.parity = DL_UART_PARITY_ODD;
|
||||
}
|
||||
else if(paritybit == mcalUART_PARITY_EVEN)
|
||||
else if (paritybit == mcalUART_PARITY_EVEN)
|
||||
{
|
||||
xprvUartConfig.parity = DL_UART_PARITY_EVEN;
|
||||
}
|
||||
|
|
@ -374,81 +390,81 @@ static xCoreStatus_t uart_init(McalUartHandle_s* pxUartHandle, McalUartBaudRate_
|
|||
xprvUartConfig.flowControl = DL_UART_FLOW_CONTROL_NONE;
|
||||
|
||||
|
||||
DL_UART_ClockConfig gUART_0ClockConfig ={0};
|
||||
DL_UART_ClockConfig gUART_0ClockConfig = { 0 };
|
||||
gUART_0ClockConfig.clockSel = DL_UART_CLOCK_BUSCLK;
|
||||
gUART_0ClockConfig.divideRatio = DL_UART_MAIN_CLOCK_DIVIDE_RATIO_1;
|
||||
|
||||
DL_UART_Main_setClockConfig(uart_inst, (DL_UART_Main_ClockConfig *) &gUART_0ClockConfig);
|
||||
DL_UART_Main_init(uart_inst, (DL_UART_Main_Config *) &xprvUartConfig);
|
||||
DL_UART_Main_setClockConfig(uart_inst, (DL_UART_Main_ClockConfig*)&gUART_0ClockConfig);
|
||||
DL_UART_Main_init(uart_inst, (DL_UART_Main_Config*)&xprvUartConfig);
|
||||
|
||||
/* Configure baud rate by setting oversampling and baud rate divisors.*/
|
||||
DL_UART_Main_setOversampling(uart_inst, DL_UART_OVERSAMPLING_RATE_16X);
|
||||
|
||||
if(xBaud==115200)
|
||||
if (xBaud == 115200)
|
||||
{
|
||||
|
||||
/*
|
||||
* Target baud rate: 115200
|
||||
* Actual baud rate: 115211.52
|
||||
*/
|
||||
// DL_UART_Main_setBaudRateDivisor(uart_inst, 13, 1);
|
||||
// DL_UART_Main_setBaudRateDivisor(uart_inst, 13, 1);
|
||||
//DL_UART_Main_setBaudRateDivisor(uart_inst, 19, 20);
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 19, 34);
|
||||
}
|
||||
else if(xBaud==9600)
|
||||
else if (xBaud == 9600)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 234, 24);
|
||||
}
|
||||
|
||||
else if(xBaud==2400)
|
||||
else if (xBaud == 2400)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 937, 32);
|
||||
}
|
||||
else if(xBaud==4800)
|
||||
else if (xBaud == 4800)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 468, 48);
|
||||
}
|
||||
else if(xBaud==14400)
|
||||
else if (xBaud == 14400)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 156, 16);
|
||||
}
|
||||
else if(xBaud==19200)
|
||||
else if (xBaud == 19200)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 117, 12);
|
||||
}
|
||||
else if(xBaud==28800)
|
||||
else if (xBaud == 28800)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 78, 8);
|
||||
}
|
||||
else if(xBaud==33600)
|
||||
else if (xBaud == 33600)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 66, 62);
|
||||
}
|
||||
else if(xBaud==38400)
|
||||
else if (xBaud == 38400)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 58, 38);
|
||||
}
|
||||
else if(xBaud==57600)
|
||||
else if (xBaud == 57600)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 39, 4);
|
||||
}
|
||||
else if(xBaud==230400)
|
||||
else if (xBaud == 230400)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 9, 49);
|
||||
}
|
||||
else if(xBaud==460800)
|
||||
else if (xBaud == 460800)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 4, 57);
|
||||
}
|
||||
else if(xBaud==921600)
|
||||
else if (xBaud == 921600)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 2, 28);
|
||||
}
|
||||
else if(xBaud==1000000)
|
||||
else if (xBaud == 1000000)
|
||||
{
|
||||
DL_UART_Main_setBaudRateDivisor(uart_inst, 2, 16);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
/*
|
||||
* Target baud rate: 115200
|
||||
* Actual baud rate: 115211.52
|
||||
|
|
@ -458,7 +474,7 @@ static xCoreStatus_t uart_init(McalUartHandle_s* pxUartHandle, McalUartBaudRate_
|
|||
|
||||
/* Configure Interrupts */
|
||||
|
||||
if(uart_inst==UART0)
|
||||
if (uart_inst == UART0)
|
||||
{
|
||||
|
||||
|
||||
|
|
@ -483,7 +499,7 @@ static xCoreStatus_t uart_init(McalUartHandle_s* pxUartHandle, McalUartBaudRate_
|
|||
NVIC_EnableIRQ(UART0_INT_IRQn);
|
||||
//b_UART0_init_flag=1;
|
||||
}
|
||||
if(uart_inst==UART1)
|
||||
if (uart_inst == UART1)
|
||||
{
|
||||
DL_UART_Main_enableInterrupt(uart_inst,
|
||||
DL_UART_MAIN_INTERRUPT_BREAK_ERROR |
|
||||
|
|
@ -506,7 +522,7 @@ static xCoreStatus_t uart_init(McalUartHandle_s* pxUartHandle, McalUartBaudRate_
|
|||
NVIC_EnableIRQ(UART1_INT_IRQn);
|
||||
//b_UART1_init_flag=1;
|
||||
}
|
||||
else if(uart_inst==UART2)
|
||||
else if (uart_inst == UART2)
|
||||
{
|
||||
|
||||
DL_UART_Main_enableInterrupt(uart_inst,
|
||||
|
|
@ -523,7 +539,7 @@ static xCoreStatus_t uart_init(McalUartHandle_s* pxUartHandle, McalUartBaudRate_
|
|||
DL_UART_Main_setRXFIFOThreshold(UART2, DL_UART_RX_FIFO_LEVEL_ONE_ENTRY);
|
||||
DL_UART_Main_setTXFIFOThreshold(UART2, DL_UART_TX_FIFO_LEVEL_1_2_EMPTY);
|
||||
|
||||
// DL_UART_Main_setRXInterruptTimeout(UART2, 15);
|
||||
// DL_UART_Main_setRXInterruptTimeout(UART2, 15);
|
||||
|
||||
DL_UART_Main_enable(uart_inst);
|
||||
/*Clearing and Enabling Interrupt Requests*/
|
||||
|
|
@ -554,7 +570,7 @@ static void __prvMCAL_UartNotifyRecvCb(uint32 ind_type, ql_uart_port_number_e po
|
|||
if (g_pxUartHandles[i] != NULL && port == (ql_uart_port_number_e)g_pxUartHandles[i]->eUartPortNumber)
|
||||
{
|
||||
if (g_pxUartHandles[i]->pvUartRecvCallback != NULL)
|
||||
g_pxUartHandles[i]->pvUartRecvCallback((IVEC_McalUartEvents_e)ind_type&0xffff, NULL, size);
|
||||
g_pxUartHandles[i]->pvUartRecvCallback((IVEC_McalUartEvents_e)ind_type & 0xffff, NULL, size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -601,5 +617,3 @@ exit:
|
|||
IVEC_MCAL_FUNC_EXIT(LOG_STRING);
|
||||
return l_xFuncStatus;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -113,21 +113,21 @@ SYSCONFIG_WEAK void SYSCFG_DL_initPower(void)
|
|||
DL_GPIO_enablePower(GPIOA);
|
||||
DL_GPIO_enablePower(GPIOB);
|
||||
|
||||
#if UART_PIN_SELECTION == 1
|
||||
DL_UART_Main_reset(UART2);
|
||||
DL_UART_Main_enablePower(UART2);
|
||||
|
||||
#elif UART_PIN_SELECTION == 2
|
||||
DL_UART_Main_reset(UART1);
|
||||
DL_UART_Main_enablePower(UART1);
|
||||
|
||||
#elif UART_PIN_SELECTION == 3
|
||||
DL_UART_Main_reset(UART1);
|
||||
DL_UART_Main_enablePower(UART1);
|
||||
DL_UART_Main_reset(UART2);
|
||||
DL_UART_Main_enablePower(UART2);
|
||||
|
||||
#endif
|
||||
// #if UART_PIN_SELECTION == 1
|
||||
// DL_UART_Main_reset(UART2);
|
||||
// DL_UART_Main_enablePower(UART2);
|
||||
//
|
||||
// #elif UART_PIN_SELECTION == 2
|
||||
// DL_UART_Main_reset(UART1);
|
||||
// DL_UART_Main_enablePower(UART1);
|
||||
//
|
||||
// #elif UART_PIN_SELECTION == 3
|
||||
// DL_UART_Main_reset(UART1);
|
||||
// DL_UART_Main_enablePower(UART1);
|
||||
// DL_UART_Main_reset(UART2);
|
||||
// DL_UART_Main_enablePower(UART2);
|
||||
//
|
||||
// #endif
|
||||
|
||||
// DL_GPIO_enablePower(GPIOA);
|
||||
// DL_GPIO_enablePower(GPIOB);
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ IVEC_EcuCommonErr_e xECU_CANDeInit(MCAN_Regs* MCAN)
|
|||
IVEC_EcuCommonErr_e xECU_GetCanStatus(MCAN_Regs* MCAN, uint16_t speed)
|
||||
{
|
||||
char l_ucErrorString[32] = {0};
|
||||
if( xMCAL_getMCAN_ErrorStatus(&l_ucErrorString) == IVEC_MCAL_STATUS_ERROR )
|
||||
if( xMCAL_getMCAN_ErrorStatus(l_ucErrorString) == IVEC_MCAL_STATUS_ERROR )
|
||||
{
|
||||
xECU_CanReInit(MCAN, speed);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,19 +28,45 @@
|
|||
typedef int PacketRetCode_t;/*SERVICE_SUCESS or SERVICE_FAIL*/
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ecuUART_PORT1 = 0,
|
||||
ecuUART_PORT2,
|
||||
ecuUART_PORT3,
|
||||
ecuUART_PORT_MAX
|
||||
}EcuUartPortNumber_e;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
IVEC_ECU_UART_EVENT_RX_ARRIVED = 1,//(1 << 0), ///< Received new data
|
||||
IVEC_ECU_UART_EVENT_RX_OVERFLOW =2 ,//(1 << 1), ///< Rx fifo overflowed
|
||||
IVEC_ECU_UART_EVENT_TX_COMPLETE = 3//(1 << 2) ///< All data had been sent
|
||||
}IVEC_EcuUartEvents_e;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
McalUartHandle_s __xUartHandle;
|
||||
EcuUartPortNumber_e eUartPortNumber;
|
||||
volatile uint8_t* u8Qbuffer;
|
||||
uint16_t u16QbufSize;
|
||||
uint16_t u16len;
|
||||
void (*pvUartRecvCallback)(EcuUartPortNumber_e, IVEC_EcuUartEvents_e , char *,uint32_t);
|
||||
}EcuUartHandle_s;
|
||||
|
||||
/*===========================================================================
|
||||
* Functions declaration
|
||||
===========================================================================*/
|
||||
IVEC_EcuCommonErr_e xECU_UARTInit(McalUartHandle_s* prvUartHandle, uint32_t speed);
|
||||
IVEC_EcuCommonErr_e xECU_UARTDeInit(McalUartHandle_s *prvUartHandle);
|
||||
IVEC_EcuCommonErr_e xECU_UARTReInit(McalUartHandle_s *prvUartHandle, uint32_t speed);
|
||||
IVEC_EcuCommonErr_e xECU_UARTTransmit(McalUartHandle_s *prvUartHandle, uint8_t* pucBuffer, uint16_t len);
|
||||
IVEC_EcuCommonErr_e xECU_UARTInit(EcuUartHandle_s* prvUartHandle, uint32_t speed);
|
||||
IVEC_EcuCommonErr_e xECU_UARTDeInit(EcuUartHandle_s *prvUartHandle);
|
||||
IVEC_EcuCommonErr_e xECU_UARTReInit(EcuUartHandle_s *prvUartHandle, uint32_t speed);
|
||||
IVEC_EcuCommonErr_e xECU_UARTTransmit(EcuUartHandle_s *prvUartHandle, uint8_t* pucBuffer, uint16_t len);
|
||||
//Uart_Typedef_e xUartWrite(Uart_PortHandle_s *xportHandle, uint8_t* pucBuffer, uint16_t len, uint16_t timeout);
|
||||
IVEC_EcuCommonErr_e xECU_UARTGetData(McalUartHandle_s *prvUartHandle, uint8_t* pucBuffer, uint16_t len, uint16_t timeout);
|
||||
IVEC_EcuCommonErr_e xECU_UARTGetData(EcuUartHandle_s *prvUartHandle, uint8_t* pucBuffer, uint16_t len, uint16_t timeout);
|
||||
//Uart_Typedef_e xUartReceive(Uart_PortHandle_s *xportHandle, uint8_t* pucBuffer, uint16_t len, uint16_t timeout);
|
||||
|
||||
PacketRetCode_t xECU_FormatUartPacket(McalUartHandle_s *prvUartHandle, uint8_t* pucData, uint8_t ucDlc, uint32_t ulId);
|
||||
PacketRetCode_t xECU_ReadCANDataLenOverUART(McalUartHandle_s *prvUartHandle, uint8_t* pucBuf, uint32_t *ulId);
|
||||
PacketRetCode_t xECU_FormatUartPacket(EcuUartHandle_s *prvUartHandle, uint8_t* pucData, uint8_t ucDlc, uint32_t ulId);
|
||||
PacketRetCode_t xECU_ReadCANDataLenOverUART(EcuUartHandle_s *prvUartHandle, uint8_t* pucBuf, uint32_t *ulId);
|
||||
|
||||
PacketRetCode_t xECU_ReadCANDataOverUART(McalUartHandle_s* prvUartHandle, uint8_t* pucBuf, uint32_t *ulId);
|
||||
int vECU_InitiateUartToCanTransmit(McalUartHandle_s* prvUartHandle, uint32_t id, uint8_t *pucData, uint8_t ucLen);
|
||||
PacketRetCode_t xECU_ReadCANDataOverUART(EcuUartHandle_s* prvUartHandle, uint8_t* pucBuf, uint32_t *ulId);
|
||||
int vECU_InitiateUartToCanTransmit(EcuUartHandle_s* prvUartHandle, uint32_t id, uint8_t *pucData, uint8_t ucLen);
|
||||
|
|
|
|||
|
|
@ -5,26 +5,42 @@
|
|||
//#include "ivec_mcal_uart.h"
|
||||
|
||||
#define LOG_STRING "ivec-ecu-UART"
|
||||
#define CAN_UART_BUFFER_MAX_SIZE 4096
|
||||
//#define CAN_UART_BUFFER_MAX_SIZE 4096
|
||||
//#define NFC_UART_BUFFER_MAX_SIZE 256
|
||||
#define DATA_PACKET_TIMEOUT 300
|
||||
|
||||
CmplxFifoQueueHandle_s __gprv_MyEcuUARTResponseQueue = { 0 };
|
||||
volatile static CmplxFifoQueueHandle_s __gprv_MyEcuUARTResponseQueue[IVEC_MCAL_UART_MAX_PORT] = { 0 };
|
||||
|
||||
static uint8_t __gprv_u8CANUartDataBuffer[CAN_UART_BUFFER_MAX_SIZE];
|
||||
static uint32_t __gprv_u32CanUartDataAvailable = 0;
|
||||
//static uint8_t __gprv_u8CANUartDataBuffer[CAN_UART_BUFFER_MAX_SIZE];
|
||||
|
||||
//static uint8_t __gprv_u8NFCUartDataBuffer[NFC_UART_BUFFER_MAX_SIZE];
|
||||
|
||||
int uartCount = 1;
|
||||
|
||||
|
||||
static void __prv_vEcu_CANOverUartMsgCallback(IVEC_McalUartEvents_e eIndType, char* pucBuffer, uint32_t u32Size)
|
||||
static void __prv_vEcu_CANOverUartMsgCallback(McalUartPortNumber_e eUartPort, IVEC_McalUartEvents_e eIndType, char* pucBuffer, uint32_t u32Size)
|
||||
{
|
||||
if(eIndType == IVEC_MCAL_UART_EVENT_RX_ARRIVED){
|
||||
if( u8CMPLX_FifoEnqueue(&__gprv_MyEcuUARTResponseQueue, pucBuffer, u32Size) )
|
||||
__gprv_u32CanUartDataAvailable += u32Size;
|
||||
switch (eUartPort)
|
||||
{
|
||||
case mcalUART_PORT2:
|
||||
if (eIndType == IVEC_MCAL_UART_EVENT_RX_ARRIVED) {
|
||||
u8CMPLX_FifoEnqueue((CmplxFifoQueueHandle_s*)&__gprv_MyEcuUARTResponseQueue[mcalUART_PORT2], pucBuffer, u32Size);
|
||||
|
||||
}
|
||||
break;
|
||||
case mcalUART_PORT3:
|
||||
if (eIndType == IVEC_MCAL_UART_EVENT_RX_ARRIVED) {
|
||||
u8CMPLX_FifoEnqueue((CmplxFifoQueueHandle_s*)&__gprv_MyEcuUARTResponseQueue[mcalUART_PORT3], pucBuffer, u32Size);
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void prvChecksumCalculate(uint8_t* pkt, int len, uint8_t *ck) {
|
||||
static void prvChecksumCalculate(uint8_t* pkt, int len, uint8_t* ck) {
|
||||
uint8_t mck_a = 0, mck_b = 0;
|
||||
/*Incremented to ignore Sync data*/
|
||||
for (int i = 2; i < len - 2; i++) {
|
||||
|
|
@ -38,18 +54,36 @@ static void prvChecksumCalculate(uint8_t* pkt, int len, uint8_t *ck) {
|
|||
}
|
||||
|
||||
|
||||
IVEC_EcuCommonErr_e xECU_UARTInit(McalUartHandle_s* prvUartHandle, uint32_t speed)
|
||||
IVEC_EcuCommonErr_e xECU_UARTInit(EcuUartHandle_s* prvUartHandle, uint32_t speed)
|
||||
{
|
||||
IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
|
||||
uint8_t l_i32Ret;
|
||||
uint8_t l_i32Ret = 0;
|
||||
|
||||
IVEC_ECU_LOG(LOG_STRING, "UART Initilising Queue");
|
||||
__gprv_MyEcuUARTResponseQueue.i32ElementSize = sizeof(uint8_t);
|
||||
__gprv_MyEcuUARTResponseQueue.i32TotalElements = CAN_UART_BUFFER_MAX_SIZE;
|
||||
__gprv_MyEcuUARTResponseQueue.pu8Buffer = (uint8_t*)__gprv_u8CANUartDataBuffer;
|
||||
__gprv_MyEcuUARTResponseQueue.i32QueueType = FIXED_ELEMENT_SIZE_QUEUE;
|
||||
l_i32Ret = u8CMPLX_FifoQueueInit(&__gprv_MyEcuUARTResponseQueue);
|
||||
if (prvUartHandle->eUartPortNumber < IVEC_MCAL_UART_MAX_PORT)
|
||||
{
|
||||
__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber].i32ElementSize = sizeof(uint8_t);
|
||||
|
||||
switch (prvUartHandle->eUartPortNumber)
|
||||
{
|
||||
case mcalUART_PORT2:
|
||||
__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber].i32TotalElements = prvUartHandle->u16QbufSize;
|
||||
__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber].pu8Buffer = prvUartHandle->u8Qbuffer;
|
||||
break;
|
||||
case mcalUART_PORT3:
|
||||
__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber].i32TotalElements = prvUartHandle->u16QbufSize;
|
||||
__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber].pu8Buffer = prvUartHandle->u8Qbuffer;
|
||||
break;
|
||||
default:
|
||||
__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber].pu8Buffer = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber].i32QueueType = FIXED_ELEMENT_SIZE_QUEUE;
|
||||
l_i32Ret = u8CMPLX_FifoQueueInit((CmplxFifoQueueHandle_s*)&__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber]);
|
||||
}
|
||||
|
||||
if (l_i32Ret == 0)
|
||||
{
|
||||
l_xFuncStatus = commonECU_FAIL;
|
||||
|
|
@ -57,33 +91,15 @@ IVEC_EcuCommonErr_e xECU_UARTInit(McalUartHandle_s* prvUartHandle, uint32_t spee
|
|||
}
|
||||
|
||||
IVEC_ECU_LOG(LOG_STRING, "Initilising UART");
|
||||
#if (UART_PIN_SELECTION == 1)
|
||||
prvUartHandle->eUartPortNumber = mcalUART_PORT3;
|
||||
prvUartHandle->__xUartHandle.pvUartRecvCallback = __prv_vEcu_CANOverUartMsgCallback;
|
||||
|
||||
#elif (UART_PIN_SELECTION == 2 )
|
||||
prvUartHandle->eUartPortNumber = mcalUART_PORT2;
|
||||
#elif (UART_PIN_SELECTION == 3)
|
||||
if(uartCount == 1)
|
||||
{
|
||||
prvUartHandle->eUartPortNumber = mcalUART_PORT2;
|
||||
uartCount = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
prvUartHandle->eUartPortNumber = mcalUART_PORT3;
|
||||
uartCount = 1;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
prvUartHandle->pvUartRecvCallback = __prv_vEcu_CANOverUartMsgCallback;
|
||||
prvUartHandle->xUartConfig.eUartBaudrate = speed;
|
||||
prvUartHandle->xUartConfig.eUartFlowCtrl = mcalUART_FC_NONE;
|
||||
prvUartHandle->xUartConfig.eUartDataBit = mcalUART_DATABIT_8;
|
||||
prvUartHandle->xUartConfig.eUartStopBit = mcalUART_STOP_1;
|
||||
prvUartHandle->xUartConfig.eUartParityBit = mcalUART_PARITY_NONE;
|
||||
l_i32Ret = xMCAL_UartInit(prvUartHandle);
|
||||
prvUartHandle->__xUartHandle.xUartConfig.eUartBaudrate = speed;
|
||||
prvUartHandle->__xUartHandle.eUartPortNumber = prvUartHandle->eUartPortNumber;
|
||||
prvUartHandle->__xUartHandle.xUartConfig.eUartFlowCtrl = mcalUART_FC_NONE;
|
||||
prvUartHandle->__xUartHandle.xUartConfig.eUartDataBit = mcalUART_DATABIT_8;
|
||||
prvUartHandle->__xUartHandle.xUartConfig.eUartStopBit = mcalUART_STOP_1;
|
||||
prvUartHandle->__xUartHandle.xUartConfig.eUartParityBit = mcalUART_PARITY_NONE;
|
||||
l_i32Ret = xMCAL_UartInit(&prvUartHandle->__xUartHandle);
|
||||
|
||||
|
||||
if (l_i32Ret != 0)
|
||||
|
|
@ -93,14 +109,14 @@ IVEC_EcuCommonErr_e xECU_UARTInit(McalUartHandle_s* prvUartHandle, uint32_t spee
|
|||
}
|
||||
|
||||
|
||||
exit:
|
||||
exit:
|
||||
IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
|
||||
return l_xFuncStatus;
|
||||
|
||||
}
|
||||
|
||||
|
||||
IVEC_EcuCommonErr_e xECU_UARTDeInit(McalUartHandle_s* prvUartHandle)
|
||||
IVEC_EcuCommonErr_e xECU_UARTDeInit(EcuUartHandle_s* prvUartHandle)
|
||||
{
|
||||
IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||
uint8_t l_i32Ret;
|
||||
|
|
@ -111,32 +127,33 @@ IVEC_EcuCommonErr_e xECU_UARTDeInit(McalUartHandle_s* prvUartHandle)
|
|||
goto exit;
|
||||
}
|
||||
IVEC_ECU_LOG(LOG_STRING, "DeInitilising CAN");
|
||||
l_i32Ret = xMCAL_UartDeInit(prvUartHandle);
|
||||
l_i32Ret = xMCAL_UartDeInit(&prvUartHandle->__xUartHandle);
|
||||
if (l_i32Ret != 0)
|
||||
{
|
||||
l_xFuncStatus = commonECU_DEINIT_FAIL;
|
||||
goto exit;
|
||||
}
|
||||
memset((CmplxFifoQueueHandle_s*)&__gprv_MyEcuUARTResponseQueue, 0, sizeof(__gprv_MyEcuUARTResponseQueue));
|
||||
exit:
|
||||
if (prvUartHandle->eUartPortNumber < IVEC_MCAL_UART_MAX_PORT)
|
||||
vCMPLX_FifoQueueFlush((CmplxFifoQueueHandle_s*)&__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber]);
|
||||
exit:
|
||||
IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
|
||||
return l_xFuncStatus;
|
||||
}
|
||||
|
||||
|
||||
IVEC_EcuCommonErr_e xECU_UARTReInit(McalUartHandle_s *prvUartHandle, uint32_t speed)
|
||||
IVEC_EcuCommonErr_e xECU_UARTReInit(EcuUartHandle_s* prvUartHandle, uint32_t speed)
|
||||
{
|
||||
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
|
||||
uint8_t l_i32Ret;
|
||||
l_i32Ret = xECU_UARTDeInit(prvUartHandle);
|
||||
if(l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
|
||||
if (l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
|
||||
{
|
||||
l_xFuncStatus = commonECU_DEINIT_FAIL;
|
||||
}
|
||||
|
||||
l_i32Ret = xECU_UARTInit(prvUartHandle, speed);
|
||||
|
||||
if(l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
|
||||
if (l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
|
||||
{
|
||||
l_xFuncStatus = commonECU_INIT_FAIL;
|
||||
}
|
||||
|
|
@ -145,18 +162,23 @@ IVEC_EcuCommonErr_e xECU_UARTReInit(McalUartHandle_s *prvUartHandle, uint32_t sp
|
|||
|
||||
|
||||
|
||||
IVEC_EcuCommonErr_e xECU_UARTTransmit(McalUartHandle_s *prvUartHandle, uint8_t* pucBuffer, uint16_t len)
|
||||
IVEC_EcuCommonErr_e xECU_UARTTransmit(EcuUartHandle_s* prvUartHandle, uint8_t* pucBuffer, uint16_t len)
|
||||
{
|
||||
return commonECU_SUCCESS;
|
||||
}
|
||||
IVEC_EcuCommonErr_e xECU_UARTFlush(McalUartHandle_s* prvUartHandle)
|
||||
{
|
||||
if(prvUartHandle ==NULL || prvUartHandle->eUartPortNumber>=IVEC_MCAL_UART_MAX_PORT)
|
||||
vCMPLX_FifoQueueFlush((CmplxFifoQueueHandle_s*)&__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber]);
|
||||
return commonECU_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
IVEC_EcuCommonErr_e xECU_UARTGetData(McalUartHandle_s *prvUartHandle, uint8_t* pucBuffer, uint16_t len, uint16_t timeout)
|
||||
IVEC_EcuCommonErr_e xECU_UARTGetData(EcuUartHandle_s* prvUartHandle, uint8_t* pucBuffer, uint16_t len, uint16_t timeout)
|
||||
{
|
||||
IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||
|
||||
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
|
||||
if (prvUartHandle == NULL)
|
||||
if (prvUartHandle == NULL || prvUartHandle->eUartPortNumber>=IVEC_MCAL_UART_MAX_PORT)
|
||||
{
|
||||
l_xFuncStatus = commonECU_INVALID_PARAM;
|
||||
goto exit;
|
||||
|
|
@ -166,11 +188,11 @@ IVEC_EcuCommonErr_e xECU_UARTGetData(McalUartHandle_s *prvUartHandle, uint8_t* p
|
|||
int l_u32Len = 0;
|
||||
uint32_t u32CommTimestamp = i32MCAL_getTicks();
|
||||
|
||||
while(((i32MCAL_getTicks()-u32CommTimestamp) <= timeout+1) && (ijk < len))
|
||||
while (((i32MCAL_getTicks() - u32CommTimestamp) <= timeout + 1) && (ijk < len))
|
||||
{
|
||||
|
||||
if(!u8CMPLX_FifoQueueEmpty(&__gprv_MyEcuUARTResponseQueue)){
|
||||
if( u8CMPLX_FifoDequeue(&__gprv_MyEcuUARTResponseQueue, &pucBuffer[ijk], &l_u32Len, 0) == 1 )
|
||||
if (!u8CMPLX_FifoQueueEmpty((CmplxFifoQueueHandle_s*)&__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber])) {
|
||||
if (u8CMPLX_FifoDequeue((CmplxFifoQueueHandle_s*)&__gprv_MyEcuUARTResponseQueue[prvUartHandle->eUartPortNumber], &pucBuffer[ijk], &l_u32Len, 0) == 1)
|
||||
ijk++;
|
||||
}
|
||||
}
|
||||
|
|
@ -181,22 +203,22 @@ IVEC_EcuCommonErr_e xECU_UARTGetData(McalUartHandle_s *prvUartHandle, uint8_t* p
|
|||
goto exit;
|
||||
}
|
||||
|
||||
exit:
|
||||
exit:
|
||||
IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
|
||||
return l_xFuncStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PacketRetCode_t xECU_ReadCANDataLenOverUART(McalUartHandle_s *prvUartHandle, uint8_t* pucBuf, uint32_t *ulId)
|
||||
PacketRetCode_t xECU_ReadCANDataLenOverUART(EcuUartHandle_s* prvUartHandle, uint8_t* pucBuf, uint32_t* ulId)
|
||||
{
|
||||
int PktLen = PACKET_FAIL;
|
||||
if ((xECU_UARTGetData(prvUartHandle, (uint8_t*) &pucBuf[0], 1, 0) == commonECU_SUCCESS))
|
||||
if ((xECU_UARTGetData(prvUartHandle, (uint8_t*)&pucBuf[0], 1, 0) == commonECU_SUCCESS))
|
||||
{
|
||||
if (pucBuf[0] == 0xB5)
|
||||
{
|
||||
if (xECU_UARTGetData(prvUartHandle, (uint8_t*) &pucBuf[1], 1, 5) == commonECU_SUCCESS){
|
||||
if (pucBuf[1] != 0x62){
|
||||
if (xECU_UARTGetData(prvUartHandle, (uint8_t*)&pucBuf[1], 1, 5) == commonECU_SUCCESS) {
|
||||
if (pucBuf[1] != 0x62) {
|
||||
PktLen = PACKET_FAIL;
|
||||
goto EXIT; //0x62 not found [OUT OF SYNC]
|
||||
}
|
||||
|
|
@ -206,7 +228,7 @@ PacketRetCode_t xECU_ReadCANDataLenOverUART(McalUartHandle_s *prvUartHandle, uin
|
|||
PktLen = PACKET_FAIL;
|
||||
goto EXIT;
|
||||
}
|
||||
if (xECU_UARTGetData(prvUartHandle, (uint8_t*) &pucBuf[2], 5, DATA_PACKET_TIMEOUT) != commonECU_SUCCESS){
|
||||
if (xECU_UARTGetData(prvUartHandle, (uint8_t*)&pucBuf[2], 5, DATA_PACKET_TIMEOUT) != commonECU_SUCCESS) {
|
||||
PktLen = PACKET_FAIL;
|
||||
goto EXIT;
|
||||
}
|
||||
|
|
@ -214,7 +236,7 @@ PacketRetCode_t xECU_ReadCANDataLenOverUART(McalUartHandle_s *prvUartHandle, uin
|
|||
*(ulId) = (uint32_t)((pucBuf[6] << 24) | (pucBuf[5] << 16) | (pucBuf[4] << 8) | (pucBuf[3] << 0));
|
||||
uint8_t l_ucTempLen = pucBuf[2];
|
||||
PktLen = PKT_HEADER_FOOTER + l_ucTempLen;
|
||||
if (xECU_UARTGetData(prvUartHandle, (uint8_t*) &pucBuf[PKT_HEADER], (uint32_t)(PktLen - PKT_HEADER), DATA_PACKET_TIMEOUT) != commonECU_SUCCESS)
|
||||
if (xECU_UARTGetData(prvUartHandle, (uint8_t*)&pucBuf[PKT_HEADER], (uint32_t)(PktLen - PKT_HEADER), DATA_PACKET_TIMEOUT) != commonECU_SUCCESS)
|
||||
{
|
||||
PktLen = PACKET_FAIL;
|
||||
goto EXIT;
|
||||
|
|
@ -225,14 +247,16 @@ PacketRetCode_t xECU_ReadCANDataLenOverUART(McalUartHandle_s *prvUartHandle, uin
|
|||
/*TODO: (Python Script)Some Times Fails due to Bad Checksum*/
|
||||
if ((checksum[0] == pucBuf[PktLen - 2]) && (checksum[1] == pucBuf[PktLen - 1])) {
|
||||
PktLen -= PKT_HEADER_FOOTER;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
IVEC_ECU_LOG(LOG_STRING, "Packet Checksum Failed\n");
|
||||
PktLen = PACKET_FAIL;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
// COM_FlushBuffer();
|
||||
// COM_FlushBuffer();
|
||||
PktLen = PACKET_FAIL;
|
||||
}
|
||||
}
|
||||
|
|
@ -240,7 +264,7 @@ EXIT:
|
|||
return PktLen;
|
||||
}
|
||||
|
||||
PacketRetCode_t xECU_ReadCANDataOverUART(McalUartHandle_s* prvUartHandle ,uint8_t* pucBuf, uint32_t *ulId)
|
||||
PacketRetCode_t xECU_ReadCANDataOverUART(EcuUartHandle_s* prvUartHandle, uint8_t* pucBuf, uint32_t* ulId)
|
||||
{
|
||||
PacketRetCode_t retCode = PACKET_FAIL;
|
||||
retCode = xECU_ReadCANDataLenOverUART(prvUartHandle, pucBuf, ulId);
|
||||
|
|
@ -248,7 +272,7 @@ PacketRetCode_t xECU_ReadCANDataOverUART(McalUartHandle_s* prvUartHandle ,uint8_
|
|||
}
|
||||
|
||||
|
||||
IVEC_EcuCommonErr_e xECU_UartWrite(McalUartHandle_s* prvUartHandle, uint8_t* pucBuffer, uint16_t len)
|
||||
IVEC_EcuCommonErr_e xECU_UartWrite(EcuUartHandle_s* prvUartHandle, uint8_t* pucBuffer, uint16_t len)
|
||||
{
|
||||
|
||||
IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_WRITE_FAIL;
|
||||
|
|
@ -259,9 +283,9 @@ IVEC_EcuCommonErr_e xECU_UartWrite(McalUartHandle_s* prvUartHandle, uint8_t* puc
|
|||
}
|
||||
|
||||
|
||||
l_i32Ret = xMCAL_UartWrite(prvUartHandle, pucBuffer, len);
|
||||
l_i32Ret = xMCAL_UartWrite(&prvUartHandle->__xUartHandle, pucBuffer, len);
|
||||
|
||||
if(l_i32Ret == commonMCAL_SUCCESS)
|
||||
if (l_i32Ret == commonMCAL_SUCCESS)
|
||||
{
|
||||
l_xFuncStatus = commonECU_SUCCESS;
|
||||
}
|
||||
|
|
@ -270,14 +294,14 @@ IVEC_EcuCommonErr_e xECU_UartWrite(McalUartHandle_s* prvUartHandle, uint8_t* puc
|
|||
}
|
||||
|
||||
|
||||
PacketRetCode_t xECU_FormatUartPacket(McalUartHandle_s* prvUartHandle, uint8_t* pucData, uint8_t ucDlc, uint32_t ulId)
|
||||
PacketRetCode_t xECU_FormatUartPacket(EcuUartHandle_s* prvUartHandle, uint8_t* pucData, uint8_t ucDlc, uint32_t ulId)
|
||||
{
|
||||
pucData[0] = 0xb5; //SYNC_CHAR[0];
|
||||
pucData[1] = 0x62; //SYNC_CHAR[1];
|
||||
pucData[2] = ucDlc;
|
||||
memcpy(&pucData[3], &ulId, sizeof(uint32_t));
|
||||
unsigned char checksum[2] = { 0 };
|
||||
prvChecksumCalculate(pucData, (ucDlc+PKT_HEADER_FOOTER), checksum);
|
||||
prvChecksumCalculate(pucData, (ucDlc + PKT_HEADER_FOOTER), checksum);
|
||||
pucData[(ucDlc + PKT_HEADER_FOOTER) - 2] = checksum[0];
|
||||
pucData[(ucDlc + PKT_HEADER_FOOTER) - 1] = checksum[1];
|
||||
if (xECU_UartWrite(prvUartHandle, pucData, (ucDlc + PKT_HEADER_FOOTER)) != commonECU_SUCCESS) {
|
||||
|
|
@ -287,9 +311,419 @@ PacketRetCode_t xECU_FormatUartPacket(McalUartHandle_s* prvUartHandle, uint8_t*
|
|||
return PACKET_SUCCESS;
|
||||
}
|
||||
|
||||
int vECU_InitiateUartToCanTransmit(McalUartHandle_s* prvUartHandle, uint32_t id, uint8_t *pucData, uint8_t ucLen)
|
||||
int vECU_InitiateUartToCanTransmit(EcuUartHandle_s* prvUartHandle, uint32_t id, uint8_t* pucData, uint8_t ucLen)
|
||||
{
|
||||
uint8_t pucBuf[MAX_PACKET_LENGTH] = {0};
|
||||
uint8_t pucBuf[MAX_PACKET_LENGTH] = { 0 };
|
||||
memcpy(&pucBuf[PKT_HEADER], pucData, ucLen);
|
||||
return ( xECU_FormatUartPacket(prvUartHandle, pucBuf, ucLen, id) == PACKET_SUCCESS ) ? 0 : -1;
|
||||
return (xECU_FormatUartPacket(prvUartHandle, pucBuf, ucLen, id) == PACKET_SUCCESS) ? 0 : -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//#include "../ivec_ECU/ivec_ecu_uart/inc/ivec_ecu_uart.h"
|
||||
//#include "ivec_cmplx_queue.h"
|
||||
//#include "../Core/Include/ivec_mcal_uart.h"
|
||||
////#include <..\Core\Include\ivec_mcal_timer.h>
|
||||
////#include "ivec_mcal_uart.h"
|
||||
//
|
||||
//#define LOG_STRING "ivec-ecu-UART"
|
||||
//#define CAN_UART_BUFFER_MAX_SIZE 4096
|
||||
//#define DATA_PACKET_TIMEOUT 300
|
||||
//
|
||||
//CmplxFifoQueueHandle_s __gprv_MyEcuUARTResponseQueue = { 0 };
|
||||
//
|
||||
//static uint8_t __gprv_u8CANUartDataBuffer[CAN_UART_BUFFER_MAX_SIZE];
|
||||
//static uint32_t __gprv_u32CanUartDataAvailable = 0;
|
||||
//
|
||||
//int uartCount = 1;
|
||||
//
|
||||
//
|
||||
//static void __prv_vEcu_CANOverUartMsgCallback(IVEC_McalUartEvents_e eIndType, char* pucBuffer, uint32_t u32Size)
|
||||
//{
|
||||
// if(eIndType == IVEC_MCAL_UART_EVENT_RX_ARRIVED){
|
||||
// if( u8CMPLX_FifoEnqueue(&__gprv_MyEcuUARTResponseQueue, pucBuffer, u32Size) )
|
||||
// __gprv_u32CanUartDataAvailable += u32Size;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//static void prvChecksumCalculate(uint8_t* pkt, int len, uint8_t *ck) {
|
||||
// uint8_t mck_a = 0, mck_b = 0;
|
||||
// /*Incremented to ignore Sync data*/
|
||||
// for (int i = 2; i < len - 2; i++) {
|
||||
// mck_a += pkt[i];
|
||||
// mck_b += mck_a;
|
||||
// }
|
||||
// mck_a &= 0xFF;
|
||||
// mck_b &= 0xFF;
|
||||
// ck[0] = mck_a;
|
||||
// ck[1] = mck_b;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//IVEC_EcuCommonErr_e xECU_UARTInit(McalUartHandle_s* prvUartHandle, uint32_t speed)
|
||||
//{
|
||||
// IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||
// IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
|
||||
// uint8_t l_i32Ret;
|
||||
//
|
||||
// IVEC_ECU_LOG(LOG_STRING, "UART Initilising Queue");
|
||||
// __gprv_MyEcuUARTResponseQueue.i32ElementSize = sizeof(uint8_t);
|
||||
// __gprv_MyEcuUARTResponseQueue.i32TotalElements = CAN_UART_BUFFER_MAX_SIZE;
|
||||
// __gprv_MyEcuUARTResponseQueue.pu8Buffer = (uint8_t*)__gprv_u8CANUartDataBuffer;
|
||||
// __gprv_MyEcuUARTResponseQueue.i32QueueType = FIXED_ELEMENT_SIZE_QUEUE;
|
||||
// l_i32Ret = u8CMPLX_FifoQueueInit(&__gprv_MyEcuUARTResponseQueue);
|
||||
// if (l_i32Ret == 0)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_FAIL;
|
||||
// goto exit;
|
||||
// }
|
||||
//
|
||||
// IVEC_ECU_LOG(LOG_STRING, "Initilising UART");
|
||||
// #if (UART_PIN_SELECTION == 1)
|
||||
// prvUartHandle->eUartPortNumber = mcalUART_PORT3;
|
||||
//
|
||||
// #elif (UART_PIN_SELECTION == 2 )
|
||||
// prvUartHandle->eUartPortNumber = mcalUART_PORT2;
|
||||
// #elif (UART_PIN_SELECTION == 3)
|
||||
// if(uartCount == 1)
|
||||
// {
|
||||
// prvUartHandle->eUartPortNumber = mcalUART_PORT2;
|
||||
// uartCount = 2;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// prvUartHandle->eUartPortNumber = mcalUART_PORT3;
|
||||
// uartCount = 1;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// #endif
|
||||
//
|
||||
// prvUartHandle->pvUartRecvCallback = __prv_vEcu_CANOverUartMsgCallback;
|
||||
// prvUartHandle->xUartConfig.eUartBaudrate = speed;
|
||||
// prvUartHandle->xUartConfig.eUartFlowCtrl = mcalUART_FC_NONE;
|
||||
// prvUartHandle->xUartConfig.eUartDataBit = mcalUART_DATABIT_8;
|
||||
// prvUartHandle->xUartConfig.eUartStopBit = mcalUART_STOP_1;
|
||||
// prvUartHandle->xUartConfig.eUartParityBit = mcalUART_PARITY_NONE;
|
||||
// l_i32Ret = xMCAL_UartInit(prvUartHandle);
|
||||
//
|
||||
//
|
||||
// if (l_i32Ret != 0)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_INIT_FAIL;
|
||||
// goto exit;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// exit:
|
||||
// IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
|
||||
// return l_xFuncStatus;
|
||||
//
|
||||
//}
|
||||
//
|
||||
//
|
||||
//IVEC_EcuCommonErr_e xECU_UARTDeInit(McalUartHandle_s* prvUartHandle)
|
||||
//{
|
||||
// IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||
// uint8_t l_i32Ret;
|
||||
// IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
|
||||
// if (prvUartHandle == NULL)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_ALREADY_DEINIT;
|
||||
// goto exit;
|
||||
// }
|
||||
// IVEC_ECU_LOG(LOG_STRING, "DeInitilising CAN");
|
||||
// l_i32Ret = xMCAL_UartDeInit(prvUartHandle);
|
||||
// if (l_i32Ret != 0)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_DEINIT_FAIL;
|
||||
// goto exit;
|
||||
// }
|
||||
// memset((CmplxFifoQueueHandle_s*)&__gprv_MyEcuUARTResponseQueue, 0, sizeof(__gprv_MyEcuUARTResponseQueue));
|
||||
// exit:
|
||||
// IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
|
||||
// return l_xFuncStatus;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//IVEC_EcuCommonErr_e xECU_UARTReInit(McalUartHandle_s *prvUartHandle, uint32_t speed)
|
||||
//{
|
||||
// IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
|
||||
// uint8_t l_i32Ret;
|
||||
// l_i32Ret = xECU_UARTDeInit(prvUartHandle);
|
||||
// if(l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_DEINIT_FAIL;
|
||||
// }
|
||||
//
|
||||
// l_i32Ret = xECU_UARTInit(prvUartHandle, speed);
|
||||
//
|
||||
// if(l_i32Ret != IVEC_MCAL_STATUS_SUCCESS)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_INIT_FAIL;
|
||||
// }
|
||||
// return l_xFuncStatus;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//
|
||||
//IVEC_EcuCommonErr_e xECU_UARTTransmit(McalUartHandle_s *prvUartHandle, uint8_t* pucBuffer, uint16_t len)
|
||||
//{
|
||||
// return commonECU_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//IVEC_EcuCommonErr_e xECU_UARTGetData(McalUartHandle_s *prvUartHandle, uint8_t* pucBuffer, uint16_t len, uint16_t timeout)
|
||||
//{
|
||||
// IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||
//
|
||||
// IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_SUCCESS;
|
||||
// if (prvUartHandle == NULL)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_INVALID_PARAM;
|
||||
// goto exit;
|
||||
// }
|
||||
//
|
||||
// uint8_t ijk = 0;
|
||||
// int l_u32Len = 0;
|
||||
// uint32_t u32CommTimestamp = i32MCAL_getTicks();
|
||||
//
|
||||
// while(((i32MCAL_getTicks()-u32CommTimestamp) <= timeout+1) && (ijk < len))
|
||||
// {
|
||||
//
|
||||
// if(!u8CMPLX_FifoQueueEmpty(&__gprv_MyEcuUARTResponseQueue)){
|
||||
// if( u8CMPLX_FifoDequeue(&__gprv_MyEcuUARTResponseQueue, &pucBuffer[ijk], &l_u32Len, 0) == 1 )
|
||||
// ijk++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (ijk != len)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_READ_FAIL;
|
||||
// goto exit;
|
||||
// }
|
||||
//
|
||||
// exit:
|
||||
// IVEC_ECU_FUNC_EXIT(LOG_STRING, 0);
|
||||
// return l_xFuncStatus;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//
|
||||
//PacketRetCode_t xECU_ReadCANDataLenOverUART(McalUartHandle_s *prvUartHandle, uint8_t* pucBuf, uint32_t *ulId)
|
||||
//{
|
||||
// int PktLen = PACKET_FAIL;
|
||||
// if ((xECU_UARTGetData(prvUartHandle, (uint8_t*) &pucBuf[0], 1, 0) == commonECU_SUCCESS))
|
||||
// {
|
||||
// if (pucBuf[0] == 0xB5)
|
||||
// {
|
||||
// if (xECU_UARTGetData(prvUartHandle, (uint8_t*) &pucBuf[1], 1, 5) == commonECU_SUCCESS){
|
||||
// if (pucBuf[1] != 0x62){
|
||||
// PktLen = PACKET_FAIL;
|
||||
// goto EXIT; //0x62 not found [OUT OF SYNC]
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// PktLen = PACKET_FAIL;
|
||||
// goto EXIT;
|
||||
// }
|
||||
// if (xECU_UARTGetData(prvUartHandle, (uint8_t*) &pucBuf[2], 5, DATA_PACKET_TIMEOUT) != commonECU_SUCCESS){
|
||||
// PktLen = PACKET_FAIL;
|
||||
// goto EXIT;
|
||||
// }
|
||||
//
|
||||
// *(ulId) = (uint32_t)((pucBuf[6] << 24) | (pucBuf[5] << 16) | (pucBuf[4] << 8) | (pucBuf[3] << 0));
|
||||
// uint8_t l_ucTempLen = pucBuf[2];
|
||||
// PktLen = PKT_HEADER_FOOTER + l_ucTempLen;
|
||||
// if (xECU_UARTGetData(prvUartHandle, (uint8_t*) &pucBuf[PKT_HEADER], (uint32_t)(PktLen - PKT_HEADER), DATA_PACKET_TIMEOUT) != commonECU_SUCCESS)
|
||||
// {
|
||||
// PktLen = PACKET_FAIL;
|
||||
// goto EXIT;
|
||||
// }
|
||||
// uint8_t checksum[2];
|
||||
// prvChecksumCalculate(pucBuf, PktLen, checksum);
|
||||
//
|
||||
// /*TODO: (Python Script)Some Times Fails due to Bad Checksum*/
|
||||
// if ((checksum[0] == pucBuf[PktLen - 2]) && (checksum[1] == pucBuf[PktLen - 1])) {
|
||||
// PktLen -= PKT_HEADER_FOOTER;
|
||||
// } else
|
||||
// {
|
||||
// IVEC_ECU_LOG(LOG_STRING, "Packet Checksum Failed\n");
|
||||
// PktLen = PACKET_FAIL;
|
||||
// }
|
||||
// } else
|
||||
// {
|
||||
//// COM_FlushBuffer();
|
||||
// PktLen = PACKET_FAIL;
|
||||
// }
|
||||
// }
|
||||
//EXIT:
|
||||
// return PktLen;
|
||||
//}
|
||||
//
|
||||
//PacketRetCode_t xECU_ReadCANDataOverUART(McalUartHandle_s* prvUartHandle ,uint8_t* pucBuf, uint32_t *ulId)
|
||||
//{
|
||||
// PacketRetCode_t retCode = PACKET_FAIL;
|
||||
// retCode = xECU_ReadCANDataLenOverUART(prvUartHandle, pucBuf, ulId);
|
||||
// return retCode;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//IVEC_EcuCommonErr_e xECU_UartWrite(McalUartHandle_s* prvUartHandle, uint8_t* pucBuffer, uint16_t len)
|
||||
//{
|
||||
//
|
||||
// IVEC_EcuCommonErr_e l_xFuncStatus = commonECU_WRITE_FAIL;
|
||||
// uint8_t l_i32Ret;
|
||||
// if (prvUartHandle == NULL)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_INVALID_PARAM;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// l_i32Ret = xMCAL_UartWrite(prvUartHandle, pucBuffer, len);
|
||||
//
|
||||
// if(l_i32Ret == commonMCAL_SUCCESS)
|
||||
// {
|
||||
// l_xFuncStatus = commonECU_SUCCESS;
|
||||
// }
|
||||
//
|
||||
// return l_xFuncStatus;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//PacketRetCode_t xECU_FormatUartPacket(McalUartHandle_s* prvUartHandle, uint8_t* pucData, uint8_t ucDlc, uint32_t ulId)
|
||||
//{
|
||||
// pucData[0] = 0xb5; //SYNC_CHAR[0];
|
||||
// pucData[1] = 0x62; //SYNC_CHAR[1];
|
||||
// pucData[2] = ucDlc;
|
||||
// memcpy(&pucData[3], &ulId, sizeof(uint32_t));
|
||||
// unsigned char checksum[2] = { 0 };
|
||||
// prvChecksumCalculate(pucData, (ucDlc+PKT_HEADER_FOOTER), checksum);
|
||||
// pucData[(ucDlc + PKT_HEADER_FOOTER) - 2] = checksum[0];
|
||||
// pucData[(ucDlc + PKT_HEADER_FOOTER) - 1] = checksum[1];
|
||||
// if (xECU_UartWrite(prvUartHandle, pucData, (ucDlc + PKT_HEADER_FOOTER)) != commonECU_SUCCESS) {
|
||||
//
|
||||
// return PACKET_FAIL;
|
||||
// }
|
||||
// return PACKET_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//int vECU_InitiateUartToCanTransmit(McalUartHandle_s* prvUartHandle, uint32_t id, uint8_t *pucData, uint8_t ucLen)
|
||||
//{
|
||||
// uint8_t pucBuf[MAX_PACKET_LENGTH] = {0};
|
||||
// memcpy(&pucBuf[PKT_HEADER], pucData, ucLen);
|
||||
// return ( xECU_FormatUartPacket(prvUartHandle, pucBuf, ucLen, id) == PACKET_SUCCESS ) ? 0 : -1;
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
void vRTE_MatlabInit(void);
|
||||
void vRTE_MatlabRun(void);
|
||||
void vApp_Init(void);
|
||||
void vApp_RunInit(void);
|
||||
void vRTE_InitUARTCANEcho(void);
|
||||
void vRTE_UARTDataProcess(void);
|
||||
void vRTE_CANDataProcess(void);
|
||||
|
|
|
|||
|
|
@ -14,12 +14,23 @@
|
|||
#include "../../TM1650_SDK/inc/ivec_TM1650.h"
|
||||
|
||||
|
||||
McalUartHandle_s g_xUartHandle;
|
||||
McalUartHandle_s g_xUart2Handle;
|
||||
EcuUartHandle_s g_xUartHandle;
|
||||
EcuUartHandle_s g_xUart2Handle;
|
||||
|
||||
// UART_PIN_SELECTION values:
|
||||
// 1 - Basil Battery Smart
|
||||
// 2 - Basil
|
||||
#define CONFIG_BASIL_BATTERY_SMART 1
|
||||
#define CONFIG_BASIL 2
|
||||
|
||||
#define UART_PIN_SELECTION CONFIG_BASIL // Set the desired UART configuration here
|
||||
|
||||
uint32_t g_u32UartSpeed = 0;
|
||||
xCAN_baud_t g_u16CanSpeed = 0;
|
||||
uint8_t g_pu8Buf[MAX_PACKET_LENGTH] = {0};
|
||||
volatile uint32_t g_u32CanId = 0x1fffffff;
|
||||
#define CAN_UART_BUFFER_MAX_SIZE 4096
|
||||
volatile uint8_t __gprv_u8CANUartDataBuffer[CAN_UART_BUFFER_MAX_SIZE];
|
||||
|
||||
#define MAX_FILTERS 10
|
||||
uint32_t maskValues[MAX_FILTERS];
|
||||
|
|
@ -227,12 +238,33 @@ void vRTE_MatlabRun(void)
|
|||
}
|
||||
}
|
||||
|
||||
void vApp_Init(void)
|
||||
{
|
||||
#if UART_PIN_SELECTION == 1
|
||||
vRTE_MatlabInit();
|
||||
#endif
|
||||
|
||||
vRTE_InitUARTCANEcho();
|
||||
}
|
||||
|
||||
|
||||
void vRTE_InitUARTCANEcho(void)
|
||||
{
|
||||
g_u32UartSpeed = mcalUART_BAUD_115200;
|
||||
g_u16CanSpeed = BAUD_500;
|
||||
g_xUartHandle.u8Qbuffer = __gprv_u8CANUartDataBuffer;
|
||||
g_xUartHandle.u16QbufSize = CAN_UART_BUFFER_MAX_SIZE;
|
||||
|
||||
#if (UART_PIN_SELECTION == 1)
|
||||
g_xUartHandle.eUartPortNumber = ecuUART_PORT3;
|
||||
#elif (UART_PIN_SELECTION == 2)
|
||||
g_xUartHandle.eUartPortNumber = ecuUART_PORT2;
|
||||
#endif
|
||||
|
||||
|
||||
xECU_UARTInit(&g_xUartHandle, g_u32UartSpeed);
|
||||
|
||||
|
||||
// #if UART_PIN_SELECTION == 3
|
||||
// xECU_UARTInit(&g_xUart2Handle, g_u32UartSpeed);
|
||||
// #endif
|
||||
|
|
@ -240,6 +272,20 @@ void vRTE_InitUARTCANEcho(void)
|
|||
xECU_CANInit(CANFD0,g_u16CanSpeed);
|
||||
}
|
||||
|
||||
void vApp_RunInit(void)
|
||||
{
|
||||
vRTE_UARTDataProcess();
|
||||
vRTE_CANDataProcess();
|
||||
}
|
||||
|
||||
void vMCAL_TimerCallback(void)
|
||||
{
|
||||
#if UART_PIN_SELECTION == 1
|
||||
vRTE_MatlabRun();
|
||||
#endif
|
||||
|
||||
DL_TimerA_clearInterruptStatus(TIMER_1_INST, GPTIMER_CPU_INT_IMASK_Z_SET);
|
||||
}
|
||||
void vCanFilterMaskSaveVal(uint8_t ucIdx, uint32_t mask, bool isExtended)
|
||||
{
|
||||
maskCount = ucIdx;
|
||||
|
|
@ -322,7 +368,7 @@ void vCanConfigFilter() {
|
|||
extFilterElement.efid2 = maskValues[i];
|
||||
extFilterElement.efec = 001;
|
||||
extFilterElement.eft = 10;
|
||||
DL_MCAN_addExtMsgIDFilter(CANFD0, extendedFilterNumber, (DL_MCAN_StdMsgIDFilterElement *) &extFilterElement);
|
||||
DL_MCAN_addExtMsgIDFilter(CANFD0, extendedFilterNumber, &extFilterElement);
|
||||
// filterValues[i] = 0;
|
||||
// maskValues[i] = 0;
|
||||
extendedFilterNumber++;
|
||||
|
|
@ -335,7 +381,7 @@ void vCanConfigFilter() {
|
|||
stdFilterElement.sfid2 = maskValues[i];
|
||||
stdFilterElement.sfec = 001;
|
||||
stdFilterElement.sft = 10;
|
||||
DL_MCAN_addStdMsgIDFilter(CANFD0, stadardFilterNumber,(DL_MCAN_StdMsgIDFilterElement *) &stdFilterElement);
|
||||
DL_MCAN_addStdMsgIDFilter(CANFD0, stadardFilterNumber, &stdFilterElement);
|
||||
// filterValues[i] = 0;
|
||||
// maskValues[i] = 0;
|
||||
stadardFilterNumber++;
|
||||
|
|
|
|||
22
main.c
22
main.c
|
|
@ -16,15 +16,10 @@
|
|||
#include "../Core/Include/ivec_mcal_uart.h"
|
||||
#include "string.h"
|
||||
#include "ivec_rte.h"
|
||||
extern McalUartHandle_s g_xUartHandle;
|
||||
void vMCAL_TimerCallback(void)
|
||||
{
|
||||
#if UART_PIN_SELECTION == 1
|
||||
vRTE_MatlabRun();
|
||||
#endif
|
||||
|
||||
DL_TimerA_clearInterruptStatus(TIMER_1_INST, GPTIMER_CPU_INT_IMASK_Z_SET);
|
||||
}
|
||||
//extern McalUartHandle_s g_xUartHandle;
|
||||
|
||||
|
||||
|
||||
static void __prv_TimerConfig(void)
|
||||
{
|
||||
|
|
@ -44,16 +39,13 @@ int main(void)
|
|||
xMCAL_SYSTICK_INIT(Period_1ms);
|
||||
__prv_TimerConfig();
|
||||
|
||||
#if UART_PIN_SELECTION == 1
|
||||
vRTE_MatlabInit();
|
||||
#endif
|
||||
|
||||
vRTE_InitUARTCANEcho();
|
||||
vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x6, NULL, 0);
|
||||
|
||||
vApp_Init();
|
||||
// vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x6, NULL, 0);
|
||||
while(1)
|
||||
{
|
||||
vRTE_UARTDataProcess();
|
||||
vRTE_CANDataProcess();
|
||||
vApp_RunInit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,11 +34,7 @@ typedef enum
|
|||
#define SYSOSC 4
|
||||
#define SLEEP0 6
|
||||
|
||||
// UART_PIN_SELECTION values:
|
||||
// 1 - Basil Battery Smart
|
||||
// 2 - Basil
|
||||
// 3 - Battery Swapping Station
|
||||
#define UART_PIN_SELECTION 1 // Set the desired UART configuration here
|
||||
|
||||
|
||||
|
||||
volatile int i32TickCnt;
|
||||
|
|
|
|||
Loading…
Reference in New Issue