14#include "common/phal/can.h"
16#if defined(STM32G474xx)
17typedef enum : uint8_t {
21 CAN_NUM_PERIPHERALS = 3,
22 CAN_PERIPHERAL_INVALID = 0xFF
25static inline CAN_peripheral_t BUS_TO_PERIPHERAL(FDCAN_GlobalTypeDef *bus) {
26 if (bus == FDCAN1)
return CAN_PERIPHERAL1;
27 else if (bus == FDCAN2)
return CAN_PERIPHERAL2;
28 else if (bus == FDCAN3)
return CAN_PERIPHERAL3;
29 else return CAN_PERIPHERAL_INVALID;
32typedef enum : uint8_t {
35 CAN_NUM_PERIPHERALS = 2,
36 CAN_PERIPHERAL_INVALID = 0xFF
39static inline CAN_peripheral_t BUS_TO_PERIPHERAL(CAN_TypeDef *bus) {
40 if (bus == CAN1)
return CAN_PERIPHERAL1;
41 else if (bus == CAN2)
return CAN_PERIPHERAL2;
42 else return CAN_PERIPHERAL_INVALID;
49 uint32_t tx_enqueue_count;
50 uint32_t tx_task_wake_count;
51 uint32_t tx_sent_count;
52 uint32_t tx_callback_count;
58extern volatile uint32_t last_can_rx_time_ms;
61extern QueueHandle_t can_rx_queue;
62extern QueueHandle_t can_tx_queues[CAN_NUM_PERIPHERALS];
65void CAN_tx_update(
void);
66void CAN_rx_update(
void);
68void CAN_enable_IRQs(
void);
69void CAN_rx_init(
void);
70void CAN_tx_init(
void);
72#define DEFINE_CAN_TASKS() \
73 DEFINE_TASK(CAN_rx_update, 0, osPriorityHigh, STACK_2048); \
74 DEFINE_TASK(CAN_tx_update, 0, osPriorityHigh, STACK_1024);
76#define START_CAN_TASKS() \
77 START_TASK(CAN_rx_update); \
78 START_TASK(CAN_tx_update); \
81#define CAN_TX_QUEUE_LENGTH (32)
82#define CAN_RX_QUEUE_LENGTH (32)
84#define NVIC_RX_IRQ_PRIO (6)
85#define NVIC_TX_IRQ_PRIO (7)
87 configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY < NVIC_RX_IRQ_PRIO,
88 "Do not set an IRQ priority higher (numerically lower) than FreeRTOS to prevent corruption of kernel data structures"
91 NVIC_RX_IRQ_PRIO < NVIC_TX_IRQ_PRIO,
92 "RX priority should be higher (numerically lower) than TX"
Wrapper macros for FreeRTOS constructs (tasks, queues, semaphores) to simplify static memory allocati...
Definition can_common.h:46