Midnight Sun Firmware
Loading...
Searching...
No Matches
can_queue.h
1#pragma once
2
3/************************************************************************************************
4 * @file can_queue.h
5 *
6 * @brief Wrappers for CAN queues to reduce instruction jumps
7 *
8 * @date 2024-11-02
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13
14/* Inter-component Headers */
15#include "queues.h"
16
17/* Intra-component Headers */
18#include "can_msg.h"
19
27#define CAN_QUEUE_SIZE 64U
28
34typedef struct CanQueue {
35 Queue queue;
36 CanMessage msg_nodes[CAN_QUEUE_SIZE];
38
39#define can_queue_init(can_queue) \
40 ({ \
41 Queue* queue = &(can_queue)->queue; \
42 queue->num_items = CAN_QUEUE_SIZE; \
43 queue->item_size = sizeof(CanMessage); \
44 queue->storage_buf = (uint8_t*) (&(can_queue)->msg_nodes); \
45 queue_init(&(can_queue)->queue); \
46 })
47
48#define can_queue_push(can_queue, source) \
49 queue_send(&(can_queue)->queue, (source), 0)
50
51#define can_queue_push_from_isr(can_queue, source, high_prio_woken) \
52 queue_send_from_isr(&(can_queue)->queue, (source), high_prio_woken)
53
54#define can_queue_peek(can_queue, dest) \
55 queue_peek(&(can_queue)->queue, (dest), 0)
56
57#define can_queue_pop(can_queue, dest) \
58 queue_receive(&(can_queue)->queue, (dest), 0)
59
60#define can_queue_pop_from_isr(can_queue, dest, higher_prio_woken) \
61 queue_receive_from_isr(&(can_queue)->queue, (dest), high_prio_woken)
62
63#define can_queue_size(can_queue) \
64 queue_get_num_items(&(can_queue)->queue)
65
#define CAN_QUEUE_SIZE
Maximum number of CAN messages permitted for the CAN queue.
Definition: can_queue.h:27
CAN message structure.
Definition: can_msg.h:55
CAN queue data structure to store received CAN messages.
Definition: can_queue.h:34
Queue storage and access struct.
Definition: queues.h:32