bs_bcu_app/drv/drv_stm32f4xx/drv_can.h

94 lines
1.6 KiB
C

#ifndef _DRV_CAN_H_
#define _DRV_CAN_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "kit_macro.h"
#define CAN_DATA_LEN (8u)
typedef enum
{
kCanDev_1,
#if defined(STM32F10X_CL) || defined(STM32F40_41xxx) || defined(STM32F429_439xx)
kCanDev_2,
#endif
kCanDev_End,
}CanDev;
typedef enum
{
kCanInterrupt_Rx = 0,
kCanInterrupt_Tx,
kCanInterrupt_End,
}CanInterrupt;
typedef enum
{
kCanIde_Std = 0,
kCanIde_Ext,
kCanIde_End,
} CanIde;
//1远程帧 0数据帧
typedef enum
{
kCanRtr_Data = 0,
kCanRtr_Remote,
kCanRtr_End,
}CanRtr;
typedef enum
{
kCanFilter_Mask,
kCanFilter_List,
kCanFilter_End,
}CanFilter;
typedef union
{
uint32_t value;
struct
{
uint8_t b0;
uint8_t b1;
uint8_t b2;
uint8_t b3;
}b;
}CanId;
typedef union
{
uint8_t byte[CAN_DATA_LEN];
uint32_t value[2];
}CanData;
typedef struct
{
CanId id;
uint8_t len;
CanIde ide; //标示符类型
CanRtr rtr; //远程数据类型
CanData data;
}CanMsg;
KitResult drv_can_init(CanDev dev, uint32_t baud_rate, uint16_t rx_idx, uint16_t tx_idx);
KitResult drv_can_send(CanDev dev, CanMsg *msg);
KitResult drv_can_receive(CanDev dev, CanMsg *msg);
uint8_t drv_can_get_mailbox(CanDev dev);
KitResult drv_can_set_interrupt(CanDev dev, CanInterrupt it_type, uint16_t priority, KitIrqCall call);
KitResult drv_can_set_filter(uint8_t channel, CanFilter mode, CanIde ide, uint32_t rcv_id, uint32_t mask_id);
KitResult drv_can_ctrl_interrupt(CanDev dev, CanInterrupt it_type, bool is_enable);
#ifdef __cplusplus
}
#endif
#endif