candev.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
6  * more details.
7  */
8 
24 #ifndef CAN_CANDEV_H
25 #define CAN_CANDEV_H
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include <stdint.h>
32 #include <stdlib.h>
33 
34 #include "can/can.h"
35 #include "can/common.h"
36 #include "mutex.h"
37 
42 typedef enum {
54  /* expand this list if needed */
56 
60 typedef struct candev candev_t;
61 
69 typedef void (*candev_event_cb_t)(candev_t *dev, candev_event_t event, void *arg);
70 
77 struct candev {
78  const struct candev_driver *driver;
80  void *isr_arg;
81  struct can_bittiming bittiming;
82  enum can_state state;
83 #ifdef MODULE_FDCAN
84  struct can_bittiming fd_data_bittiming;
85  uint16_t loop_delay;
86 #endif
87 };
88 
92 typedef struct candev_driver {
102  int (*send)(candev_t *dev, const can_frame_t *frame);
103 
113  int (*abort)(candev_t *dev, const can_frame_t *frame);
114 
122  int (*init)(candev_t *dev);
123 
129  void (*isr)(candev_t *dev);
130 
142  int (*get)(candev_t *dev, canopt_t opt, void *value, size_t max_len);
143 
155  int (*set)(candev_t *dev, canopt_t opt, void *value, size_t value_len);
156 
166  int (*set_filter)(candev_t *dev, const struct can_filter *filter);
167 
177  int (*remove_filter)(candev_t *dev, const struct can_filter *filter);
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif /* CAN_CANDEV_H */
struct candev_driver candev_driver_t
Structure to hold driver interface -> function mapping.
void(* candev_event_cb_t)(candev_t *dev, candev_event_t event, void *arg)
Event callback for signaling event to upper layers.
Definition: candev.h:69
candev_event_t
Possible event types that are sent from the device driver to the upper layer.
Definition: candev.h:42
@ CANDEV_EVENT_RX_ERROR
there was an error when receiving
Definition: candev.h:50
@ CANDEV_EVENT_TX_CONFIRMATION
a packet has been sent
Definition: candev.h:46
@ CANDEV_EVENT_ISR
driver needs its ISR handled
Definition: candev.h:44
@ CANDEV_EVENT_TX_ERROR
there was an error when transmitting
Definition: candev.h:49
@ CANDEV_EVENT_WAKE_UP
driver has been woken up by bus
Definition: candev.h:45
@ CANDEV_EVENT_NOEVENT
no event, used internally
Definition: candev.h:43
@ CANDEV_EVENT_RX_INDICATION
a packet has been received
Definition: candev.h:48
@ CANDEV_EVENT_TIMEOUT_TX_CONF
tx conf timeout received
Definition: candev.h:47
@ CANDEV_EVENT_BUS_OFF
bus-off detected
Definition: candev.h:51
@ CANDEV_EVENT_ERROR_PASSIVE
driver switched in error passive
Definition: candev.h:52
@ CANDEV_EVENT_ERROR_WARNING
driver reached error warning
Definition: candev.h:53
canopt_t
CAN options.
Definition: common.h:54
can_state
CAN operational and error states.
Definition: can.h:78
Mutex for thread synchronization.
CAN bit-timing parameters.
Definition: can.h:144
Controller Area Network filter.
Definition: can.h:129
Controller Area Network frame.
Definition: can.h:101
Structure to hold driver interface -> function mapping.
Definition: candev.h:92
int(* set_filter)(candev_t *dev, const struct can_filter *filter)
Set a receive filter.
Definition: candev.h:166
int(* get)(candev_t *dev, canopt_t opt, void *value, size_t max_len)
Get an option value from a given CAN device.
Definition: candev.h:142
int(* send)(candev_t *dev, const can_frame_t *frame)
Send packet.
Definition: candev.h:102
int(* set)(candev_t *dev, canopt_t opt, void *value, size_t value_len)
Set an option value for a given CAN device.
Definition: candev.h:155
int(* abort)(candev_t *dev, const can_frame_t *frame)
Abort a packet sending.
Definition: candev.h:113
int(* init)(candev_t *dev)
the driver's initialization function
Definition: candev.h:122
void(* isr)(candev_t *dev)
a driver's user-space ISR handler
Definition: candev.h:129
int(* remove_filter)(candev_t *dev, const struct can_filter *filter)
Remove a filter.
Definition: candev.h:177
Structure to hold driver state.
Definition: candev.h:77
const struct candev_driver * driver
ptr to that driver's interface.
Definition: candev.h:78
candev_event_cb_t event_callback
callback for device events
Definition: candev.h:79
enum can_state state
device state
Definition: candev.h:82
struct can_bittiming bittiming
device bittimings
Definition: candev.h:81
void * isr_arg
argument to pass on isr event
Definition: candev.h:80
event structure
Definition: event.h:148
Definitions high-level CAN interface.
Definitions of high-level CAN interface.