optical/NxBase/canctrl.h
2025-09-04 09:45:08 +08:00

88 lines
1.5 KiB
C

#ifndef __CANCTRL_H__
#define __CANCTRL_H__
#include "config.h"
#if (COMM_CAN != 0)
#include "can.h"
//---------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
#ifndef HCAN
#define HCAN hcan
#endif
//-------------------------------------------------------------------------------
#ifndef CAN_DATA_LEN
#define CAN_DATA_LEN 8
#endif
#ifndef RESV_PKT_LIST_NUM
#define RESV_PKT_LIST_NUM 16
#endif
#ifndef TRANS_PKT_LIST_NUM
#define TRANS_PKT_LIST_NUM 16
#endif
typedef struct
{
CAN_TxHeaderTypeDef canTxhead;
u8 data[CAN_DATA_LEN];
}CanTxMsg;
typedef struct
{
CAN_RxHeaderTypeDef canRxhead;
u8 data[8];
}CanRxMsg;
typedef struct
{
CanRxMsg pktRxList[RESV_PKT_LIST_NUM]; // 接收缓冲区
CanRxMsg * pktRxListHead; // 头指针
CanRxMsg * pktRxListTail; // 尾指针
int pktRxNumber; // 有效个数
}CanRxCtrl;
typedef struct
{
CanTxMsg pktTxList[TRANS_PKT_LIST_NUM]; // 发送缓冲区
CanTxMsg * pktTxListHead; // 头指针
CanTxMsg * pktTxListTail; // 尾指针
int pktTxNumber; // 有效个数
int sendingFlag; // 发送标志
}CanTxCtrl;
//---------------------------------------------------------------------------------------------
void InitCanCtrl(void);
void DefaultCanFilter(u8 fifo);
void RegistFilter(void*func);
int SendACANDataPacket(CanTxMsg * pMsg);
int GetACanDataPacket(CanRxMsg * pMsg);
//---------------------------------------------------------------------------------------------
#endif
#endif