device.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 OTA keys S.A.
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
20 #ifndef CAN_DEVICE_H
21 #define CAN_DEVICE_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include "can/candev.h"
28 #include "sched.h"
29 
30 #ifdef MODULE_CAN_PM
31 #include "ztimer.h"
32 #endif
33 #ifdef MODULE_CAN_TRX
34 #include "can/can_trx.h"
35 #endif
36 
37 #ifndef CAN_MAX_RATE_ERROR
42 #define CAN_MAX_RATE_ERROR (50) /* 5 % */
43 #endif
44 
45 #ifndef CAN_DLL_NUMOF
49 #define CAN_DLL_NUMOF (1)
50 #endif
51 
55 typedef struct candev_params {
56  const char *name;
57 #if defined(MODULE_CAN_TRX) || defined(DOXYGEN)
59 #endif
60 #if defined(MODULE_FDCAN)
61  uint16_t loop_delay;
62 #endif
63 #if defined(MODULE_CAN_PM) || defined(DOXYGEN)
65  uint32_t tx_wakeup_timeout;
66 #endif
68 
72 typedef struct candev_dev {
74  int ifnum;
76  const char *name;
77 #if defined(MODULE_CAN_TRX) || defined(DOXYGEN)
79 #endif
80 #if defined(MODULE_FDCAN)
81  uint16_t loop_delay;
82 #endif
83 #if defined(MODULE_CAN_PM) || defined(DOXYGEN)
85  uint32_t tx_wakeup_timeout;
86  uint32_t last_pm_update;
87  uint32_t last_pm_value;
89 #endif
91 
105 kernel_pid_t can_device_init(char *stack, int stacksize, char priority,
106  const char *name, candev_dev_t *params);
107 
118 int can_device_calc_bittiming(uint32_t clock, const struct can_bittiming_const *timing_const,
119  struct can_bittiming *bittiming);
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif /* CAN_DEVICE_H */
126 
CAN generic transceiver interface.
Definitions for low-level CAN driver interface.
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:139
Scheduler API definition.
CAN hardware-dependent bit-timing constant.
Definition: can.h:160
CAN bit-timing parameters.
Definition: can.h:144
Generic transceiver descriptor.
Definition: can_trx.h:48
candev descriptor to pass to the device thread
Definition: device.h:72
int ifnum
interface number
Definition: device.h:74
candev_t * dev
the device
Definition: device.h:73
uint32_t last_pm_update
time when the pm was updated
Definition: device.h:86
const char * name
device name
Definition: device.h:76
kernel_pid_t pid
pid
Definition: device.h:75
uint32_t last_pm_value
last pm timer value set
Definition: device.h:87
uint32_t tx_wakeup_timeout
Min timeout loaded when a frame is sent.
Definition: device.h:85
ztimer_t pm_timer
timer for power management
Definition: device.h:88
uint32_t rx_inactivity_timeout
Min timeout loaded when a frame is received.
Definition: device.h:84
can_trx_t * trx
transceiver attached to the device
Definition: device.h:78
Parameters to initialize a candev.
Definition: device.h:55
uint32_t tx_wakeup_timeout
power management tx wake up value
Definition: device.h:65
uint32_t rx_inactivity_timeout
power management rx timeout value
Definition: device.h:64
can_trx_t * trx
transceiver to set
Definition: device.h:58
const char * name
candev name to set
Definition: device.h:56
Structure to hold driver state.
Definition: candev.h:77
ztimer structure
Definition: ztimer.h:319
kernel_pid_t can_device_init(char *stack, int stacksize, char priority, const char *name, candev_dev_t *params)
Initialize a CAN device thread.
int can_device_calc_bittiming(uint32_t clock, const struct can_bittiming_const *timing_const, struct can_bittiming *bittiming)
Fill in a bittiming structure from bittiming->bitrate and timing_const.
struct candev_params candev_params_t
Parameters to initialize a candev.
struct candev_dev candev_dev_t
candev descriptor to pass to the device thread
ztimer API