Zephyr Project API  3.4.0
A Scalable Open Source RTOS
can.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Vestas Wind Systems A/S
3 * Copyright (c) 2018 Karsten Koenig
4 * Copyright (c) 2018 Alexander Wachter
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9#ifndef ZEPHYR_INCLUDE_DRIVERS_CAN_H_
10#define ZEPHYR_INCLUDE_DRIVERS_CAN_H_
11
12#include <errno.h>
13
14#include <zephyr/types.h>
15#include <zephyr/device.h>
16#include <zephyr/kernel.h>
17#include <string.h>
18#include <zephyr/sys_clock.h>
19#include <zephyr/sys/util.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
40#define CAN_STD_ID_MASK 0x7FFU
44#define CAN_MAX_STD_ID CAN_STD_ID_MASK
48#define CAN_EXT_ID_MASK 0x1FFFFFFFU
52#define CAN_MAX_EXT_ID CAN_EXT_ID_MASK
56#define CAN_MAX_DLC 8U
60#define CANFD_MAX_DLC 15U
61
66#ifndef CONFIG_CAN_FD_MODE
67#define CAN_MAX_DLEN 8U
68#else
69#define CAN_MAX_DLEN 64U
70#endif /* CONFIG_CAN_FD_MODE */
71
84#define CAN_MODE_NORMAL 0
85
87#define CAN_MODE_LOOPBACK BIT(0)
88
90#define CAN_MODE_LISTENONLY BIT(1)
91
93#define CAN_MODE_FD BIT(2)
94
96#define CAN_MODE_ONE_SHOT BIT(3)
97
99#define CAN_MODE_3_SAMPLES BIT(4)
100
112
127};
128
137#define CAN_FRAME_IDE BIT(0)
138
140#define CAN_FRAME_RTR BIT(1)
141
143#define CAN_FRAME_FDF BIT(2)
144
146#define CAN_FRAME_BRS BIT(3)
147
151#define CAN_FRAME_ESI BIT(4)
152
158struct can_frame {
162 uint8_t res0 : 3; /* reserved/padding. */
168#if defined(CONFIG_CAN_RX_TIMESTAMP) || defined(__DOXYGEN__)
177#else
179 uint16_t res1; /* reserved/padding. */
181#endif
183 union {
184 uint8_t data[CAN_MAX_DLEN];
185 uint32_t data_32[DIV_ROUND_UP(CAN_MAX_DLEN, sizeof(uint32_t))];
186 };
187};
188
197#define CAN_FILTER_IDE BIT(0)
198
200#define CAN_FILTER_RTR BIT(1)
201
203#define CAN_FILTER_DATA BIT(2)
204
206#define CAN_FILTER_FDF BIT(3)
207
217 uint32_t res0 : 3;
225};
226
235};
236
240#define CAN_SJW_NO_CHANGE 0
241
285};
286
295typedef void (*can_tx_callback_t)(const struct device *dev, int error, void *user_data);
296
304typedef void (*can_rx_callback_t)(const struct device *dev, struct can_frame *frame,
305 void *user_data);
306
315typedef void (*can_state_change_callback_t)(const struct device *dev,
316 enum can_state state,
317 struct can_bus_err_cnt err_cnt,
318 void *user_data);
319
330typedef int (*can_set_timing_t)(const struct device *dev,
331 const struct can_timing *timing);
332
337typedef int (*can_set_timing_data_t)(const struct device *dev,
338 const struct can_timing *timing_data);
339
344typedef int (*can_get_capabilities_t)(const struct device *dev, can_mode_t *cap);
345
350typedef int (*can_start_t)(const struct device *dev);
351
356typedef int (*can_stop_t)(const struct device *dev);
357
362typedef int (*can_set_mode_t)(const struct device *dev, can_mode_t mode);
363
371typedef int (*can_send_t)(const struct device *dev,
372 const struct can_frame *frame,
374 void *user_data);
375
380typedef int (*can_add_rx_filter_t)(const struct device *dev,
381 can_rx_callback_t callback,
382 void *user_data,
383 const struct can_filter *filter);
384
389typedef void (*can_remove_rx_filter_t)(const struct device *dev, int filter_id);
390
395typedef int (*can_recover_t)(const struct device *dev, k_timeout_t timeout);
396
401typedef int (*can_get_state_t)(const struct device *dev, enum can_state *state,
402 struct can_bus_err_cnt *err_cnt);
403
408typedef void(*can_set_state_change_callback_t)(const struct device *dev,
410 void *user_data);
411
416typedef int (*can_get_core_clock_t)(const struct device *dev, uint32_t *rate);
417
422typedef int (*can_get_max_filters_t)(const struct device *dev, bool ide);
423
428typedef int (*can_get_max_bitrate_t)(const struct device *dev, uint32_t *max_bitrate);
429
430__subsystem struct can_driver_api {
431 can_get_capabilities_t get_capabilities;
432 can_start_t start;
433 can_stop_t stop;
434 can_set_mode_t set_mode;
435 can_set_timing_t set_timing;
436 can_send_t send;
437 can_add_rx_filter_t add_rx_filter;
438 can_remove_rx_filter_t remove_rx_filter;
439#if !defined(CONFIG_CAN_AUTO_BUS_OFF_RECOVERY) || defined(__DOXYGEN__)
440 can_recover_t recover;
441#endif /* CONFIG_CAN_AUTO_BUS_OFF_RECOVERY */
442 can_get_state_t get_state;
443 can_set_state_change_callback_t set_state_change_callback;
444 can_get_core_clock_t get_core_clock;
445 can_get_max_filters_t get_max_filters;
446 can_get_max_bitrate_t get_max_bitrate;
447 /* Min values for the timing registers */
448 struct can_timing timing_min;
449 /* Max values for the timing registers */
450 struct can_timing timing_max;
451#if defined(CONFIG_CAN_FD_MODE) || defined(__DOXYGEN__)
452 can_set_timing_data_t set_timing_data;
453 /* Min values for the timing registers during the data phase */
454 struct can_timing timing_data_min;
455 /* Max values for the timing registers during the data phase */
456 struct can_timing timing_data_max;
457#endif /* CONFIG_CAN_FD_MODE */
458};
459
462#if defined(CONFIG_CAN_STATS) || defined(__DOXYGEN__)
463
464#include <zephyr/stats/stats.h>
465
469STATS_SECT_ENTRY32(bit0_error)
470STATS_SECT_ENTRY32(bit1_error)
471STATS_SECT_ENTRY32(stuff_error)
472STATS_SECT_ENTRY32(crc_error)
473STATS_SECT_ENTRY32(form_error)
474STATS_SECT_ENTRY32(ack_error)
475STATS_SECT_ENTRY32(rx_overrun)
477
479STATS_NAME(can, bit0_error)
480STATS_NAME(can, bit1_error)
481STATS_NAME(can, stuff_error)
482STATS_NAME(can, crc_error)
483STATS_NAME(can, form_error)
484STATS_NAME(can, ack_error)
485STATS_NAME(can, rx_overrun)
486STATS_NAME_END(can);
487
496 struct stats_can stats;
497};
498
504#define Z_CAN_GET_STATS(dev_) \
505 CONTAINER_OF(dev_->state, struct can_device_state, devstate)->stats
506
517#define CAN_STATS_BIT0_ERROR_INC(dev_) \
518 STATS_INC(Z_CAN_GET_STATS(dev_), bit0_error)
519
528#define CAN_STATS_BIT1_ERROR_INC(dev_) \
529 STATS_INC(Z_CAN_GET_STATS(dev_), bit1_error)
530
539#define CAN_STATS_STUFF_ERROR_INC(dev_) \
540 STATS_INC(Z_CAN_GET_STATS(dev_), stuff_error)
541
550#define CAN_STATS_CRC_ERROR_INC(dev_) \
551 STATS_INC(Z_CAN_GET_STATS(dev_), crc_error)
552
561#define CAN_STATS_FORM_ERROR_INC(dev_) \
562 STATS_INC(Z_CAN_GET_STATS(dev_), form_error)
563
572#define CAN_STATS_ACK_ERROR_INC(dev_) \
573 STATS_INC(Z_CAN_GET_STATS(dev_), ack_error)
574
584#define CAN_STATS_RX_OVERRUN_INC(dev_) \
585 STATS_INC(Z_CAN_GET_STATS(dev_), rx_overrun)
586
595#define CAN_STATS_RESET(dev_) \
596 stats_reset(&(Z_CAN_GET_STATS(dev_).s_hdr))
597
603#define Z_CAN_DEVICE_STATE_DEFINE(dev_id) \
604 static struct can_device_state Z_DEVICE_STATE_NAME(dev_id) \
605 __attribute__((__section__(".z_devstate")))
606
613#define Z_CAN_INIT_FN(dev_id, init_fn) \
614 static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
615 { \
616 struct can_device_state *state = \
617 CONTAINER_OF(dev->state, struct can_device_state, devstate); \
618 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 7, \
619 STATS_NAME_INIT_PARMS(can)); \
620 stats_register(dev->name, &(state->stats.s_hdr)); \
621 if (init_fn != NULL) { \
622 return init_fn(dev); \
623 } \
624 \
625 return 0; \
626 }
627
650#define CAN_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, \
651 prio, api, ...) \
652 Z_CAN_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
653 Z_CAN_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
654 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
655 DEVICE_DT_NAME(node_id), \
656 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
657 pm, data, config, level, prio, api, \
658 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
659 __VA_ARGS__)
660
661#else /* CONFIG_CAN_STATS */
662
663#define CAN_STATS_BIT0_ERROR_INC(dev_)
664#define CAN_STATS_BIT1_ERROR_INC(dev_)
665#define CAN_STATS_STUFF_ERROR_INC(dev_)
666#define CAN_STATS_CRC_ERROR_INC(dev_)
667#define CAN_STATS_FORM_ERROR_INC(dev_)
668#define CAN_STATS_ACK_ERROR_INC(dev_)
669#define CAN_STATS_RX_OVERRUN_INC(dev_)
670#define CAN_STATS_RESET(dev_)
671
672#define CAN_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, \
673 prio, api, ...) \
674 DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, \
675 prio, api, __VA_ARGS__)
676
677#endif /* CONFIG_CAN_STATS */
678
686#define CAN_DEVICE_DT_INST_DEFINE(inst, ...) \
687 CAN_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
688
705__syscall int can_get_core_clock(const struct device *dev, uint32_t *rate);
706
707static inline int z_impl_can_get_core_clock(const struct device *dev, uint32_t *rate)
708{
709 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
710
711 return api->get_core_clock(dev, rate);
712}
713
726__syscall int can_get_max_bitrate(const struct device *dev, uint32_t *max_bitrate);
727
728static inline int z_impl_can_get_max_bitrate(const struct device *dev, uint32_t *max_bitrate)
729{
730 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
731
732 if (api->get_max_bitrate == NULL) {
733 return -ENOSYS;
734 }
735
736 return api->get_max_bitrate(dev, max_bitrate);
737}
738
746__syscall const struct can_timing *can_get_timing_min(const struct device *dev);
747
748static inline const struct can_timing *z_impl_can_get_timing_min(const struct device *dev)
749{
750 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
751
752 return &api->timing_min;
753}
754
762__syscall const struct can_timing *can_get_timing_max(const struct device *dev);
763
764static inline const struct can_timing *z_impl_can_get_timing_max(const struct device *dev)
765{
766 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
767
768 return &api->timing_max;
769}
770
792__syscall int can_calc_timing(const struct device *dev, struct can_timing *res,
793 uint32_t bitrate, uint16_t sample_pnt);
794
808__syscall const struct can_timing *can_get_timing_data_min(const struct device *dev);
809
810#ifdef CONFIG_CAN_FD_MODE
811static inline const struct can_timing *z_impl_can_get_timing_data_min(const struct device *dev)
812{
813 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
814
815 return &api->timing_data_min;
816}
817#endif /* CONFIG_CAN_FD_MODE */
818
832__syscall const struct can_timing *can_get_timing_data_max(const struct device *dev);
833
834#ifdef CONFIG_CAN_FD_MODE
835static inline const struct can_timing *z_impl_can_get_timing_data_max(const struct device *dev)
836{
837 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
838
839 return &api->timing_data_max;
840}
841#endif /* CONFIG_CAN_FD_MODE */
842
862__syscall int can_calc_timing_data(const struct device *dev, struct can_timing *res,
863 uint32_t bitrate, uint16_t sample_pnt);
864
884__syscall int can_set_timing_data(const struct device *dev,
885 const struct can_timing *timing_data);
886
915__syscall int can_set_bitrate_data(const struct device *dev, uint32_t bitrate_data);
916
933int can_calc_prescaler(const struct device *dev, struct can_timing *timing,
934 uint32_t bitrate);
935
951__syscall int can_set_timing(const struct device *dev,
952 const struct can_timing *timing);
953
967__syscall int can_get_capabilities(const struct device *dev, can_mode_t *cap);
968
969static inline int z_impl_can_get_capabilities(const struct device *dev, can_mode_t *cap)
970{
971 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
972
973 return api->get_capabilities(dev, cap);
974}
975
991__syscall int can_start(const struct device *dev);
992
993static inline int z_impl_can_start(const struct device *dev)
994{
995 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
996
997 return api->start(dev);
998}
999
1015__syscall int can_stop(const struct device *dev);
1016
1017static inline int z_impl_can_stop(const struct device *dev)
1018{
1019 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
1020
1021 return api->stop(dev);
1022}
1023
1034__syscall int can_set_mode(const struct device *dev, can_mode_t mode);
1035
1036static inline int z_impl_can_set_mode(const struct device *dev, can_mode_t mode)
1037{
1038 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
1039
1040 return api->set_mode(dev, mode);
1041}
1042
1068__syscall int can_set_bitrate(const struct device *dev, uint32_t bitrate);
1069
1122__syscall int can_send(const struct device *dev, const struct can_frame *frame,
1124 void *user_data);
1125
1157static inline int can_add_rx_filter(const struct device *dev, can_rx_callback_t callback,
1158 void *user_data, const struct can_filter *filter)
1159{
1160 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
1161
1162 if (filter == NULL || (filter->flags & (CAN_FILTER_DATA | CAN_FILTER_RTR)) == 0) {
1163 return -EINVAL;
1164 }
1165
1166 return api->add_rx_filter(dev, callback, user_data, filter);
1167}
1168
1179#define CAN_MSGQ_DEFINE(name, max_frames) \
1180 K_MSGQ_DEFINE(name, sizeof(struct can_frame), max_frames, 4)
1181
1208__syscall int can_add_rx_filter_msgq(const struct device *dev, struct k_msgq *msgq,
1209 const struct can_filter *filter);
1210
1220__syscall void can_remove_rx_filter(const struct device *dev, int filter_id);
1221
1222static inline void z_impl_can_remove_rx_filter(const struct device *dev, int filter_id)
1223{
1224 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
1225
1226 return api->remove_rx_filter(dev, filter_id);
1227}
1228
1242__syscall int can_get_max_filters(const struct device *dev, bool ide);
1243
1244static inline int z_impl_can_get_max_filters(const struct device *dev, bool ide)
1245{
1246 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
1247
1248 if (api->get_max_filters == NULL) {
1249 return -ENOSYS;
1250 }
1251
1252 return api->get_max_filters(dev, ide);
1253}
1254
1276__syscall int can_get_state(const struct device *dev, enum can_state *state,
1277 struct can_bus_err_cnt *err_cnt);
1278
1279static inline int z_impl_can_get_state(const struct device *dev, enum can_state *state,
1280 struct can_bus_err_cnt *err_cnt)
1281{
1282 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
1283
1284 return api->get_state(dev, state, err_cnt);
1285}
1286
1302#if !defined(CONFIG_CAN_AUTO_BUS_OFF_RECOVERY) || defined(__DOXYGEN__)
1303__syscall int can_recover(const struct device *dev, k_timeout_t timeout);
1304
1305static inline int z_impl_can_recover(const struct device *dev, k_timeout_t timeout)
1306{
1307 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
1308
1309 return api->recover(dev, timeout);
1310}
1311#else /* CONFIG_CAN_AUTO_BUS_OFF_RECOVERY */
1312/* This implementation prevents inking errors for auto recovery */
1313static inline int z_impl_can_recover(const struct device *dev, k_timeout_t timeout)
1314{
1315 ARG_UNUSED(dev);
1316 ARG_UNUSED(timeout);
1317 return 0;
1318}
1319#endif /* !CONFIG_CAN_AUTO_BUS_OFF_RECOVERY */
1320
1334static inline void can_set_state_change_callback(const struct device *dev,
1336 void *user_data)
1337{
1338 const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
1339
1340 api->set_state_change_callback(dev, callback, user_data);
1341}
1342
1359{
1360 static const uint8_t dlc_table[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12,
1361 16, 20, 24, 32, 48, 64};
1362
1363 return dlc > 0x0F ? 64 : dlc_table[dlc];
1364}
1365
1373static inline uint8_t can_bytes_to_dlc(uint8_t num_bytes)
1374{
1375 return num_bytes <= 8 ? num_bytes :
1376 num_bytes <= 12 ? 9 :
1377 num_bytes <= 16 ? 10 :
1378 num_bytes <= 20 ? 11 :
1379 num_bytes <= 24 ? 12 :
1380 num_bytes <= 32 ? 13 :
1381 num_bytes <= 48 ? 14 :
1382 15;
1383}
1384
1392static inline bool can_frame_matches_filter(const struct can_frame *frame,
1393 const struct can_filter *filter)
1394{
1395 if ((frame->flags & CAN_FRAME_IDE) != 0 && (filter->flags & CAN_FILTER_IDE) == 0) {
1396 /* Extended (29-bit) ID frame, standard (11-bit) filter */
1397 return false;
1398 }
1399
1400 if ((frame->flags & CAN_FRAME_IDE) == 0 && (filter->flags & CAN_FILTER_IDE) != 0) {
1401 /* Standard (11-bit) ID frame, extended (29-bit) filter */
1402 return false;
1403 }
1404
1405 if ((frame->flags & CAN_FRAME_RTR) == 0 && (filter->flags & CAN_FILTER_DATA) == 0) {
1406 /* non-RTR frame, remote transmission request (RTR) filter */
1407 return false;
1408 }
1409
1410 if ((frame->flags & CAN_FRAME_RTR) != 0 && (filter->flags & CAN_FILTER_RTR) == 0) {
1411 /* Remote transmission request (RTR) frame, non-RTR filter */
1412 return false;
1413 }
1414
1415 if ((frame->flags & CAN_FRAME_FDF) != 0 && (filter->flags & CAN_FILTER_FDF) == 0) {
1416 /* CAN-FD format frame, classic format filter */
1417 return false;
1418 }
1419
1420 if ((frame->flags & CAN_FRAME_FDF) == 0 && (filter->flags & CAN_FILTER_FDF) != 0) {
1421 /* Classic frame, CAN-FD format filter */
1422 return false;
1423 }
1424
1425 if ((frame->id ^ filter->id) & filter->mask) {
1426 /* Masked ID mismatch */
1427 return false;
1428 }
1429
1430 return true;
1431}
1432
1439#ifdef __cplusplus
1440}
1441#endif
1442
1443#include <syscalls/can.h>
1444
1445#endif /* ZEPHYR_INCLUDE_DRIVERS_CAN_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
System error numbers.
static ssize_t send(int sock, const void *buf, size_t len, int flags)
Definition: socket.h:738
void(* can_state_change_callback_t)(const struct device *dev, enum can_state state, struct can_bus_err_cnt err_cnt, void *user_data)
Defines the state change callback handler function signature.
Definition: can.h:315
int can_set_bitrate(const struct device *dev, uint32_t bitrate)
Set the bitrate of the CAN controller.
int can_set_bitrate_data(const struct device *dev, uint32_t bitrate_data)
Set the bitrate for the data phase of the CAN-FD controller.
uint32_t can_mode_t
Provides a type to hold CAN controller configuration flags.
Definition: can.h:111
static int can_add_rx_filter(const struct device *dev, can_rx_callback_t callback, void *user_data, const struct can_filter *filter)
Add a callback function for a given CAN filter.
Definition: can.h:1157
#define CAN_FILTER_FDF
Definition: can.h:206
int can_stop(const struct device *dev)
Stop the CAN controller.
int can_set_timing(const struct device *dev, const struct can_timing *timing)
Configure the bus timing of a CAN controller.
#define CAN_FRAME_FDF
Definition: can.h:143
int can_calc_timing_data(const struct device *dev, struct can_timing *res, uint32_t bitrate, uint16_t sample_pnt)
Calculate timing parameters for the data phase.
int can_send(const struct device *dev, const struct can_frame *frame, k_timeout_t timeout, can_tx_callback_t callback, void *user_data)
Queue a CAN frame for transmission on the CAN bus.
const struct can_timing * can_get_timing_data_max(const struct device *dev)
Get the maximum supported timing parameter values for the data phase.
int can_get_core_clock(const struct device *dev, uint32_t *rate)
Get the CAN core clock rate.
int can_get_capabilities(const struct device *dev, can_mode_t *cap)
Get the supported modes of the CAN controller.
int can_get_max_filters(const struct device *dev, bool ide)
Get maximum number of RX filters.
const struct can_timing * can_get_timing_min(const struct device *dev)
Get the minimum supported timing parameter values.
int can_set_timing_data(const struct device *dev, const struct can_timing *timing_data)
Configure the bus timing for the data phase of a CAN-FD controller.
const struct can_timing * can_get_timing_data_min(const struct device *dev)
Get the minimum supported timing parameter values for the data phase.
int can_calc_prescaler(const struct device *dev, struct can_timing *timing, uint32_t bitrate)
Fill in the prescaler value for a given bitrate and timing.
void can_remove_rx_filter(const struct device *dev, int filter_id)
Remove a CAN RX filter.
static uint8_t can_bytes_to_dlc(uint8_t num_bytes)
Convert from number of bytes to Data Length Code (DLC)
Definition: can.h:1373
int can_get_max_bitrate(const struct device *dev, uint32_t *max_bitrate)
Get maximum supported bitrate.
#define CAN_FILTER_RTR
Definition: can.h:200
#define CAN_FRAME_IDE
Definition: can.h:137
static uint8_t can_dlc_to_bytes(uint8_t dlc)
Convert from Data Length Code (DLC) to the number of data bytes.
Definition: can.h:1358
#define CAN_FILTER_DATA
Definition: can.h:203
int can_add_rx_filter_msgq(const struct device *dev, struct k_msgq *msgq, const struct can_filter *filter)
Simple wrapper function for adding a message queue for a given filter.
void(* can_rx_callback_t)(const struct device *dev, struct can_frame *frame, void *user_data)
Defines the application callback handler function signature for receiving.
Definition: can.h:304
static bool can_frame_matches_filter(const struct can_frame *frame, const struct can_filter *filter)
Check if a CAN frame matches a CAN filter.
Definition: can.h:1392
void(* can_tx_callback_t)(const struct device *dev, int error, void *user_data)
Defines the application callback handler function signature.
Definition: can.h:295
int can_get_state(const struct device *dev, enum can_state *state, struct can_bus_err_cnt *err_cnt)
Get current CAN controller state.
const struct can_timing * can_get_timing_max(const struct device *dev)
Get the maximum supported timing parameter values.
int can_calc_timing(const struct device *dev, struct can_timing *res, uint32_t bitrate, uint16_t sample_pnt)
Calculate timing parameters from bitrate and sample point.
int can_recover(const struct device *dev, k_timeout_t timeout)
Recover from bus-off state.
can_state
Defines the state of the CAN controller.
Definition: can.h:116
static void can_set_state_change_callback(const struct device *dev, can_state_change_callback_t callback, void *user_data)
Set a callback for CAN controller state change events.
Definition: can.h:1334
int can_set_mode(const struct device *dev, can_mode_t mode)
Set the CAN controller to the given operation mode.
int can_start(const struct device *dev)
Start the CAN controller.
#define CAN_FRAME_RTR
Definition: can.h:140
#define CAN_FILTER_IDE
Definition: can.h:197
@ CAN_STATE_ERROR_ACTIVE
Definition: can.h:118
@ CAN_STATE_ERROR_WARNING
Definition: can.h:120
@ CAN_STATE_STOPPED
Definition: can.h:126
@ CAN_STATE_BUS_OFF
Definition: can.h:124
@ CAN_STATE_ERROR_PASSIVE
Definition: can.h:122
#define DIV_ROUND_UP(n, d)
Divide and round up.
Definition: util.h:262
#define EINVAL
Definition: errno.h:61
#define ENOSYS
Definition: errno.h:83
Public kernel APIs.
Variables needed for system clock.
struct k_msgq msgq
Definition: test_msgq_contexts.c:12
state
Definition: parser_state.h:29
Statistics.
#define STATS_NAME_END(name__)
Definition: stats.h:391
#define STATS_NAME(name__, entry__)
Definition: stats.h:390
#define STATS_SECT_END
Ends a stats group struct definition.
Definition: stats.h:89
#define STATS_SECT_ENTRY32(var__)
Definition: stats.h:359
#define STATS_NAME_START(name__)
Definition: stats.h:389
#define STATS_SECT_START(group__)
Definition: stats.h:354
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
CAN controller error counters.
Definition: can.h:230
uint8_t tx_err_cnt
Definition: can.h:232
uint8_t rx_err_cnt
Definition: can.h:234
CAN specific device state which allows for CAN device class specific additions.
Definition: can.h:494
struct device_state devstate
Definition: can.h:495
struct stats_can stats
Definition: can.h:496
CAN filter structure.
Definition: can.h:213
uint32_t mask
Definition: can.h:222
uint8_t flags
Definition: can.h:224
uint32_t id
Definition: can.h:215
CAN frame structure.
Definition: can.h:158
uint8_t dlc
Definition: can.h:165
uint8_t flags
Definition: can.h:167
uint32_t id
Definition: can.h:160
uint8_t data[CAN_MAX_DLEN]
Definition: can.h:184
uint32_t data_32[DIV_ROUND_UP(CAN_MAX_DLEN, sizeof(uint32_t))]
Definition: can.h:185
uint16_t timestamp
Definition: can.h:176
CAN bus timing structure.
Definition: can.h:274
uint16_t sjw
Definition: can.h:276
uint16_t phase_seg2
Definition: can.h:282
uint16_t prescaler
Definition: can.h:284
uint16_t phase_seg1
Definition: can.h:280
uint16_t prop_seg
Definition: can.h:278
Runtime device dynamic structure (in RAM) per driver instance.
Definition: device.h:353
Runtime device structure (in ROM) per driver instance.
Definition: device.h:380
const void * api
Definition: device.h:386
Message Queue Structure.
Definition: kernel.h:4306
Kernel timeout type.
Definition: sys_clock.h:65
static const intptr_t user_data[5]
Definition: main.c:588
Misc utilities.