Core
Loading...
Searching...
No Matches
can.h
Go to the documentation of this file.
1
69#pragma once
70
71#include "clock.h"
72#include "timestamp.h"
73#include "core_config.h"
74#include <stdbool.h>
75#include <stdint.h>
76
77#if (CORE_CAN_DISABLE_TX_QUEUE != 1) || (CORE_CAN_DISABLE_SEMAPHORE != 1) || (CORE_CAN_USE_MSGBUF == 1) || (CORE_CAN_DISABLE_RX_QUEUE != 1)
78#include "FreeRTOS.h"
79#include "queue.h"
80#include "semphr.h"
81#include "message_buffer.h"
82#endif
83
84
85typedef struct
86{
87 int id;
88 int dlc;
89 uint64_t data;
91
92typedef struct
93{
94 int id;
95 int dlc;
96 bool use_fd;
97 uint8_t data[64];
99
100typedef struct core_CAN_module_s {
101 FDCAN_HandleTypeDef hfdcan;
102#if CORE_CAN_DISABLE_RX_QUEUE != 1
103 QueueHandle_t can_queue_rx;
104#endif
105#if CORE_CAN_DISABLE_TX_QUEUE != 1
106 QueueHandle_t can_queue_tx;
107#endif
108#if CORE_CAN_USE_MSGBUF != 0
109 MessageBufferHandle_t msgbuf;
110#endif
111#if CORE_CAN_DISABLE_SEMAPHORE != 1
112 SemaphoreHandle_t can_tx_semaphore;
115#endif
116 uint32_t *timestamp_msb;
118 uint8_t fdcan_num_standard_filters;
119 uint8_t fdcan_num_extended_filters;
120 uint8_t autort;
121 uint8_t use_fd;
123
128typedef struct core_CAN_head_s {
129 uint8_t type;
130 uint8_t length : 7;
131 uint8_t fdf : 1;
132 uint16_t timestamp;
133 uint32_t id : 29;
134 uint8_t rtr : 1;
135 uint8_t xtd : 1;
136 uint8_t esi : 1;
138
139typedef struct core_CAN_msg_s {
140 core_CAN_head_t header;
141 uint64_t data;
143
144typedef struct core_CAN_errors_s {
145 uint16_t arbitration_error;
146 uint16_t data_error;
147 uint16_t bus_off;
148 uint16_t tx_lost;
150
151extern const uint8_t core_CAN_dlc_lookup[16];
152extern core_CAN_errors_t core_CAN_errors;
153
160bool core_CAN_init(FDCAN_GlobalTypeDef *fdcan, uint32_t baudrate);
161
162core_CAN_module_t *core_CAN_convert(FDCAN_GlobalTypeDef *fdcan);
163
164#define core_CAN_enable_timestamps core_timestamp_init
165
178bool core_CAN_send_message(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint64_t data);
179
193bool core_CAN_send_fd_message(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint8_t *data);
194
195#if !defined(CORE_CAN_DISABLE_TX_QUEUE) || (CORE_CAN_DISABLE_TX_QUEUE == 0) || defined(DOXYGEN)
206bool core_CAN_add_message_to_tx_queue(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint64_t data);
207
219bool core_CAN_add_extended_message_to_tx_queue(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint8_t *data);
220
227bool core_CAN_send_from_tx_queue_task(FDCAN_GlobalTypeDef *can);
228#endif
229
230#if ((CORE_CAN_USE_MSGBUF != 1) && (CORE_CAN_DISABLE_RX_QUEUE != 1)) || defined(DOXYGEN)
245bool core_CAN_receive_from_queue(FDCAN_GlobalTypeDef *can, CanMessage_s *received_message);
246
261bool core_CAN_receive_extended_from_queue(FDCAN_GlobalTypeDef *can, CanExtendedMessage_s *received_message);
262#endif
263
264#if (defined(CORE_CAN_USE_MSGBUF)) && (CORE_CAN_USE_MSGBUF != 0)
278uint8_t core_CAN_receive_from_msgbuf(FDCAN_GlobalTypeDef *can, uint8_t *buf, TickType_t timeout);
279
283BaseType_t core_CAN_msgbuf_insert_ts(core_CAN_module_t *p_can, uint8_t *buf, uint8_t buflen, uint32_t lsb);
284#endif
285
298bool core_CAN_add_filter(FDCAN_GlobalTypeDef *can, bool isExtended, uint32_t id1, uint32_t id2);
299
bool core_CAN_add_filter(FDCAN_GlobalTypeDef *can, bool isExtended, uint32_t id1, uint32_t id2)
Add an RX filter for the given FDCAN module.
Definition can.c:577
bool core_CAN_receive_from_queue(FDCAN_GlobalTypeDef *can, CanMessage_s *received_message)
If a frame is waiting in the RX queue, copy it to the given location.
Definition can.c:554
bool core_CAN_send_from_tx_queue_task(FDCAN_GlobalTypeDef *can)
Loop for sending data in the TX queue over CAN. This function must be run in its own task....
Definition can.c:301
bool core_CAN_receive_extended_from_queue(FDCAN_GlobalTypeDef *can, CanExtendedMessage_s *received_message)
If a frame is waiting in the RX queue, copy it to the given location.
Definition can.c:544
bool core_CAN_add_extended_message_to_tx_queue(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint8_t *data)
Add a CAN frame to the TX queue. This function is only available if CORE_CAN_DISABLE_TX_QUEUE is set ...
Definition can.c:287
bool core_CAN_send_message(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint64_t data)
Add a CAN message to the hardware FIFO.
Definition can.c:330
bool core_CAN_add_message_to_tx_queue(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint64_t data)
Add a CAN frame to the TX queue. This function is only available if CORE_CAN_DISABLE_TX_QUEUE is set ...
Definition can.c:271
bool core_CAN_send_fd_message(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint8_t *data)
Add an FDCAN message to the hardware FIFO.
Definition can.c:357
bool core_CAN_init(FDCAN_GlobalTypeDef *fdcan, uint32_t baudrate)
Initialize an FDCAN module, the RX and TX pins, the TX queue (if enabled), and the RX queue or messag...
Definition can.c:78
Core clock library.
Configuration file for the core library.
Definition can.h:93
Definition can.h:86
Definition can.h:144
Header for a CAN packet.
Definition can.h:128
uint8_t rtr
Indicates if the frame was a remote transmission request.
Definition can.h:134
uint8_t esi
Indicates if the transmitting node is error passive.
Definition can.h:136
uint8_t type
Packet type.
Definition can.h:129
uint8_t xtd
Indicates if the ID is an extended ID.
Definition can.h:135
uint8_t length
Length of the packet not including the header.
Definition can.h:130
uint32_t id
CAN ID.
Definition can.h:133
uint8_t fdf
1 for FD frames, 0 otherwise
Definition can.h:131
uint16_t timestamp
Timestamp for received packets.
Definition can.h:132
Definition can.h:100
SemaphoreHandle_t can_tx_semaphore
TX semaphore, taken when a message is added to the hardware FIFO and given when transmission complete...
Definition can.h:112
uint32_t * timestamp_msb
Most significant bits of the timestamp for the most recently received packet.
Definition can.h:116
FDCAN_HandleTypeDef hfdcan
HAL FDCAN handle.
Definition can.h:101
QueueHandle_t can_queue_rx
Handle for FreeRTOS RX queue.
Definition can.h:103
QueueHandle_t can_queue_tx
Handle for FreeRTOS TX queue.
Definition can.h:106
Definition can.h:139
Core timestamp library.