fix: can implementation
- add ping reply - can mcal implementation from socmeter - removed the dot buffer usage in TM1650 - removed unsued variables/codestable
parent
ab99333dad
commit
ed765079dd
|
|
@ -1,27 +1,23 @@
|
|||
|
||||
#ifndef CORE_INCLUDE_IVEC_MCAL_MCAN_H_
|
||||
#define CORE_INCLUDE_IVEC_MCAL_MCAN_H_
|
||||
|
||||
#include "ti_msp_dl_config.h"
|
||||
#include "..\utils\utils.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
STD_ID = 0x00,
|
||||
EXT_ID = 0x01,
|
||||
ERROR = 0x02
|
||||
} xCanIdType_t;
|
||||
#include "ti_msp_dl_config.h"
|
||||
|
||||
typedef enum {
|
||||
STD_ID = 0x00, EXT_ID = 0x01, ERROR = 0x02
|
||||
} xCanIdType_t;
|
||||
|
||||
|
||||
IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* const mcan, xCAN_baud_t BAUD);
|
||||
IVEC_McalStatus_e xMCAL_MCANDeInit(MCAN_Regs* const mcan);
|
||||
IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, DL_MCAN_TxBufElement *TxMsg ,uint16_t *TxData, uint32_t BufNum, int Bytes);
|
||||
IVEC_McalStatus_e xMCAL_MCANRx(MCAN_Regs *MCAN, DL_MCAN_RxBufElement *RxMsg ,uint32_t FifoNum,uint8_t *RxData,int DLC);
|
||||
//IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, uint32_t u32ID ,uint16_t *TxData, uint32_t BufNum, uint32_t Bytes);
|
||||
IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, uint32_t u32ID ,uint16_t *TxData, uint32_t BufNum, uint32_t Bytes);
|
||||
IVEC_McalStatus_e xMCAL_MCANTxBlocking(MCAN_Regs *MCAN, uint32_t u32ID ,uint16_t *TxData, uint32_t BufNum, int Bytes);
|
||||
IVEC_McalStatus_e xMCAL_MCANRx(MCAN_Regs *MCAN,uint32_t *ID ,uint8_t *RxData, int DLC);
|
||||
IVEC_McalStatus_e xMCAL_getMCAN_ErrorStatus(char *ErrorStatus);
|
||||
IVEC_McalStatus_e xMCAL_getMCAN_InterruptLine1Status(uint32_t *Interrupt_Status);
|
||||
|
||||
void mcu_FDCAN_RxFifo_Callback(uint32_t Identifier, uint8_t *data, uint16_t DataLength);
|
||||
|
||||
IVEC_McalStatus_e xMCAL_resetMCAN(MCAN_Regs* const mcan, xCAN_baud_t BAUD);
|
||||
|
||||
#endif /* CORE_INCLUDE_IVEC_MCAL_MCAN_H_ */
|
||||
|
|
|
|||
|
|
@ -7,28 +7,32 @@
|
|||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <..\Core\Include\ivec_mcal_mcan.h>
|
||||
#include <../Core/Include/ivec_mcal_mcan.h>
|
||||
#include "string.h"
|
||||
|
||||
static volatile bool b_MCAN_InitFlag = 0; /*!< CAN initialization flag */
|
||||
static volatile bool b_ServiceInt=true;
|
||||
static volatile uint32_t u32InterruptLine1Status;
|
||||
static char u8ErrorInterruptStatus[50];
|
||||
static volatile DL_MCAN_RxFIFOStatus rxFS;
|
||||
static DL_MCAN_RxBufElement TempRxMsg;
|
||||
static uint32_t id;
|
||||
extern uint16_t idx;
|
||||
uint32_t IntrStatus;
|
||||
static volatile uint8_t u8_MCAN_StatusFlag = IVEC_MCAL_STATUS_ERROR;
|
||||
uint8_t g_CanData[8];
|
||||
volatile DL_MCAN_ProtocolStatus HeaderStat;
|
||||
#define MCAN_FILTER_SIZE 4u
|
||||
|
||||
extern uint16_t g_u16CanSpeed;
|
||||
|
||||
|
||||
volatile bool b_MCAN_InitFlag = 0; /*!< CAN initialization flag */
|
||||
volatile uint8_t u8_MCAN_StatusFlag = IVEC_MCAL_STATUS_ERROR;
|
||||
volatile bool b_ServiceInt=true;
|
||||
volatile uint32_t u32InterruptLine1Status;
|
||||
volatile char u8ErrorInterruptStatus[50];
|
||||
volatile DL_MCAN_RxFIFOStatus rxFS;
|
||||
volatile DL_MCAN_RxBufElement TempRxMsg;
|
||||
volatile uint8_t TempRxBuffer[8];
|
||||
volatile uint32_t TempRxID;
|
||||
volatile uint32_t id;
|
||||
DL_MCAN_ProtocolStatus HeaderStat;
|
||||
volatile uint32_t l_canTransmitTimeout;
|
||||
volatile uint8_t u8CallBack_buff[8]={0};
|
||||
volatile IVEC_McalStatus_e l_statusFlag = IVEC_MCAL_STATUS_SUCCESS;
|
||||
extern volatile uint8_t u8CANDataAct;
|
||||
/*REQUIRED MCAN CONFIGS*/
|
||||
|
||||
|
||||
__attribute__((weak)) void mcu_FDCAN_RxFifo_Callback(uint32_t Identifier, uint8_t *data, uint16_t DataLength)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*=======================================================================================PRIVATE_MEMBERS======================================================================================*/
|
||||
|
||||
static const DL_MCAN_ClockConfig gMCAN0ClockConf = {
|
||||
|
|
@ -36,7 +40,7 @@ static const DL_MCAN_ClockConfig gMCAN0ClockConf = {
|
|||
.divider = DL_MCAN_FCLK_DIV_1,
|
||||
};
|
||||
|
||||
static const DL_MCAN_InitParams gMCAN0InitParams= {
|
||||
static DL_MCAN_InitParams gMCAN0InitParams= {
|
||||
|
||||
/* Initialize MCAN Init parameters. */
|
||||
.fdMode = false,
|
||||
|
|
@ -69,24 +73,18 @@ static DL_MCAN_ConfigParams gMCAN0ConfigParams={
|
|||
.filterConfig.rrfe = false,
|
||||
.filterConfig.anfe = 0,
|
||||
.filterConfig.anfs = 0,
|
||||
// .filterConfig.rrfs = true,
|
||||
// .filterConfig.rrfe = true,
|
||||
// .filterConfig.anfe = 1,
|
||||
// .filterConfig.anfs = 1,
|
||||
};
|
||||
|
||||
|
||||
|
||||
static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParams ={
|
||||
|
||||
/* Standard ID Filter List Start Address. */
|
||||
.flssa = 5 ,
|
||||
.flssa = 0 ,
|
||||
/* List Size: Standard ID. */
|
||||
.lss = MCAN_FILTER_SIZE,
|
||||
.lss = 0 ,
|
||||
/* Extended ID Filter List Start Address. */
|
||||
.flesa = 48 ,
|
||||
.flesa = 0 ,
|
||||
/* List Size: Extended ID. */
|
||||
.lse = 1 ,
|
||||
.lse = 0 ,
|
||||
/* Tx Buffers Start Address. */
|
||||
.txStartAddr = 10 ,
|
||||
/* Number of Dedicated Transmit Buffers. */
|
||||
|
|
@ -126,24 +124,6 @@ static DL_MCAN_MsgRAMConfigParams gMCAN0MsgRAMConfigParams ={
|
|||
.rxFIFO1ElemSize = DL_MCAN_ELEM_SIZE_8BYTES,
|
||||
};
|
||||
|
||||
//static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem = {
|
||||
// .sfec = 0x1, // Store in Rx FIFO 0 if filter matches
|
||||
// .sft = 0x11, // Disable filter, receive all IDs
|
||||
// .sfid1 = 0, // These values won't be used because filtering is disabled
|
||||
// .sfid2 = 0, // These values won't be used because filtering is disabled
|
||||
//};
|
||||
//
|
||||
//// Static filter element definition to disable filtering
|
||||
//static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFilterElem = {
|
||||
// .efid1 = 0, // These values won't be used because filtering is disabled
|
||||
// .efec = 0x0, // Disable filter element (0b000)
|
||||
// .efid2 = 0xffffffff, // These values won't be used because filtering is disabled
|
||||
// .eft = 0x3, // Set to 0b11 for disabling filtering (no specific filter applied)
|
||||
//};
|
||||
|
||||
|
||||
|
||||
|
||||
static DL_MCAN_BitTimingParams gMCAN0BitTimes_500 = {
|
||||
/* Arbitration Baud Rate Pre-scaler. */
|
||||
.nomRatePrescalar = 0,
|
||||
|
|
@ -163,45 +143,7 @@ static DL_MCAN_BitTimingParams gMCAN0BitTimes_500 = {
|
|||
.dataSynchJumpWidth = 0,
|
||||
};
|
||||
|
||||
static const DL_MCAN_BitTimingParams gMCAN0BitTimes_250 = {
|
||||
/* Arbitration Baud Rate Pre-scaler. */
|
||||
.nomRatePrescalar = 0,
|
||||
/* Arbitration Time segment before sample point. */
|
||||
.nomTimeSeg1 = 82,
|
||||
/* Arbitration Time segment after sample point. */
|
||||
.nomTimeSeg2 = 11,
|
||||
/* Arbitration (Re)Synchronization Jump Width Range. */
|
||||
.nomSynchJumpWidth = 11,
|
||||
/* Data Baud Rate Pre-scaler. */
|
||||
.dataRatePrescalar = 0,
|
||||
/* Data Time segment before sample point. */
|
||||
.dataTimeSeg1 = 0,
|
||||
/* Data Time segment after sample point. */
|
||||
.dataTimeSeg2 = 0,
|
||||
/* Data (Re)Synchronization Jump Width. */
|
||||
.dataSynchJumpWidth = 0,
|
||||
};
|
||||
|
||||
//static const DL_MCAN_BitTimingParams gMCAN0BitTimes_125 = {
|
||||
// /* Arbitration Baud Rate Pre-scaler. */
|
||||
// .nomRatePrescalar = 0,
|
||||
// /* Arbitration Time segment before sample point. */
|
||||
// .nomTimeSeg1 = 138,
|
||||
// /* Arbitration Time segment after sample point. */
|
||||
// .nomTimeSeg2 = 19,
|
||||
// /* Arbitration (Re)Synchronization Jump Width Range. */
|
||||
// .nomSynchJumpWidth = 19,
|
||||
// /* Data Baud Rate Pre-scaler. */
|
||||
// .dataRatePrescalar = 0,
|
||||
// /* Data Time segment before sample point. */
|
||||
// .dataTimeSeg1 = 0,
|
||||
// /* Data Time segment after sample point. */
|
||||
// .dataTimeSeg2 = 0,
|
||||
// /* Data (Re)Synchronization Jump Width. */
|
||||
// .dataSynchJumpWidth = 0,
|
||||
//};
|
||||
|
||||
static const DL_MCAN_BitTimingParams gMCAN0BitTimes_150 = {
|
||||
static DL_MCAN_BitTimingParams gMCAN0BitTimes_250 = {
|
||||
/* Arbitration Baud Rate Pre-scaler. */
|
||||
.nomRatePrescalar = 0,
|
||||
/* Arbitration Time segment before sample point. */
|
||||
|
|
@ -213,33 +155,84 @@ static const DL_MCAN_BitTimingParams gMCAN0BitTimes_150 = {
|
|||
/* Data Baud Rate Pre-scaler. */
|
||||
.dataRatePrescalar = 0,
|
||||
/* Data Time segment before sample point. */
|
||||
.dataTimeSeg1 = 19,
|
||||
.dataTimeSeg1 = 0,
|
||||
/* Data Time segment after sample point. */
|
||||
.dataTimeSeg2 = 2,
|
||||
.dataTimeSeg2 = 0,
|
||||
/* Data (Re)Synchronization Jump Width. */
|
||||
.dataSynchJumpWidth = 2,
|
||||
.dataSynchJumpWidth = 0,
|
||||
};
|
||||
|
||||
|
||||
static const DL_MCAN_BitTimingParams gMCAN0BitTimes_1000 = {
|
||||
/* Arbitration Baud Rate Pre-scaler. */
|
||||
.nomRatePrescalar = 0,
|
||||
/* Arbitration Time segment before sample point. */
|
||||
.nomTimeSeg1 = 19,
|
||||
/* Arbitration Time segment after sample point. */
|
||||
.nomTimeSeg2 = 2,
|
||||
/* Arbitration (Re)Synchronization Jump Width Range. */
|
||||
.nomSynchJumpWidth = 2,
|
||||
/* Data Baud Rate Pre-scaler. */
|
||||
.dataRatePrescalar = 0,
|
||||
/* Data Time segment before sample point. */
|
||||
.dataTimeSeg1 = 19,
|
||||
/* Data Time segment after sample point. */
|
||||
.dataTimeSeg2 = 2,
|
||||
/* Data (Re)Synchronization Jump Width. */
|
||||
.dataSynchJumpWidth = 2,
|
||||
static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem1 = {
|
||||
.sfec = 0x1,
|
||||
.sft = 0x01,
|
||||
.sfid1 = 0x1AE,
|
||||
.sfid2 = 0x520,
|
||||
};
|
||||
|
||||
static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem2 = {
|
||||
.sfec = 0x1,
|
||||
.sft = 0x00,
|
||||
.sfid1 = 0xBB,
|
||||
.sfid2 = 0xBB,
|
||||
};
|
||||
|
||||
static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem3 = {
|
||||
.sfec = 0x1,
|
||||
.sft = 0x00,
|
||||
.sfid1 = 0x1A4,
|
||||
.sfid2 = 0x1A4,
|
||||
};
|
||||
|
||||
static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem4 = {
|
||||
.sfec = 0x1,
|
||||
.sft = 0x00,
|
||||
.sfid1 = 0x521,
|
||||
.sfid2 = 0x521,
|
||||
};
|
||||
|
||||
static const DL_MCAN_StdMsgIDFilterElement gMCAN0StdFiltelem5 = {
|
||||
.sfec = 0x1,
|
||||
.sft = 0x00,
|
||||
.sfid1 = 0x16,
|
||||
.sfid2 = 0x16,
|
||||
};
|
||||
|
||||
static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFiltelem1 = {
|
||||
.efec = 0x1,
|
||||
.eft = 0x0,
|
||||
.efid1 = 0x18904001,
|
||||
.efid2 = 0x18904001,
|
||||
};
|
||||
|
||||
static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFiltelem2 = {
|
||||
.efec = 0x1,
|
||||
.eft = 0x0,
|
||||
.efid1 = 0x1CECFF23,
|
||||
.efid2 = 0x1CECFF23,
|
||||
};
|
||||
|
||||
static const DL_MCAN_ExtMsgIDFilterElement gMCAN0ExtFiltelem3 = {
|
||||
.efec = 0x1,
|
||||
.eft = 0x0,
|
||||
.efid1 = 0x1CEBFF23,
|
||||
.efid2 = 0x1CEBFF23,
|
||||
};
|
||||
|
||||
volatile DL_MCAN_TxBufElement txMsg = {
|
||||
.id = ((uint32_t)(0x00)) << 18U,
|
||||
.rtr = 0U,
|
||||
.xtd = 0U,
|
||||
.esi = 0U,
|
||||
.dlc = 8U,
|
||||
.brs = 1U,
|
||||
.fdf = 1U,
|
||||
.efc = 1U,
|
||||
.mm = 0xAAU,
|
||||
.data = 0U,
|
||||
};
|
||||
|
||||
|
||||
/*____________________________________________________________________________________________________________________________________________________________________________________________*/
|
||||
|
||||
|
||||
|
|
@ -251,125 +244,26 @@ static const DL_MCAN_BitTimingParams gMCAN0BitTimes_1000 = {
|
|||
* @brief Static Function to store RX data in a static buffer
|
||||
* @retval void
|
||||
*/
|
||||
//static void _prv_vGetRxMsg(DL_MCAN_RxBufElement *rxMsg,uint8_t *RxData,int DLC)
|
||||
//{
|
||||
// for (int i =0 ; i < DLC ; i++)
|
||||
// {
|
||||
// RxData[i] = rxMsg->data[i];
|
||||
// }
|
||||
//
|
||||
//}
|
||||
static void _prv_vGetRxMsg(DL_MCAN_RxBufElement *rxMsg,uint8_t *RxData,int DLC)
|
||||
static void _prv_vGetRxMsg(DL_MCAN_RxBufElement *rxMsg,uint32_t *ID,uint8_t *RxData,int DLC)
|
||||
{
|
||||
|
||||
id = ((rxMsg->id & (uint32_t) 0x1FFC0000) >> (uint32_t) 18);
|
||||
for (int i =0 ; i < DLC ; i++)
|
||||
|
||||
switch (id) {
|
||||
case 0x5:
|
||||
|
||||
*RxData = rxMsg->data[0];
|
||||
idx = (rxMsg->data[0] + 1) % 256;
|
||||
|
||||
break;
|
||||
default:
|
||||
/* Don't do anything */
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Private Function working as an Error Handler in IRQ
|
||||
* @retval void
|
||||
*/
|
||||
static void ErrorHandler()
|
||||
{
|
||||
switch(DL_MCAN_getIntrStatus(CANFD0))
|
||||
{
|
||||
case MCAN_IR_PED_MASK:
|
||||
strcpy(u8ErrorInterruptStatus, "Protocol Error in Data Phase!");
|
||||
__asm("nop");
|
||||
break;
|
||||
case MCAN_IR_PEA_MASK:
|
||||
strcpy(u8ErrorInterruptStatus, "Protocol Error in Arbitration Phase!");
|
||||
__asm("nop");
|
||||
break;
|
||||
case MCAN_IR_BO_MASK:
|
||||
strcpy(u8ErrorInterruptStatus, "CAN BUS OFF!");
|
||||
DL_MCAN_reset(CANFD0);
|
||||
__asm("nop");
|
||||
break;
|
||||
case MCAN_IR_EW_MASK:
|
||||
strcpy(u8ErrorInterruptStatus, "Warning Status Interrupt generated!");
|
||||
__asm("nop");
|
||||
break;
|
||||
case MCAN_IR_EP_MASK:
|
||||
strcpy(u8ErrorInterruptStatus, "Error Passive Interrupt generated!");
|
||||
__asm("nop");
|
||||
break;
|
||||
case MCAN_IR_ELO_MASK:
|
||||
strcpy(u8ErrorInterruptStatus, "Error Logging Overflow!");
|
||||
__asm("nop");
|
||||
break;
|
||||
case MCAN_IR_BEU_MASK:
|
||||
strcpy(u8ErrorInterruptStatus, "Bit Error Uncorrected!");
|
||||
__asm("nop");
|
||||
break;
|
||||
case MCAN_IR_TOO_MASK:
|
||||
strcpy(u8ErrorInterruptStatus, "Timeout Occured!");
|
||||
__asm("nop");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
RxData[i] = (rxMsg->data[i] & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default Interrupt Handler for MCAN
|
||||
*
|
||||
*/
|
||||
//void CANFD0_IRQHandler(void)
|
||||
//{
|
||||
// ErrorHandler();
|
||||
//
|
||||
// switch (DL_MCAN_getPendingInterrupt(CANFD0)) {
|
||||
// case DL_MCAN_IIDX_LINE1:
|
||||
// /* Check MCAN interrupts fired during TX/RX of CAN package */
|
||||
// u32InterruptLine1Status |= DL_MCAN_getIntrStatus(CANFD0);
|
||||
// DL_MCAN_clearIntrStatus(CANFD0, u32InterruptLine1Status,DL_MCAN_INTR_SRC_MCAN_LINE_1);
|
||||
// b_ServiceInt = true;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
void CANFD0_IRQHandler(void)
|
||||
{
|
||||
IntrStatus = DL_MCAN_getIntrStatus(CANFD0);
|
||||
uint32_t IntrStatus = DL_MCAN_getIntrStatus(CANFD0);
|
||||
DL_MCAN_getProtocolStatus(CANFD0, &HeaderStat);
|
||||
|
||||
if(HeaderStat.busOffStatus==1)
|
||||
{
|
||||
DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL);
|
||||
|
||||
}
|
||||
if (HeaderStat.lastErrCode) {
|
||||
|
||||
if (HeaderStat.lastErrCode != 3){
|
||||
int status = -1;
|
||||
//printf("Attempting recovery...\n");
|
||||
status = xECU_CanReInit(CANFD0 , g_u16CanSpeed);
|
||||
if(status == 0)
|
||||
{
|
||||
//printf("done\n");
|
||||
}
|
||||
}
|
||||
// else
|
||||
//printf("tx ack err...\n");
|
||||
}
|
||||
|
||||
if (IntrStatus & DL_MCAN_INTERRUPT_TC){
|
||||
__asm("nop");
|
||||
DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1);
|
||||
|
|
@ -378,61 +272,71 @@ void CANFD0_IRQHandler(void)
|
|||
u8_MCAN_StatusFlag = IVEC_MCAL_STATUS_SUCCESS;
|
||||
__asm("nop");
|
||||
}
|
||||
if(IntrStatus & DL_MCAN_INTERRUPT_RF0N)
|
||||
{
|
||||
else if(IntrStatus & DL_MCAN_INTERRUPT_RF0N){
|
||||
|
||||
while (false == b_ServiceInt);
|
||||
|
||||
b_ServiceInt = false;
|
||||
rxFS.fillLvl = 0;
|
||||
rxFS.num = DL_MCAN_RX_FIFO_NUM_0;
|
||||
|
||||
|
||||
int status = -1;
|
||||
|
||||
while ((rxFS.fillLvl) == 0)
|
||||
{
|
||||
DL_MCAN_getRxFIFOStatus(CANFD0, &rxFS);
|
||||
}
|
||||
if (rxFS.fillLvl > 0) {
|
||||
// There are messages to process
|
||||
while (rxFS.fillLvl > 0) {
|
||||
// Read and process messages...
|
||||
// (Assuming you have logic to read from the FIFO)
|
||||
DL_MCAN_readMsgRam(CANFD0, DL_MCAN_MEM_TYPE_FIFO, 0, rxFS.num, &TempRxMsg);
|
||||
|
||||
// Acknowledge the message
|
||||
DL_MCAN_readMsgRam(CANFD0, DL_MCAN_MEM_TYPE_FIFO, 0, rxFS.num, &TempRxMsg);
|
||||
DL_MCAN_writeRxFIFOAck(CANFD0, rxFS.num, rxFS.getIdx);
|
||||
|
||||
// Update the FIFO status again after reading
|
||||
DL_MCAN_getRxFIFOStatus(CANFD0, &rxFS);
|
||||
}
|
||||
}
|
||||
|
||||
xCanIdType_t idType = ERROR;
|
||||
uint64_t idx = 0;
|
||||
idx = TempRxMsg.id;
|
||||
if(TempRxMsg.xtd == 0)
|
||||
if (TempRxMsg.id >= 0 && TempRxMsg.id <= 0x7FF)
|
||||
{
|
||||
idx = ((TempRxMsg.id & (uint32_t) 0x1FFC0000) >> (uint32_t) 18);
|
||||
idType = STD_ID;
|
||||
} else if (TempRxMsg.id <= 0x1FFFFFFF)
|
||||
{
|
||||
idType = EXT_ID;
|
||||
}
|
||||
|
||||
if(idx)
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
for(uint8_t inx = 0; inx <= 7; inx++)
|
||||
{
|
||||
g_CanData[inx] = TempRxMsg.data[inx];
|
||||
}
|
||||
mcu_FDCAN_RxFifo_Callback(idx, &g_CanData[0], TempRxMsg.dlc);
|
||||
u8CallBack_buff[i]=(TempRxMsg.data[i] & 0xFF);
|
||||
}
|
||||
|
||||
__asm("nop");
|
||||
|
||||
TempRxID=TempRxMsg.id;
|
||||
_prv_vGetRxMsg(&TempRxMsg,&TempRxID ,TempRxBuffer,TempRxMsg.dlc);
|
||||
DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1);
|
||||
b_ServiceInt = true;
|
||||
DL_MCAN_getIntrStatus(CANFD0);
|
||||
if(HeaderStat.busOffStatus==1)
|
||||
{
|
||||
DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL);
|
||||
}
|
||||
|
||||
uint32_t u32RxCANID = 0;
|
||||
uint8_t u8RxData[8] = {0};
|
||||
|
||||
xMCAL_MCANRx(CANFD0,&u32RxCANID,u8RxData,8);
|
||||
|
||||
// vSOC_MeterCallback(u32RxCANID, &u8RxData[0]);
|
||||
mcu_FDCAN_RxFifo_Callback(u32RxCANID, &u8RxData[0], TempRxMsg.dlc);
|
||||
}
|
||||
else if(IntrStatus & MCAN_IR_PEA_MASK)
|
||||
{
|
||||
__asm("nop");
|
||||
DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1);
|
||||
|
||||
}
|
||||
else if(IntrStatus & MCAN_IR_BO_MASK)
|
||||
|
||||
{
|
||||
DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1);
|
||||
}
|
||||
//ErrorHandler();
|
||||
else{
|
||||
DL_MCAN_clearIntrStatus(CANFD0, IntrStatus,DL_MCAN_INTR_SRC_MCAN_LINE_1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*=============================================================================================================================================================================================
|
||||
API
|
||||
|
|
@ -447,9 +351,6 @@ void CANFD0_IRQHandler(void)
|
|||
*/
|
||||
IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD)
|
||||
{
|
||||
// DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM59, IOMUX_PINCM59_PF_CANFD0_CANTX); //ok
|
||||
// DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM60, IOMUX_PINCM60_PF_CANFD0_CANRX);
|
||||
|
||||
assert(MCAN == CANFD0);
|
||||
assert(BAUD == BAUD_500 || BAUD == BAUD_250);
|
||||
assert(b_MCAN_InitFlag == 0);
|
||||
|
|
@ -482,36 +383,33 @@ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD)
|
|||
/* Configure Bit timings. */
|
||||
if(BAUD==BAUD_500)
|
||||
{
|
||||
|
||||
DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_500);
|
||||
}
|
||||
else if(BAUD==BAUD_250)
|
||||
{
|
||||
DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_250);
|
||||
}
|
||||
else if(BAUD==BAUD_1000)
|
||||
{
|
||||
DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_1000);
|
||||
}
|
||||
else if(BAUD==BAUD_150)
|
||||
{
|
||||
DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_150);
|
||||
}
|
||||
// else if(BAUD==BAUD_125)
|
||||
// {
|
||||
// DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_125);
|
||||
// }
|
||||
else
|
||||
{
|
||||
DL_MCAN_setBitTime(MCAN, (DL_MCAN_BitTimingParams*) &gMCAN0BitTimes_500);
|
||||
}
|
||||
|
||||
/* Configure Message RAM Sections */
|
||||
DL_MCAN_msgRAMConfig(MCAN, (DL_MCAN_MsgRAMConfigParams*) &gMCAN0MsgRAMConfigParams);
|
||||
|
||||
// /* Configure Standard ID filter element */
|
||||
// DL_MCAN_addStdMsgIDFilter(MCAN, 0U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem);
|
||||
/* Configure Standard ID filter element */
|
||||
// DL_MCAN_addStdMsgIDFilter(MCAN, 0U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem1);
|
||||
//
|
||||
// DL_MCAN_addExtMsgIDFilter(MCAN, 0U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0ExtFilterElem);
|
||||
// DL_MCAN_addStdMsgIDFilter(MCAN, 1U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem2);
|
||||
//
|
||||
// DL_MCAN_addStdMsgIDFilter(MCAN, 2U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem3);
|
||||
//
|
||||
// DL_MCAN_addStdMsgIDFilter(MCAN, 3U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem4);
|
||||
//
|
||||
// DL_MCAN_addStdMsgIDFilter(MCAN, 4U, (DL_MCAN_StdMsgIDFilterElement *) &gMCAN0StdFiltelem5);
|
||||
//
|
||||
// DL_MCAN_addExtMsgIDFilter(MCAN, 0U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem1);
|
||||
//
|
||||
// DL_MCAN_addExtMsgIDFilter(MCAN, 1U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem2);
|
||||
//
|
||||
// DL_MCAN_addExtMsgIDFilter(MCAN, 2U,(DL_MCAN_ExtMsgIDFilterElement *)&gMCAN0ExtFiltelem3);
|
||||
|
||||
|
||||
/* Set Extended ID Mask. */
|
||||
|
|
@ -534,12 +432,22 @@ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD)
|
|||
DL_MCAN_INTERRUPT_TC | \
|
||||
DL_MCAN_INTERRUPT_TOO), 1U);
|
||||
|
||||
DL_MCAN_selectIntrLine(MCAN, DL_MCAN_INTR_MASK_ALL, DL_MCAN_INTR_LINE_NUM_1);
|
||||
DL_MCAN_selectIntrLine(MCAN, (DL_MCAN_INTERRUPT_BEU | \
|
||||
DL_MCAN_INTERRUPT_BO | \
|
||||
DL_MCAN_INTERRUPT_ELO | \
|
||||
DL_MCAN_INTERRUPT_EP | \
|
||||
DL_MCAN_INTERRUPT_EW | \
|
||||
DL_MCAN_INTERRUPT_PEA | \
|
||||
DL_MCAN_INTERRUPT_PED | \
|
||||
DL_MCAN_INTERRUPT_RF0N | \
|
||||
DL_MCAN_INTERRUPT_TC | \
|
||||
DL_MCAN_INTERRUPT_TOO), DL_MCAN_INTR_LINE_NUM_1);
|
||||
DL_MCAN_enableIntrLine(MCAN, DL_MCAN_INTR_LINE_NUM_1, 1U);
|
||||
|
||||
/* Enable MSPM0 MCAN interrupt */
|
||||
DL_MCAN_clearInterruptStatus(MCAN,(DL_MCAN_MSP_INTERRUPT_LINE1));
|
||||
DL_MCAN_enableInterrupt(MCAN,(DL_MCAN_MSP_INTERRUPT_LINE1));
|
||||
NVIC_SetPriority(CANFD0_INT_IRQn, 1);
|
||||
NVIC_EnableIRQ(CANFD0_INT_IRQn);
|
||||
b_MCAN_InitFlag = 1;
|
||||
|
||||
|
|
@ -553,70 +461,80 @@ IVEC_McalStatus_e xMCAL_MCANInit(MCAN_Regs* MCAN, xCAN_baud_t BAUD)
|
|||
* @param MCAN Pointer to the register overlay for the peripheral
|
||||
* @retval IVEC MCAL status
|
||||
*/
|
||||
|
||||
IVEC_McalStatus_e xMCAL_MCANDeInit(MCAN_Regs* MCAN)
|
||||
{
|
||||
assert(MCAN == CANFD0);
|
||||
assert(b_MCAN_InitFlag != 0); // Ensure the module was initialized before deinitializing.
|
||||
assert(b_MCAN_InitFlag != 0);
|
||||
|
||||
/* Disable MSPM0 MCAN interrupt */
|
||||
NVIC_DisableIRQ(CANFD0_INT_IRQn);
|
||||
DL_MCAN_disableInterrupt(MCAN, DL_MCAN_MSP_INTERRUPT_LINE1);
|
||||
|
||||
/* Put MCAN in SW initialization mode to stop it */
|
||||
DL_MCAN_setOpMode(MCAN, DL_MCAN_OPERATION_MODE_SW_INIT);
|
||||
|
||||
/* Wait till MCAN is in SW initialization mode */
|
||||
while (DL_MCAN_OPERATION_MODE_SW_INIT != DL_MCAN_getOpMode(MCAN));
|
||||
|
||||
/* Disable the MCAN clock */
|
||||
DL_MCAN_disableModuleClock(MCAN);
|
||||
|
||||
/* Clear initialization flag */
|
||||
DL_MCAN_disablePower(MCAN);
|
||||
b_MCAN_InitFlag = 0;
|
||||
|
||||
return IVEC_MCAL_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to Transmit CAN message
|
||||
* @param MCAN Pointer to the register overlay for the peripheral
|
||||
* @param TxMsg Message Object.
|
||||
* @param ID Message ID for TxMsg Object.
|
||||
* @param TxData Array of Data to be transmitted
|
||||
* @param BufNum Tx Buffer Number
|
||||
* @param Bytes Number of bytes to be transmitted
|
||||
* @retval IVEC_McalStatus_e
|
||||
*/
|
||||
IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, DL_MCAN_TxBufElement *TxMsg ,uint16_t *TxData, uint32_t BufNum, int Bytes)
|
||||
IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, uint32_t u32ID ,uint16_t *TxData, uint32_t BufNum, uint32_t Bytes)
|
||||
{
|
||||
// xMCAL_MCANTx(CANFD0,0x14FFFC23, timerTxData , 0, 8);
|
||||
|
||||
assert(MCAN == CANFD0);
|
||||
assert(b_MCAN_InitFlag != 0);
|
||||
assert(Bytes<=8);
|
||||
|
||||
if (u32ID>0x7FF){
|
||||
txMsg.xtd = 1;
|
||||
txMsg.id = u32ID;
|
||||
}
|
||||
else{
|
||||
txMsg.xtd = 0;
|
||||
txMsg.id = ((uint32_t)(u32ID)) << 18U;
|
||||
}
|
||||
|
||||
for(int i=0;i<Bytes;i++)
|
||||
{
|
||||
TxMsg->data[i] = TxData[i];
|
||||
txMsg.data[i]=TxData[i];
|
||||
}
|
||||
uint32_t txPendingStatus;
|
||||
|
||||
//Check if the Tx Buffer is available (no pending request)
|
||||
txPendingStatus = DL_MCAN_getTxBufReqPend(MCAN);
|
||||
// memcpy(txMsg.data,TxData,Bytes);
|
||||
__asm("nop");
|
||||
|
||||
DL_MCAN_writeMsgRam(MCAN, DL_MCAN_MEM_TYPE_BUF, BufNum , &txMsg);
|
||||
|
||||
DL_MCAN_TXBufTransIntrEnable(MCAN, BufNum, 1U);
|
||||
|
||||
//Check if the specified buffer (BufNum) is available
|
||||
if ((txPendingStatus & (1 << BufNum)) == 0)
|
||||
{
|
||||
DL_MCAN_writeMsgRam(MCAN, DL_MCAN_MEM_TYPE_BUF, BufNum , TxMsg);
|
||||
DL_MCAN_TXBufAddReq(MCAN, BufNum);
|
||||
|
||||
l_canTransmitTimeout = i32MCAL_getTicks();
|
||||
u8_MCAN_StatusFlag = IVEC_MCAL_STATUS_BUSY;
|
||||
|
||||
while(1){
|
||||
|
||||
if (u8_MCAN_StatusFlag == IVEC_MCAL_STATUS_SUCCESS || u8_MCAN_StatusFlag == IVEC_MCAL_STATUS_ERROR){
|
||||
__asm("nop");
|
||||
return u8_MCAN_StatusFlag;
|
||||
}
|
||||
else
|
||||
else if((i32MCAL_getTicks() - l_canTransmitTimeout) > 2){
|
||||
__asm("nop");
|
||||
return IVEC_MCAL_STATUS_TIMEOUT;
|
||||
}
|
||||
}
|
||||
if(HeaderStat.busOffStatus==1)
|
||||
{
|
||||
//printf("tx pending\n");
|
||||
//return IVEC_MCAL_STATUS_BUSY;
|
||||
|
||||
DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
b_ServiceInt = true;
|
||||
return IVEC_MCAL_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -629,32 +547,33 @@ IVEC_McalStatus_e xMCAL_MCANTx(MCAN_Regs *MCAN, DL_MCAN_TxBufElement *TxMsg ,uin
|
|||
* @param DLC length of received data
|
||||
* @retval IVEC_McalStatus_e
|
||||
*/
|
||||
IVEC_McalStatus_e xMCAL_MCANRx(MCAN_Regs *MCAN, DL_MCAN_RxBufElement *RxMsg ,uint32_t FifoNum,uint8_t *RxData,int DLC)
|
||||
IVEC_McalStatus_e xMCAL_MCANRx(MCAN_Regs *MCAN,uint32_t *ID ,uint8_t *RxData, int DLC)
|
||||
{
|
||||
assert(MCAN == CANFD0);
|
||||
assert(b_MCAN_InitFlag != 0);
|
||||
|
||||
while (false == b_ServiceInt)
|
||||
if(HeaderStat.busOffStatus==1)
|
||||
{
|
||||
__WFE();//__asm("nop");
|
||||
DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL);
|
||||
}
|
||||
|
||||
b_ServiceInt = false;
|
||||
rxFS.fillLvl = 0;
|
||||
|
||||
if ((u32InterruptLine1Status & MCAN_IR_RF0N_MASK) == MCAN_IR_RF0N_MASK)
|
||||
if((((TempRxID&0xFFF)>>1)==0x16))
|
||||
{
|
||||
rxFS.num = DL_MCAN_RX_FIFO_NUM_0;
|
||||
while ((rxFS.fillLvl) == 0)
|
||||
{
|
||||
DL_MCAN_getRxFIFOStatus(MCAN, &rxFS);
|
||||
xMCAL_SoftReset();
|
||||
}
|
||||
DL_MCAN_readMsgRam(MCAN, DL_MCAN_MEM_TYPE_FIFO, FifoNum, rxFS.num, RxMsg);
|
||||
DL_MCAN_writeRxFIFOAck(MCAN, rxFS.num, rxFS.getIdx);
|
||||
_prv_vGetRxMsg(RxMsg,RxData,DLC);
|
||||
u32InterruptLine1Status &= ~(MCAN_IR_RF0N_MASK);
|
||||
if((((TempRxID&0xFFF)>>1)==0x1AE)||(((TempRxID&0xFFF)>>1)==0x520)||(((TempRxID&0xFFF)>>1)==0xBB)||(((TempRxID&0xFFF)>>1)==0x1A4)||(((TempRxID&0xFFF)>>1)==0x521))//TODO: CHANGE ID CHECKS AFTER UPDATED CAN MATRIX
|
||||
{
|
||||
*ID=((TempRxID&0xFFF)>>1);
|
||||
}
|
||||
else
|
||||
{
|
||||
*ID=TempRxID;
|
||||
}
|
||||
|
||||
for(int i=0;i<DLC;i++)
|
||||
{
|
||||
RxData[i]=TempRxMsg.data[i];
|
||||
}
|
||||
|
||||
return IVEC_MCAL_STATUS_SUCCESS;
|
||||
}
|
||||
|
|
@ -680,11 +599,25 @@ IVEC_McalStatus_e xMCAL_getMCAN_ErrorStatus(char *ErrorStatus)
|
|||
*/
|
||||
IVEC_McalStatus_e xMCAL_getMCAN_InterruptLine1Status(uint32_t *Interrupt_Status)
|
||||
{
|
||||
assert(b_MCAN_InitFlag != 0);
|
||||
// assert(b_MCAN_InitFlag != 0);
|
||||
|
||||
*Interrupt_Status=u32InterruptLine1Status;
|
||||
|
||||
return IVEC_MCAL_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
IVEC_McalStatus_e xMCAL_resetMCAN(MCAN_Regs* const mcan, xCAN_baud_t BAUD)
|
||||
{
|
||||
assert(b_MCAN_InitFlag != 0);
|
||||
assert(mcan == CANFD0);
|
||||
|
||||
//DL_MCAN_reset(CANFD0);
|
||||
xMCAL_MCANDeInit(mcan);
|
||||
xMCAL_MCANInit(mcan,BAUD);
|
||||
|
||||
return IVEC_MCAL_STATUS_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*____________________________________________________________________________________________________________________________________________________________________________________________*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "../Core/Include/ivec_mcal_uart.h"
|
||||
#include "string.h"
|
||||
#include "../../utils/utils.h"
|
||||
//#include "ivec_mcal_uart.h"
|
||||
#define LOG_STRING "ivec-mcal-uart"
|
||||
|
||||
|
|
@ -203,7 +204,8 @@ static xCoreStatus_t uart_read(McalUartHandle_s* pxUartHandle, unsigned char* pu
|
|||
}
|
||||
|
||||
bool status = false;
|
||||
while (!DL_UART_Main_isRXFIFOEmpty(uart_inst)) {
|
||||
uint32_t l_u32Tick = i32MCAL_getTicks();
|
||||
while (!DL_UART_Main_isRXFIFOEmpty(uart_inst) && ((i32MCAL_getTicks() - l_u32Tick) < 50)) {
|
||||
*pucData = DL_UART_Main_receiveData(uart_inst);
|
||||
status = true;
|
||||
}
|
||||
|
|
@ -270,14 +272,11 @@ static xCoreStatus_t uart_transmit(McalUartHandle_s* pxUartHandle, uint8_t *u8tx
|
|||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
|
||||
uint32_t l_u32Tick = i32MCAL_getTicks();
|
||||
for(int j=0; j<u32size; j++)
|
||||
{
|
||||
|
||||
DL_UART_transmitData(uart_inst,u8txdata[j]);
|
||||
//DL_UART_transmitDataBlocking(uart_inst, u8txdata[j]);
|
||||
//while (DL_UART_isBusy(uart_inst));
|
||||
while(DL_UART_Main_isBusy(uart_inst));
|
||||
while(DL_UART_Main_isBusy(uart_inst) && ((i32MCAL_getTicks() - l_u32Tick) < 10));
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -210,7 +210,7 @@ TM1650_Status_T tm1650_showNum(TM_1650_Digit_t digit, uint8_t num)
|
|||
retVal = TM1650_SendByte(&tm1650_drv, digit);
|
||||
if(retVal == 0)
|
||||
{
|
||||
retVal = TM1650_SendByte(&tm1650_drv, numericDisplayArray[num] | digitDot[(digit - TM_1650_DIG_1)/2] );
|
||||
retVal = TM1650_SendByte(&tm1650_drv, numericDisplayArray[num]);
|
||||
}
|
||||
// | digitDot[(digit - TM_1650_DIG_1)/2]
|
||||
TM1650_End(&tm1650_drv);
|
||||
|
|
|
|||
|
|
@ -17,12 +17,10 @@ void mcu_FDCAN_RxFifo_Callback(uint32_t Identifier, uint8_t *data, uint16_t Data
|
|||
uint8_t store_msg_from_isr_to_queue(uint32_t id, uint8_t* data, uint8_t len)
|
||||
{
|
||||
can_buff_t buff = {0};
|
||||
//printf("id %d\n",id);
|
||||
buff.id = id;
|
||||
buff.length = len;
|
||||
memcpy(buff.data, data, len);
|
||||
ENQUEUE(g_canQueue, buff);
|
||||
//printf("enqueue id after enqueue %d\n",buff.id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -57,23 +55,13 @@ IVEC_EcuCommonErr_e xECU_WriteDataOverCAN(uint8_t* pucBuf, uint32_t ulId, int re
|
|||
xFrame.mm = 0xAAU;
|
||||
|
||||
uint16_t TxData[DL_MCAN_MAX_PAYLOAD_BYTES]; // Define a buffer for the CAN payload data
|
||||
//
|
||||
// // Copy the data you want to transmit (from pucBuf) into TxData
|
||||
// //memcpy(TxData, &pucBuf[PKT_HEADER], retCode);
|
||||
//
|
||||
// Loop through pucBuf starting at PKT_HEADER and XOR each byte with 0x0000
|
||||
for (int i = 0; i < retCode; i++) {
|
||||
TxData[i] = pucBuf[PKT_HEADER + i]^0x0000;
|
||||
}
|
||||
|
||||
|
||||
// Set up the buffer number
|
||||
//uint32_t BufNum = 0; // Example: Use buffer number 0
|
||||
|
||||
// Number of bytes to transmit (retCode holds DLC)
|
||||
int Bytes = retCode;
|
||||
//printf("bufnum %d\n",BufNum);
|
||||
l_i32Ret = xMCAL_MCANTx(CANFD0, &xFrame, TxData, BufNum, Bytes);
|
||||
l_i32Ret = xMCAL_MCANTx(CANFD0, xFrame.id, TxData, BufNum, Bytes);
|
||||
if(l_i32Ret == IVEC_MCAL_STATUS_SUCCESS)
|
||||
{
|
||||
l_xFuncStatus = commonECU_SUCCESS;
|
||||
|
|
@ -92,10 +80,7 @@ IVEC_EcuCommonErr_e xECU_CANGetData(can_buff_t *pxBuff)
|
|||
|
||||
can_buff_t xBuff = { 0x00 };
|
||||
DEQUEUE(g_canQueue, xBuff);
|
||||
//printf("dequeue id %d\n",xBuff.id);
|
||||
memcpy(pxBuff,&xBuff,sizeof(can_buff_t));
|
||||
// printf("dequeue id after memcpy %d\n",pxBuff->id);
|
||||
// printf("ID received dequeue %d\n",xBuff.id);
|
||||
l_xFuncStatus = commonECU_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,24 +6,14 @@
|
|||
|
||||
#define LOG_STRING "ivec-ecu-UART"
|
||||
#define CAN_UART_BUFFER_MAX_SIZE 2048
|
||||
|
||||
|
||||
volatile uint8_t g_TxCplt;
|
||||
static uint8_t g_prv_u8CANUartDataBuffer[CAN_UART_BUFFER_MAX_SIZE];
|
||||
|
||||
#define DATA_PACKET_TIMEOUT 100
|
||||
|
||||
CmplxFifoQueueHandle_s __gprv_MyEcuUARTResponseQueue = { 0 };
|
||||
|
||||
static uint32_t g_prv_u32CanUartDataAvailable = 0;
|
||||
uint8_t QueueBuffer[100];
|
||||
static uint8_t __gprv_u8CANUartDataBuffer[CAN_UART_BUFFER_MAX_SIZE];
|
||||
static uint32_t __gprv_u32CanUartDataAvailable = 0;
|
||||
|
||||
#define DATA_PACKET_TIMEOUT 300
|
||||
|
||||
//McalUartHandle_s prvUartHandle;
|
||||
//#define SIZE 12U
|
||||
//uint8_t u8txdata[SIZE]="Hello World";
|
||||
//uint32_t u32data_size=sizeof(u8txdata);
|
||||
uint8_t u8rxdata;
|
||||
|
||||
// Get the UART instance based on the enum
|
||||
static UART_Regs* GetUartInstance(McalUartPortNumber_e eUartPortNumber)
|
||||
|
|
@ -43,15 +33,10 @@ static UART_Regs* GetUartInstance(McalUartPortNumber_e eUartPortNumber)
|
|||
|
||||
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) )
|
||||
g_prv_u32CanUartDataAvailable += u32Size;
|
||||
__gprv_u32CanUartDataAvailable += u32Size;
|
||||
}
|
||||
|
||||
// IVEC_EcuCANHandle_s* l_xTempHandle = __prvECU_CANGetHandle(IVEC_ECU_CAN_EXTERNAL);
|
||||
// if (l_xTempHandle != NULL)
|
||||
|
||||
}
|
||||
|
||||
static void prvChecksumCalculate(uint8_t* pkt, int len, uint8_t *ck) {
|
||||
|
|
@ -76,8 +61,8 @@ IVEC_EcuCommonErr_e xECU_UARTInit(McalUartHandle_s* prvUartHandle, uint32_t spee
|
|||
|
||||
IVEC_ECU_LOG(LOG_STRING, "UART Initilising Queue");
|
||||
__gprv_MyEcuUARTResponseQueue.i32ElementSize = sizeof(uint8_t);
|
||||
__gprv_MyEcuUARTResponseQueue.i32TotalElements = 100;
|
||||
__gprv_MyEcuUARTResponseQueue.pu8Buffer = (uint8_t*)QueueBuffer;
|
||||
__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)
|
||||
|
|
@ -186,8 +171,6 @@ IVEC_EcuCommonErr_e xECU_UARTGetData(McalUartHandle_s *prvUartHandle, uint8_t* p
|
|||
}
|
||||
}
|
||||
|
||||
//xMCAL_TimerstopCounter(); // Stop the timer
|
||||
|
||||
if (ijk != len)
|
||||
{
|
||||
l_xFuncStatus = commonECU_READ_FAIL;
|
||||
|
|
|
|||
|
|
@ -69,11 +69,6 @@ uint8_t mcu_tempDataReadPin(void){
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* #define TOUCH_BUTTON_PORT (GPIOB)
|
||||
#define TOUCH_BUTTON_PIN_17_PIN (DL_GPIO_PIN_17)
|
||||
#define TOUCH_BUTTON_PIN_17_IOMUX (IOMUX_PINCM43)
|
||||
*/
|
||||
void vRTE_MatlabInit(void)
|
||||
{
|
||||
u8MCAL_gpioInit();
|
||||
|
|
@ -102,18 +97,18 @@ void vRTE_MatlabRun(void)
|
|||
tm1650_displaySwitch(TM_1650_Screen_ON);
|
||||
tm1650_showDot(TM_1650_DIG_1,false);
|
||||
tm1650_showDot(TM_1650_DIG_2,false);
|
||||
// tm1650_showDot(TM_1650_DIG_3,false);
|
||||
tm1650_showDot(TM_1650_DIG_3,false);
|
||||
|
||||
tm1650_showNum(TM_1650_DIG_3, socTouchDisplay_Y.op_u8OnesPlace);
|
||||
tm1650_showNum(TM_1650_DIG_2, socTouchDisplay_Y.op_u8TensPlace);
|
||||
// tm1650_showNum(TM_1650_DIG_1, socTouchDisplay_Y.op_u8HundredsPlace);
|
||||
tm1650_showNum(TM_1650_DIG_1, socTouchDisplay_Y.op_u8HundredsPlace);
|
||||
}
|
||||
if( socTouchDisplay_Y.op_bErrorStatus )
|
||||
{
|
||||
tm1650_displaySwitch(TM_1650_Screen_ON);
|
||||
tm1650_showDot(TM_1650_DIG_1,false);
|
||||
tm1650_showDot(TM_1650_DIG_2,false);
|
||||
// tm1650_showDot(TM_1650_DIG_3,false);
|
||||
tm1650_showDot(TM_1650_DIG_3,false);
|
||||
|
||||
char l_cData = 'R';
|
||||
l_cData = 'C';
|
||||
|
|
@ -145,26 +140,30 @@ void vRTE_UARTDataProcess(void)
|
|||
retCode= xECU_ReadCANDataOverUART(&g_xUartHandle,pucBuf,&ulId);
|
||||
if(retCode > -1)
|
||||
{
|
||||
if(ulId == 0x00)
|
||||
if(retCode > 0 && ulId == 0x00)
|
||||
{
|
||||
//vECU_InitiateUartToCanTransmit(&g_xUartHandle, ulId, pucBuf, 0);
|
||||
|
||||
uint32_t baudrate = 0;
|
||||
uint8_t mode = pucBuf[PKT_HEADER];
|
||||
memcpy(&baudrate, &pucBuf[PKT_HEADER+1], (uint32_t)retCode);
|
||||
vECU_InitiateUartToCanTransmit(&g_xUartHandle, ulId, pucBuf, 0);
|
||||
vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x01, pucBuf, 0);
|
||||
if( mode == 0 )
|
||||
{
|
||||
g_u32UartSpeed = baudrate;
|
||||
xECU_UARTReInit(&g_xUartHandle, g_u32UartSpeed);
|
||||
// xECU_UARTReInit(&g_xUartHandle, g_u32UartSpeed);
|
||||
}
|
||||
else if( mode == 1 )
|
||||
{
|
||||
g_u16CanSpeed = (uint16_t)baudrate;
|
||||
xECU_CanReInit(CANFD0, g_u16CanSpeed);
|
||||
// xECU_CanReInit(CANFD0, g_u16CanSpeed);
|
||||
}
|
||||
vMCAL_DelayTicks(100);
|
||||
vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x01, pucBuf, 0);
|
||||
}
|
||||
else{
|
||||
if ( retCode == 0 && ulId == 0){
|
||||
vECU_InitiateUartToCanTransmit(&g_xUartHandle, 0x0, pucBuf, 0);
|
||||
}
|
||||
if ( retCode >= 0 && ulId > 0x00 && ulId < 0xffffffff )
|
||||
{
|
||||
xECU_WriteDataOverCAN(pucBuf, ulId, retCode, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,4 +258,7 @@ IVEC_McalStatus_e xMCAL_VrefInit(void)
|
|||
return IVEC_MCAL_STATUS_INIT_FAIL;
|
||||
}
|
||||
|
||||
|
||||
void xMCAL_SoftReset(void)
|
||||
{
|
||||
DL_SYSCTL_resetDevice(DL_SYSCTL_RESET_CPU);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ xCoreStatus_t xMCAL_SYSTICK_INIT(xTicks_t tick);
|
|||
int i32MCAL_getTicks();
|
||||
void vMCAL_DelayTicks(int i32Delay_ms);
|
||||
|
||||
|
||||
void xMCAL_SoftReset(void);
|
||||
void xMCAL_McuInit(void);
|
||||
void delay (uint32_t us);
|
||||
IVEC_McalStatus_e xMCAL_VrefInit(void);
|
||||
|
|
|
|||
Loading…
Reference in New Issue