Core
Loading...
Searching...
No Matches
can.h
1#pragma once
2
3#include "clock.h"
4#include "timestamp.h"
5#include "core_config.h"
6#include <stdbool.h>
7#include <stdint.h>
8
9#if (CORE_CAN_DISABLE_TX_QUEUE != 1) || (CORE_CAN_DISABLE_SEMAPHORE != 1) || (CORE_CAN_USE_MSGBUF == 1) || (CORE_CAN_DISABLE_RX_QUEUE != 1)
10#include "FreeRTOS.h"
11#include "queue.h"
12#include "semphr.h"
13#include "message_buffer.h"
14#endif
15
16
17typedef struct
18{
19 int id;
20 int dlc;
21 uint64_t data;
23
24typedef struct
25{
26 int id;
27 int dlc;
28 bool use_fd;
29 uint8_t data[64];
31
32typedef struct core_CAN_module_s {
33 FDCAN_HandleTypeDef hfdcan;
34#if CORE_CAN_DISABLE_RX_QUEUE != 1
35 QueueHandle_t can_queue_rx;
36#endif
37#if CORE_CAN_DISABLE_TX_QUEUE != 1
38 QueueHandle_t can_queue_tx;
39#endif
40#if CORE_CAN_USE_MSGBUF != 0
41 MessageBufferHandle_t msgbuf;
42#endif
43#if CORE_CAN_DISABLE_SEMAPHORE != 1
44 SemaphoreHandle_t can_tx_semaphore;
47#endif
48 uint32_t timestamp_msb;
50 uint8_t fdcan_num_standard_filters;
51 uint8_t fdcan_num_extended_filters;
52 uint8_t autort;
53 uint8_t use_fd;
55
60typedef struct core_CAN_head_s {
61 uint8_t type;
62 uint8_t length : 7;
63 uint8_t fdf : 1;
64 uint16_t timestamp;
65 uint32_t id : 29;
66 uint8_t rtr : 1;
67 uint8_t xtd : 1;
68 uint8_t esi : 1;
70
71typedef struct core_CAN_errors_s {
72 uint16_t arbitration_error;
73 uint16_t data_error;
74 uint16_t bus_off;
75 uint16_t tx_lost;
77
78extern const uint8_t core_CAN_dlc_lookup[16];
79extern core_CAN_errors_t core_CAN_errors;
80
81bool core_CAN_init(FDCAN_GlobalTypeDef *fdcan, uint32_t baudrate);
82core_CAN_module_t *core_CAN_convert(FDCAN_GlobalTypeDef *fdcan);
83
84#define core_CAN_enable_timestamps core_timestamp_init
85
86bool core_CAN_send_message(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint64_t data);
87bool core_CAN_send_fd_message(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint8_t *data);
88bool core_CAN_add_message_to_tx_queue(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint64_t data);
89bool core_CAN_add_extended_message_to_tx_queue(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint8_t *data);
90bool core_CAN_send_from_tx_queue_task(FDCAN_GlobalTypeDef *can);
91
92bool core_CAN_receive_from_queue(FDCAN_GlobalTypeDef *can, CanMessage_s *received_message);
93bool core_CAN_receive_extended_from_queue(FDCAN_GlobalTypeDef *can, CanExtendedMessage_s *received_message);
94#if (defined(CORE_CAN_USE_MSGBUF)) && (CORE_CAN_USE_MSGBUF != 0)
95uint8_t core_CAN_receive_from_msgbuf(FDCAN_GlobalTypeDef *can, uint8_t *buf, TickType_t timeout);
96BaseType_t core_CAN_msgbuf_insert_ts(core_CAN_module_t *p_can, uint8_t *buf, uint8_t buflen, uint32_t lsb);
97#endif
98
99bool core_CAN_add_filter(FDCAN_GlobalTypeDef *can, bool isExtended, uint32_t id1, uint32_t id2);
100
101/* STATIC FUNCTIONS (DECLARED/DEFINED IN CAN.C)
102static bool CAN_send_message(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint64_t data);
103static void rx_handler(FDCAN_GlobalTypeDef *can);
104static void add_CAN_message_to_rx_queue(FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint8_t *data);
105*/
Configuration file for the core library.
Definition can.h:25
Definition can.h:18
Definition can.h:71
Header for a CAN packet.
Definition can.h:60
uint8_t rtr
Indicates if the frame was a remote transmission request.
Definition can.h:66
uint8_t esi
Indicates if the transmitting node is error passive.
Definition can.h:68
uint8_t type
Packet type.
Definition can.h:61
uint8_t xtd
Indicates if the ID is an extended ID.
Definition can.h:67
uint8_t length
Length of the packet not including the header.
Definition can.h:62
uint32_t id
CAN ID.
Definition can.h:65
uint8_t fdf
1 for FD frames, 0 otherwise
Definition can.h:63
uint16_t timestamp
Timestamp for received packets.
Definition can.h:64
Definition can.h:32
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:44
FDCAN_HandleTypeDef hfdcan
HAL FDCAN handle.
Definition can.h:33
QueueHandle_t can_queue_rx
Handle for FreeRTOS RX queue.
Definition can.h:35
QueueHandle_t can_queue_tx
Handle for FreeRTOS TX queue.
Definition can.h:38
uint32_t timestamp_msb
Most significant bits of the timestamp for the most recently received packet.
Definition can.h:48