PER Firmware
Loading...
Searching...
No Matches
can_common.h
Go to the documentation of this file.
1#ifndef CAN_COMMON_H
2#define CAN_COMMON_H
3
11#include <stdint.h>
12
13#include "common/rtos/rtos.h"
14#if defined(STM32F407xx)
16#elif defined(STM32G474xx)
18#else
19#error "Unsupported CAN target"
20#endif
21
22typedef struct {
23 uint32_t rx_overflow; // software queue overflow
24 uint32_t tx_overflow; // software queue overflow
27 uint32_t tx_sent_count;
29 // todo: track hardware stats
30 // todo: per-peripheral stats
32
33extern volatile can_stats_t can_stats;
34extern volatile uint32_t last_can_rx_time_ms;
35// todo: last tx time
36
37extern QueueHandle_t can_rx_queue;
38
39void CAN_tx_update(void);
40void CAN_rx_update(void);
41bool CAN_init(void);
42void CAN_enable_IRQs(void);
43void CAN_rx_init(void);
44void CAN_tx_init(void);
45
46#define DEFINE_CAN_TASKS() \
47 RTOS_DEFINE_TASK(CAN_rx_update, 0, TASK_PRIORITY_HIGH, STACK_2048); \
48 RTOS_DEFINE_TASK(CAN_tx_update, 0, TASK_PRIORITY_HIGH, STACK_1024);
49
50#define START_CAN_TASKS() \
51 RTOS_START_TASK(CAN_rx_update); \
52 RTOS_START_TASK(CAN_tx_update); \
53 CAN_enable_IRQs();
54
55#define CAN_TX_QUEUE_LENGTH (32) // Length of software queue for each CAN peripheral
56#define CAN_RX_QUEUE_LENGTH (32) // Length of software queue for received messages
57
58#define NVIC_RX_IRQ_PRIO (6)
59#define NVIC_TX_IRQ_PRIO (7)
60static_assert(
62 "Do not set an IRQ priority higher (numerically lower) than FreeRTOS to prevent corruption of kernel data structures"
63);
64static_assert(
66 "RX priority should be higher (numerically lower) than TX"
67);
68
69#endif // CAN_COMMON_H
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
Definition FreeRTOSConfig.h:178
void CAN_enable_IRQs(void)
Definition can_init.c:47
void CAN_tx_update(void)
Definition can_tx.c:160
void CAN_rx_update(void)
Definition can_rx.c:20
void CAN_rx_init(void)
Definition can_rx.c:16
void CAN_tx_init(void)
Definition can_tx.c:47
#define NVIC_RX_IRQ_PRIO
Definition can_common.h:58
volatile uint32_t last_can_rx_time_ms
Definition can_irq.c:16
#define NVIC_TX_IRQ_PRIO
Definition can_common.h:59
QueueHandle_t can_rx_queue
volatile can_stats_t can_stats
Definition can_tx.c:13
bool CAN_init(void)
Definition can_init.c:146
G4 FDCAN public API implementation.
Wrapper macros for FreeRTOS constructs (tasks, queues, semaphores) to simplify static memory allocati...
Definition can_common.h:22
uint32_t tx_callback_count
Definition can_common.h:28
uint32_t tx_enqueue_count
Definition can_common.h:25
uint32_t rx_overflow
Definition can_common.h:23
uint32_t tx_overflow
Definition can_common.h:24
uint32_t tx_task_wake_count
Definition can_common.h:26
uint32_t tx_sent_count
Definition can_common.h:27