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
14#include "common/phal/can.h"
15
16typedef struct {
17 uint32_t rx_overflow; // software queue overflow
18 uint32_t tx_overflow; // software queue overflow
19 uint32_t tx_enqueue_count;
20 uint32_t tx_task_wake_count;
21 uint32_t tx_sent_count;
22 uint32_t tx_callback_count;
23 // todo: track hardware stats
24 // todo: per-peripheral stats
26
27extern volatile can_stats_t can_stats;
28extern volatile uint32_t last_can_rx_time_ms;
29// todo: last tx time
30
31extern QueueHandle_t can_rx_queue;
32
33void CAN_tx_update(void);
34void CAN_rx_update(void);
35bool CAN_init(void);
36void CAN_enable_IRQs(void);
37void CAN_rx_init(void);
38void CAN_tx_init(void);
39
40#define DEFINE_CAN_TASKS() \
41 DEFINE_TASK(CAN_rx_update, 0, osPriorityHigh, STACK_2048); \
42 DEFINE_TASK(CAN_tx_update, 0, osPriorityHigh, STACK_1024);
43
44#define START_CAN_TASKS() \
45 START_TASK(CAN_rx_update); \
46 START_TASK(CAN_tx_update); \
47 CAN_enable_IRQs();
48
49#define CAN_TX_QUEUE_LENGTH (32) // Length of software queue for each CAN peripheral
50#define CAN_RX_QUEUE_LENGTH (32) // Length of software queue for received messages
51
52#define NVIC_RX_IRQ_PRIO (6)
53#define NVIC_TX_IRQ_PRIO (7)
54static_assert(
55 configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY < NVIC_RX_IRQ_PRIO,
56 "Do not set an IRQ priority higher (numerically lower) than FreeRTOS to prevent corruption of kernel data structures"
57);
58static_assert(
59 NVIC_RX_IRQ_PRIO < NVIC_TX_IRQ_PRIO,
60 "RX priority should be higher (numerically lower) than TX"
61);
62
63#endif // CAN_COMMON_H
Wrapper macros for FreeRTOS constructs (tasks, queues, semaphores) to simplify static memory allocati...
Definition can_common.h:16