99 lines
2.5 KiB
C
99 lines
2.5 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"
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
CAN_BAUD_RATE_1000K,
|
|
CAN_BAUD_RATE_500K,
|
|
CAN_BAUD_RATE_250K,
|
|
CAN_BAUD_RATE_125K
|
|
} eCanBaudRate;
|
|
|
|
typedef enum {
|
|
CAN_STD_ID,
|
|
CAN_EXT_ID
|
|
} eCanTypeFrame;
|
|
|
|
#define COUNT_QUEUE 2
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t u16CanId; /**< FLEXCAN id */
|
|
uint8_t u8DataLen; /**< data length */
|
|
uint8_t aData[8]; /**< data buffer */
|
|
|
|
} can_rx_message_type;
|
|
|
|
typedef struct {
|
|
|
|
FLEXCAN_Type *can;
|
|
|
|
uint8_t CAN_INDEX;
|
|
|
|
uint32_t id;
|
|
uint32_t id1;
|
|
eCanTypeFrame canTypeFrame;
|
|
bool canFilterEnable;
|
|
|
|
bool reInit;
|
|
|
|
eCanBaudRate canBaudRate;
|
|
|
|
FLEXCAN_RxMbFilterType aRxFiltList[COUNT_QUEUE];
|
|
FLEXCAN_RxMbFilterType pRxFilterFifoList[COUNT_QUEUE];
|
|
|
|
osMessageQueueId_t rxDataQueue[COUNT_QUEUE];
|
|
osMessageQueueId_t rxDataSnifferQueue[COUNT_QUEUE];
|
|
|
|
osMessageQueueId_t txAccessQueue;
|
|
|
|
} tCanSerialPortFrameFlagchip;
|
|
|
|
|
|
|
|
void vCanSerialPortFrameInit(
|
|
tCanSerialPortFrameFlagchip *env,
|
|
|
|
|
|
FLEXCAN_Type *CANx, // FLEXCAN0
|
|
PCC_ClkSrcType canClock, // PCC_CLK_FLEXCAN0
|
|
uint8 CAN_INDEX, // CAN0 = 0 ... CAN3 = 3
|
|
|
|
eCanBaudRate canBaudRate,
|
|
uint8_t irqSubPriority,
|
|
eCanTypeFrame 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 CAN_RxInterrupt_CallBack_Handler(tCanSerialPortFrameFlagchip *env, uint8_t u8CanIndex, FLEXCAN_RxMsgType *pRxCfg);
|
|
|
|
void CanSerialPortFrameSetId(tCanSerialPortFrameFlagchip *env, uint32_t id);
|
|
void CanSerialPortFrameSetId1(tCanSerialPortFrameFlagchip *env, uint32_t id);
|
|
void CanSerialPortFrameSetType(tCanSerialPortFrameFlagchip *env, eCanTypeFrame canTypeFrame);
|
|
tSerialPortFrameIO CanPortFrame_GetIo(tCanSerialPortFrameFlagchip *env);
|
|
tSerialPortFrameIO CanPortFrame_GetSnifferIo(tCanSerialPortFrameFlagchip *env);
|
|
|
|
#endif //FLAGCHIP_CAN_MODULE_CAN_FRAME_H
|