137 lines
4.2 KiB
C
137 lines
4.2 KiB
C
//
|
|
// Created by cfif on 16.03.2024.
|
|
//
|
|
|
|
#ifndef FLAGCHIP_CAN_MODULE_CAN_FRAME_H
|
|
#define FLAGCHIP_CAN_MODULE_CAN_FRAME_H
|
|
|
|
#include "SerialPortFrameIO.h"
|
|
#include "cmsis_os2.h"
|
|
#include "stdbool.h"
|
|
|
|
|
|
#include "device_header.h"
|
|
#include "interrupt_manager.h"
|
|
|
|
#include "fc7xxx_driver_flexcan.h"
|
|
#include "fc7xxx_driver_pcc.h"
|
|
#include "fc7xxx_driver_dma.h"
|
|
|
|
|
|
typedef struct
|
|
{
|
|
uint32_t standard_id; /*!< specifies the 11 bits standard identifier
|
|
this parameter can be a value between 0 to 0x7FF. */
|
|
|
|
uint32_t extended_id; /*!< specifies the 29 bits extended identifier.
|
|
this parameter can be a value between 0 to 0x1FFFFFFF. */
|
|
|
|
FLEXCAN_IdType id_type; /*!< specifies identifier type for the receive message.*/
|
|
|
|
FLEXCAN_DataType frame_type; /*!< specifies frame type for the receive message.*/
|
|
|
|
uint8_t dlc; /*!< specifies the frame data length that will be received.
|
|
this parameter can be a value between 0 to 8 */
|
|
|
|
uint8_t data[8]; /*!< contains the receive data. it ranges from 0 to 0xFF.*/
|
|
|
|
uint8_t filter_index; /*!< specifies the message stored in which filter
|
|
this parameter can be a value between 0 to 0xFF */
|
|
} can_rx_message_type;
|
|
|
|
|
|
#define COUNT_QUEUE 2
|
|
|
|
typedef struct {
|
|
|
|
FLEXCAN_Type *can;
|
|
|
|
uint8_t CAN_INDEX;
|
|
|
|
uint32_t id;
|
|
uint32_t id1;
|
|
FLEXCAN_IdType canTypeFrame;
|
|
bool canFilterEnable;
|
|
|
|
bool reInit;
|
|
|
|
FLEXCAN_BaudType canBaudRate;
|
|
|
|
uint32_t g_u32RxDataIndex;
|
|
|
|
FLEXCAN_RxMbFilterType aRxFiltList[COUNT_QUEUE];
|
|
FLEXCAN_RxMbFilterType pRxFilterFifoList[COUNT_QUEUE];
|
|
|
|
osMessageQueueId_t rxDataQueue;
|
|
osMessageQueueId_t rxDataSnifferQueue;
|
|
|
|
osMessageQueueId_t txAccessQueue;
|
|
|
|
FLEXCAN_InitType tInitCfg;
|
|
FLEXCAN_MBConfigType tMbCfg;
|
|
FLEXCAN_InterruptType tIntCfg;
|
|
|
|
} tCanSerialPortFrameFlagchip;
|
|
|
|
|
|
|
|
void vCanSerialPortFrameInit(
|
|
tCanSerialPortFrameFlagchip *env,
|
|
|
|
|
|
FLEXCAN_Type *CANx, // FLEXCAN0
|
|
uint8 CAN_INDEX, // CAN0 = 0 ... CAN3 = 3
|
|
IRQn_Type IRQ_CAN, // FlexCAN0_IRQn ... FlexCAN3_IRQn
|
|
uint8 CAN_PRIORITY,
|
|
|
|
FLEXCAN_BaudType canBaudRate,
|
|
FLEXCAN_IdType canTypeFrame,
|
|
uint32_t canId,
|
|
FLEXCAN_ErrorInterruptCallBackType CAN_ErrorInterrupt_CallBack,
|
|
FLEXCAN_RxInterruptCallBackType CAN_RxInterrupt_CallBack,
|
|
FLEXCAN_RxInterruptCallBackType CAN_RxFifoInterrupt_CallBack,
|
|
FLEXCAN_TxInterruptCallBackType CAN_TxInterrupt_CallBack
|
|
|
|
);
|
|
|
|
void vCanSerialPortFrameDMAInit(
|
|
tCanSerialPortFrameFlagchip *env,
|
|
|
|
FLEXCAN_Type *CANx, // FLEXCAN0
|
|
uint8 CAN_INDEX, // CAN0 = 0 ... CAN3 = 3
|
|
|
|
IRQn_Type IRQ_CAN, // FlexCAN0_IRQn ... FlexCAN3_IRQn
|
|
uint8 CAN_PRIORITY,
|
|
|
|
DMA_ChannelType RX_DMA_CHANNEL,
|
|
DMA_RequestSourceType RX_DMA_CHANNEL_REQ, // DMA_REQ_FLEXCAN0
|
|
|
|
uint8_t *DMA_BUF,
|
|
|
|
IRQn_Type IRQ_DMA,
|
|
uint8_t IRQ_DMA_PRIORITY,
|
|
uint8_t IRQ_DMA_CHANNEL_PRIORITY,
|
|
|
|
FLEXCAN_BaudType canBaudRate,
|
|
FLEXCAN_IdType canTypeFrame,
|
|
uint32_t canId,
|
|
FLEXCAN_ErrorInterruptCallBackType CAN_ErrorInterrupt_CallBack,
|
|
FLEXCAN_RxInterruptCallBackType CAN_RxInterrupt_CallBack,
|
|
FLEXCAN_RxInterruptCallBackType CAN_RxFifoInterrupt_CallBack,
|
|
FLEXCAN_TxInterruptCallBackType CAN_TxInterrupt_CallBack,
|
|
|
|
DMA_TransferCompleteCallbackType DMA_TransferCompleteCallback,
|
|
DMA_TransferErrorCallbackType DMA_ErrorCallback
|
|
);
|
|
|
|
void CAN_RxInterrupt_CallBack_Handler(tCanSerialPortFrameFlagchip *env, uint8_t u8CanIndex, FLEXCAN_RxMsgType *pRxCfg);
|
|
|
|
void CanSerialPortFrameIrqRxProcessing(tCanSerialPortFrameFlagchip *env, uint32_t *pBuf);
|
|
|
|
void CanSerialPortFrameSetId(tCanSerialPortFrameFlagchip *env, uint32_t id);
|
|
void CanSerialPortFrameSetType(tCanSerialPortFrameFlagchip *env, FLEXCAN_IdType canTypeFrame);
|
|
tSerialPortFrameIO CanPortFrame_GetIo(tCanSerialPortFrameFlagchip *env);
|
|
tSerialPortFrameIO CanPortFrame_GetSnifferIo(tCanSerialPortFrameFlagchip *env);
|
|
|
|
#endif //FLAGCHIP_CAN_MODULE_CAN_FRAME_H
|