Loading...
Searching...
No Matches
candev_samd5x.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 ML!PA Consulting GmbH
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
9#pragma once
10
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#if defined(CAN_INST_NUM)
27# include "can/candev.h"
28
29# ifndef CANDEV_SAMD5X_DEFAULT_BITRATE
33# define CANDEV_SAMD5X_DEFAULT_BITRATE 500000U
34# endif
35
36# ifndef CANDEV_SAMD5X_DEFAULT_SPT
38# define CANDEV_SAMD5X_DEFAULT_SPT 875
39# endif
40
41# ifndef CANDEV_SAMD5X_DEFAULT_STD_FILTER_NUM
42# define CANDEV_SAMD5X_DEFAULT_STD_FILTER_NUM 3
43# endif
44
45# ifndef CANDEV_SAMD5X_DEFAULT_EXT_FILTER_NUM
46# define CANDEV_SAMD5X_DEFAULT_EXT_FILTER_NUM 3
47# endif
48
49# ifndef CANDEV_SAMD5X_DEFAULT_RX_FIFO_0_ELTS_NUM
50# define CANDEV_SAMD5X_DEFAULT_RX_FIFO_0_ELTS_NUM 32
51# endif
52
53# ifndef CANDEV_SAMD5X_DEFAULT_RX_FIFO_1_ELTS_NUM
54# define CANDEV_SAMD5X_DEFAULT_RX_FIFO_1_ELTS_NUM 32
55# endif
56
57# ifndef CANDEV_SAMD5X_DEFAULT_TX_EVT_FIFO_ELTS_NUM
58# define CANDEV_SAMD5X_DEFAULT_TX_EVT_FIFO_ELTS_NUM 16
59# endif
60
61# ifndef CANDEV_SAMD5X_DEFAULT_TX_BUFFER_NUM
62# define CANDEV_SAMD5X_DEFAULT_TX_BUFFER_NUM 16
63# endif
64
65# ifndef CANDEV_SAMD5X_DEFAULT_TX_BUFFER_FIFO_QUEUE_NUM
66# define CANDEV_SAMD5X_DEFAULT_TX_BUFFER_FIFO_QUEUE_NUM 16
67# endif
68
69/* unit: elements */
70# define CANDEV_SAMD5X_MAX_STD_FILTER 128
71# define CANDEV_SAMD5X_MAX_EXT_FILTER 64
72# define CANDEV_SAMD5X_MAX_RX_FIFO_0_ELTS 64
73# define CANDEV_SAMD5X_MAX_RX_FIFO_1_ELTS 64
74# define CANDEV_SAMD5X_MAX_RX_BUFFER 64
75# define CANDEV_SAMD5X_MAX_TX_EVT_FIFO_ELTS 32
76# define CANDEV_SAMD5X_MAX_TX_BUFFER 32
77# define CANDEV_SAMD5X_MSG_RAM_MAX_SIZE 448
78
79/* SAMD5x CAN controller error codes (values from datasheet section 39.8.14) */
80# define CANDEV_SAMD5X_NO_ERROR 0
81# define CANDEV_SAMD5X_STUFF_ERROR 1
82# define CANDEV_SAMD5X_FORM_ERROR 2
83# define CANDEV_SAMD5X_ACK_ERROR 3
84# define CANDEV_SAMD5X_BIT1_ERROR 4
85# define CANDEV_SAMD5X_BIT0_ERROR 5
86# define CANDEV_SAMD5X_CRC_ERROR 6
87# define CANDEV_SAMD5X_NO_CHANGE_ERROR 7
88
92typedef struct {
94 Can *can;
95 uint32_t bitrate;
97 gpio_t rx_pin;
99 gpio_t tx_pin;
101 gpio_t enable_pin;
103 gpio_mode_t enable_pin_mode;
105 uint8_t gclk_src;
114 bool enable_pin_active_low : 1;
122 bool disable_automatic_retransmission : 1;
132 bool enable_transmit_pause : 1;
139 bool start_in_monitor_mode : 1;
140} can_conf_t;
141# define HAVE_CAN_CONF_T
142
146typedef struct can_msg_ram {
148 CanMramSidfe std_filter[CANDEV_SAMD5X_DEFAULT_STD_FILTER_NUM];
150 CanMramXifde ext_filter[CANDEV_SAMD5X_DEFAULT_EXT_FILTER_NUM];
152 CanMramRxf0e rx_fifo_0[CANDEV_SAMD5X_DEFAULT_RX_FIFO_0_ELTS_NUM];
154 CanMramRxf1e rx_fifo_1[CANDEV_SAMD5X_DEFAULT_RX_FIFO_1_ELTS_NUM];
156 CanMramRxbe rx_buffer[CANDEV_SAMD5X_MAX_RX_BUFFER];
158 CanMramTxefe tx_event_fifo[CANDEV_SAMD5X_DEFAULT_TX_EVT_FIFO_ELTS_NUM];
160 CanMramTxbe tx_buffer[CANDEV_SAMD5X_DEFAULT_TX_BUFFER_FIFO_QUEUE_NUM];
161} can_msg_ram_t;
162
166typedef struct {
170 const can_conf_t *conf;
172 struct {
173 uint8_t last_error_code;
174 uint8_t d_last_error_code;
175 uint8_t tx_error_count;
176 uint8_t rx_error_count;
177 } state;
179 can_msg_ram_t msg_ram;
181 bool tdc_ctrl;
182} can_t;
183# define HAVE_CAN_T
184
191void candev_samd5x_tdc_control(can_t *dev);
192
199void candev_samd5x_enter_sleep_mode(candev_t *candev);
200
207void candev_samd5x_exit_sleep_mode(candev_t *candev);
208
209#endif /* CAN_INST_NUM */
210
211#ifdef __cplusplus
212}
213#endif
214
Definitions for low-level CAN driver interface.
struct can can_t
Low level device structure for ESP32 CAN (extension of candev_t)
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:91
struct candev candev_t
Forward declaration for candev struct.
Definition candev.h:59
ESP CAN device configuration.
Definition can_esp.h:84
Low level device structure for ESP32 CAN (extension of candev_t)
Definition can_esp.h:60
Structure to hold driver state.
Definition candev.h:76