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
20#ifndef CANDEV_SAMD5X_H
21#define CANDEV_SAMD5X_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#if defined(CAN_INST_NUM)
28#include "can/candev.h"
29
30#ifndef CANDEV_SAMD5X_DEFAULT_BITRATE
32#define CANDEV_SAMD5X_DEFAULT_BITRATE 500000U
33#endif
34
35#ifndef CANDEV_SAMD5X_DEFAULT_SPT
37#define CANDEV_SAMD5X_DEFAULT_SPT 875
38#endif
39
40#ifndef CANDEV_SAMD5X_DEFAULT_STD_FILTER_NUM
41#define CANDEV_SAMD5X_DEFAULT_STD_FILTER_NUM 3
42#endif
43
44#ifndef CANDEV_SAMD5X_DEFAULT_EXT_FILTER_NUM
45#define CANDEV_SAMD5X_DEFAULT_EXT_FILTER_NUM 3
46#endif
47
48#ifndef CANDEV_SAMD5X_DEFAULT_RX_FIFO_0_ELTS_NUM
49#define CANDEV_SAMD5X_DEFAULT_RX_FIFO_0_ELTS_NUM 32
50#endif
51
52#ifndef CANDEV_SAMD5X_DEFAULT_RX_FIFO_1_ELTS_NUM
53#define CANDEV_SAMD5X_DEFAULT_RX_FIFO_1_ELTS_NUM 32
54#endif
55
56#ifndef CANDEV_SAMD5X_DEFAULT_TX_EVT_FIFO_ELTS_NUM
57#define CANDEV_SAMD5X_DEFAULT_TX_EVT_FIFO_ELTS_NUM 16
58#endif
59
60#ifndef CANDEV_SAMD5X_DEFAULT_TX_BUFFER_NUM
61#define CANDEV_SAMD5X_DEFAULT_TX_BUFFER_NUM 16
62#endif
63
64#ifndef CANDEV_SAMD5X_DEFAULT_TX_BUFFER_FIFO_QUEUE_NUM
65#define CANDEV_SAMD5X_DEFAULT_TX_BUFFER_FIFO_QUEUE_NUM 16
66#endif
67
68/* unit: elements */
69#define CANDEV_SAMD5X_MAX_STD_FILTER 128
70#define CANDEV_SAMD5X_MAX_EXT_FILTER 64
71#define CANDEV_SAMD5X_MAX_RX_FIFO_0_ELTS 64
72#define CANDEV_SAMD5X_MAX_RX_FIFO_1_ELTS 64
73#define CANDEV_SAMD5X_MAX_RX_BUFFER 64
74#define CANDEV_SAMD5X_MAX_TX_EVT_FIFO_ELTS 32
75#define CANDEV_SAMD5X_MAX_TX_BUFFER 32
76#define CANDEV_SAMD5X_MSG_RAM_MAX_SIZE 448
77
78/* SAMD5x CAN controller error codes (values from datasheet section 39.8.14) */
79#define CANDEV_SAMD5X_NO_ERROR 0
80#define CANDEV_SAMD5X_STUFF_ERROR 1
81#define CANDEV_SAMD5X_FORM_ERROR 2
82#define CANDEV_SAMD5X_ACK_ERROR 3
83#define CANDEV_SAMD5X_BIT1_ERROR 4
84#define CANDEV_SAMD5X_BIT0_ERROR 5
85#define CANDEV_SAMD5X_CRC_ERROR 6
86#define CANDEV_SAMD5X_NO_CHANGE_ERROR 7
87
91typedef struct {
93 Can *can;
95 gpio_t rx_pin;
97 gpio_t tx_pin;
99 uint8_t gclk_src;
100} can_conf_t;
101#define HAVE_CAN_CONF_T
102
106typedef struct {
108 CanMramSidfe std_filter[CANDEV_SAMD5X_DEFAULT_STD_FILTER_NUM];
110 CanMramXifde ext_filter[CANDEV_SAMD5X_DEFAULT_EXT_FILTER_NUM];
112 CanMramRxf0e rx_fifo_0[CANDEV_SAMD5X_DEFAULT_RX_FIFO_0_ELTS_NUM];
114 CanMramRxf1e rx_fifo_1[CANDEV_SAMD5X_DEFAULT_RX_FIFO_1_ELTS_NUM];
116 CanMramRxbe rx_buffer[CANDEV_SAMD5X_MAX_RX_BUFFER];
118 CanMramTxefe tx_event_fifo[CANDEV_SAMD5X_DEFAULT_TX_EVT_FIFO_ELTS_NUM];
120 CanMramTxbe tx_fifo_queue[CANDEV_SAMD5X_DEFAULT_TX_BUFFER_FIFO_QUEUE_NUM];
121} msg_ram_conf_t;
122
126typedef struct {
130 const can_conf_t *conf;
132 msg_ram_conf_t msg_ram_conf;
134 bool tdc_ctrl;
136 bool tx_fifo_queue_ctrl;
137} can_t;
138#define HAVE_CAN_T
139
146void candev_samd5x_tdc_control(can_t *dev);
147
154void candev_samd5x_enter_sleep_mode(candev_t *candev);
155
162void candev_samd5x_exit_sleep_mode(candev_t *candev);
163
164#endif /* CAN_INST_NUM */
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif /* CANDEV_SAMD5X_H */
Definitions for low-level CAN driver interface.
struct can can_t
Low level device structure for ESP32 CAN (extension of candev_t)
ESP CAN device configuration.
Definition can_esp.h:88
Low level device structure for ESP32 CAN (extension of candev_t)
Definition can_esp.h:64
Structure to hold driver state.
Definition candev.h:77