hal_can_frame_t hal_can_frame;
flexcan_fd_frame_t CANFDframe;
flexcan_mb_transfer_t CANFDtxXfer;
flexcan_mb_transfer_t CANFDrxXfer;
int main(void)
{
hal_can_param_t param;
static uint8_t CANFDSendCount;
// memset(&CANFDframe,0,sizeof(flexcan_fd_frame_t));
uint8_t ebuff[10]={0x01,0x02,0x03,0x04,0x00,0x05,0x06,0x07,0x08,0x09};
/* Initialize board hardware. */
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
//CAN过滤ID
PRINTF("-------INT start-------");
// }
//init函数
#if 0
HAL_CANInit(instance,¶m);
#else
FLEXCAN_GetDefaultConfig(&flexcanConfig);
flexcanConfig.clksrc=kFLEXCAN_ClkSrcPeri;
flexcan_timing_config_t timing_config;
memset(&timing_config, 0, sizeof(flexcan_timing_config_t));
if (FLEXCAN_FDCalculateImprovedTimingValues(flexcanConfig.baudRate, flexcanConfig.baudRateFD, EXAMPLE_CAN_CLK_FREQ,
&timing_config))
{
/* Update the improved timing configuration*/
memcpy(&(flexcanConfig.timingConfig), &timing_config, sizeof(flexcan_timing_config_t));
}
else
{
PRINTF("No found Improved Timing Configuration. Just used default configuration\r\n\r\n");
}
FLEXCAN_FDInit(EXAMPLE_CAN, &flexcanConfig, EXAMPLE_CAN_CLK_FREQ, BYTES_IN_MB, true);
FLEXCAN_TransferCreateHandle(EXAMPLE_CAN, &flexcanHandle, flexcan_callback, NULL);
FLEXCAN_SetRxMbGlobalMask(EXAMPLE_CAN, FLEXCAN_RX_MB_STD_MASK(0x123, 0, 0));
mbConfig.format = kFLEXCAN_FrameFormatStandard;
mbConfig.type = kFLEXCAN_FrameTypeData;
mbConfig.id = FLEXCAN_ID_STD(0x123);
FLEXCAN_SetFDRxMbConfig(EXAMPLE_CAN, RX_MESSAGE_BUFFER_NUM, &mbConfig, true);
FLEXCAN_SetFDTxMbConfig(EXAMPLE_CAN, TX_MESSAGE_BUFFER_NUM, true);
#endif
while(1)
{
// if((param.isEnableCANFD == true))
// {
CANFDframe.id = FLEXCAN_ID_STD(0x321);
CANFDframe.format = kFLEXCAN_FrameFormatStandard;
CANFDframe.type = kFLEXCAN_FrameTypeData;
CANFDframe.length = 10;
CANFDframe.brs = 1;
CANFDtxXfer.mbIdx = TX_MESSAGE_BUFFER_NUM;
CANFDtxXfer.framefd = &CANFDframe;
// FLEXCAN_TransferFDSendBlocking(EXAMPLE_CAN,TX_MESSAGE_BUFFER_NUM,&CANFDframe);
FLEXCAN_TransferFDSendNonBlocking(EXAMPLE_CAN, &flexcanHandle, &CANFDtxXfer);
CANFDSendCount++;
while (!txComplete)
{
};
txComplete = false;
CANFDrxXfer.mbIdx = RX_MESSAGE_BUFFER_NUM;
CANFDrxXfer.framefd = &CANFDframe;
while (!rxComplete)
{
FLEXCAN_TransferFDReceiveNonBlocking(EXAMPLE_CAN, &flexcanHandle, &CANFDrxXfer);
};
rxComplete = false;
PRINTF("Rx MB ID: 0x%3x, Rx MB data: 0x%x, Time stamp: %d\r\n", CANFDframe.id >> CAN_ID_STD_SHIFT,CANFDframe.dataByte0, CANFDframe.timestamp);
// }
}
}