Files
motor-controller/interfaces/can/can_if.h
2026-04-18 11:02:40 +08:00

29 lines
769 B
C

#ifndef CAN_IF_H
#define CAN_IF_H
#include <stdint.h>
typedef struct {
uint32_t id; // CAN ID
uint8_t data[8]; // CAN 数据
uint8_t length; // 数据长度 (0-8)
} can_message_t;
typedef struct {
int (*init)(int ch);
int (*send)(int ch, const can_message_t *msg);
int (*recv)(int ch, can_message_t *msg);
int (*filter_config)(int ch, uint8_t filter_id, uint32_t id, uint32_t mask);
} can_ops_t;
// 注册接口(由 HAL 调用)
void can_register_ops(const can_ops_t *ops);
// 对上层暴露统一 API
int can_if_init(int ch);
int can_if_send(int ch, const can_message_t *msg);
int can_if_recv(int ch, can_message_t *msg);
int can_if_filter_config(int ch, uint8_t filter_id, uint32_t id, uint32_t mask);
#endif