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
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
McalUartHandle_s* g_pxUartHandles[IVEC_MCAL_UART_MAX_PORT] = { 0 };
|
||||
static uint32_t __gprv_u32DataCount = 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)
|
||||
{
|
||||
|
|
@ -23,7 +23,7 @@ void UART_ReadCallback(UART_Regs *uart, uint8_t *buf, bool status)
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
{
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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,23 +5,39 @@
|
|||
//#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)
|
||||
{
|
||||
switch (eUartPort)
|
||||
{
|
||||
case mcalUART_PORT2:
|
||||
if (eIndType == IVEC_MCAL_UART_EVENT_RX_ARRIVED) {
|
||||
if( u8CMPLX_FifoEnqueue(&__gprv_MyEcuUARTResponseQueue, pucBuffer, u32Size) )
|
||||
__gprv_u32CanUartDataAvailable += u32Size;
|
||||
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) {
|
||||
|
|
@ -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)
|
||||
|
|
@ -100,7 +116,7 @@ IVEC_EcuCommonErr_e xECU_UARTInit(McalUartHandle_s* prvUartHandle, uint32_t spee
|
|||
}
|
||||
|
||||
|
||||
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,20 +127,21 @@ 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));
|
||||
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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -169,8 +191,8 @@ IVEC_EcuCommonErr_e xECU_UARTGetData(McalUartHandle_s *prvUartHandle, uint8_t* p
|
|||
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++;
|
||||
}
|
||||
}
|
||||
|
|
@ -188,7 +210,7 @@ IVEC_EcuCommonErr_e xECU_UARTGetData(McalUartHandle_s *prvUartHandle, uint8_t* p
|
|||
|
||||
|
||||
|
||||
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))
|
||||
|
|
@ -225,12 +247,14 @@ 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();
|
||||
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,7 +283,7 @@ 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)
|
||||
{
|
||||
|
|
@ -270,7 +294,7 @@ 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];
|
||||
|
|
@ -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 };
|
||||
memcpy(&pucBuf[PKT_HEADER], pucData, ucLen);
|
||||
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