libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
stm32_can.hpp
1#pragma once
2
3#include "main.h"
4
5#ifdef HAL_CAN_MODULE_ENABLED
6
7#ifdef CAN
8#undef CAN
9#endif
10
11#include "can.hpp"
12#include "libxr.hpp"
13
14typedef enum
15{
16#ifdef CAN1
17 STM32_CAN1,
18#endif
19#ifdef CAN2
20 STM32_CAN2,
21#endif
22#ifdef CAN3
23 STM32_CAN3,
24#endif
25 STM32_CAN_NUMBER,
26 STM32_CAN_ID_ERROR
27} stm32_can_id_t;
28
29stm32_can_id_t STM32_CAN_GetID(CAN_TypeDef* addr); // NOLINT
30
31namespace LibXR
32{
38class STM32CAN : public CAN
39{
40 public:
47 STM32CAN(CAN_HandleTypeDef* hcan, uint32_t pool_size);
48
54 ErrorCode Init(void);
55
56 ErrorCode AddMessage(const ClassicPack& pack) override;
57
62 void ProcessRxInterrupt();
63
68 void ProcessTxInterrupt();
69
70 CAN_HandleTypeDef* hcan_;
71
72 stm32_can_id_t id_;
73 uint32_t fifo_;
74 static STM32CAN* map[STM32_CAN_NUMBER]; // NOLINT
75
76 struct
77 {
78 CAN_RxHeaderTypeDef header;
79 ClassicPack pack;
80 } rx_buff_;
81
82 struct
83 {
84 CAN_TxHeaderTypeDef header;
85 ClassicPack pack;
86 } tx_buff_;
87
88 uint32_t txMailbox;
89
91
92 std::atomic<uint32_t> bus_busy_ = 0;
93};
94} // namespace LibXR
95
96#endif
CAN通信接口,定义标准CAN通信结构,支持不同类型的消息 (CAN communication interface that defines a standard CAN structure supp...
Definition can.hpp:14
无锁无序槽池 / Lock-free, unordered slot pool
STM32CAN 类,用于处理 STM32 系统的 CAN 通道。 Provides handling for STM32 CAN channels.
Definition stm32_can.hpp:39
STM32CAN(CAN_HandleTypeDef *hcan, uint32_t pool_size)
STM32CAN 类,用于处理 STM32 系统的 CAN 通道。 Provides handling for STM32 CAN.
Definition stm32_can.cpp:47
ErrorCode Init(void)
初始化
Definition stm32_can.cpp:54
ErrorCode AddMessage(const ClassicPack &pack) override
添加 CAN 消息到系统 (Adds a CAN message to the system).
void ProcessRxInterrupt()
处理接收中断
void ProcessTxInterrupt()
处理发送中断
LibXR 命名空间
Definition ch32_gpio.hpp:9