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 
38 
43 typedef enum {
55  /* expand this list if needed */
57 
61 typedef struct candev candev_t;
62 
70 typedef void (*candev_event_cb_t)(candev_t *dev, candev_event_t event, void *arg);
71 
78 struct candev {
79  const struct candev_driver *driver;
81  void *isr_arg;
84 };
85 
89 typedef struct candev_driver {
99  int (*send)(candev_t *dev, const struct can_frame *frame);
100 
110  int (*abort)(candev_t *dev, const struct can_frame *frame);
111 
119  int (*init)(candev_t *dev);
120 
126  void (*isr)(candev_t *dev);
127 
139  int (*get)(candev_t *dev, canopt_t opt, void *value, size_t max_len);
140 
152  int (*set)(candev_t *dev, canopt_t opt, void *value, size_t value_len);
153 
163  int (*set_filter)(candev_t *dev, const struct can_filter *filter);
164 
174  int (*remove_filter)(candev_t *dev, const struct can_filter *filter);
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 #endif /* CAN_CANDEV_H */
182 
candev_event_cb_t
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:70
candev_driver::set_filter
int(* set_filter)(candev_t *dev, const struct can_filter *filter)
Set a receive filter.
Definition: candev.h:163
candev_driver_t
struct candev_driver candev_driver_t
Structure to hold driver interface -> function mapping.
candev_driver::abort
int(* abort)(candev_t *dev, const struct can_frame *frame)
Abort a packet sending.
Definition: candev.h:110
candev
Structure to hold driver state.
Definition: candev.h:78
candev::state
enum can_state state
device state
Definition: candev.h:83
candev::event_callback
candev_event_cb_t event_callback
callback for device events
Definition: candev.h:80
candev_event_t
candev_event_t
Possible event types that are sent from the device driver to the upper layer.
Definition: candev.h:43
candev::driver
const struct candev_driver * driver
ptr to that driver's interface.
Definition: candev.h:79
event
event structure
Definition: event.h:142
can.h
Definitions high-level CAN interface.
candev_driver::set
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:152
candev::isr_arg
void * isr_arg
argument to pass on isr event
Definition: candev.h:81
can_filter
Controller Area Network filter.
Definition: can.h:101
CANDEV_EVENT_TIMEOUT_TX_CONF
@ CANDEV_EVENT_TIMEOUT_TX_CONF
tx conf timeout received
Definition: candev.h:48
common.h
Definitions of high-level CAN interface.
candev_driver::init
int(* init)(candev_t *dev)
the driver's initialization function
Definition: candev.h:119
candev::bittiming
struct can_bittiming bittiming
device bittimings
Definition: candev.h:82
CANDEV_EVENT_TX_CONFIRMATION
@ CANDEV_EVENT_TX_CONFIRMATION
a packet has been sent
Definition: candev.h:47
can_frame
Controller Area Network frame.
Definition: can.h:88
CANDEV_EVENT_NOEVENT
@ CANDEV_EVENT_NOEVENT
no event, used internally
Definition: candev.h:44
can_state
can_state
CAN operational and error states.
Definition: can.h:65
candev_driver::isr
void(* isr)(candev_t *dev)
a driver's user-space ISR handler
Definition: candev.h:126
CANDEV_EVENT_ERROR_WARNING
@ CANDEV_EVENT_ERROR_WARNING
driver reached error warning
Definition: candev.h:54
canopt_t
canopt_t
CAN options.
Definition: common.h:45
CANDEV_EVENT_RX_INDICATION
@ CANDEV_EVENT_RX_INDICATION
a packet has been received
Definition: candev.h:49
mutex.h
Mutex for thread synchronization.
candev_driver
Structure to hold driver interface -> function mapping.
Definition: candev.h:89
candev_driver::send
int(* send)(candev_t *dev, const struct can_frame *frame)
Send packet.
Definition: candev.h:99
can_bittiming
CAN bit-timing parameters.
Definition: can.h:113
CANDEV_EVENT_ISR
@ CANDEV_EVENT_ISR
driver needs its ISR handled
Definition: candev.h:45
candev_driver::remove_filter
int(* remove_filter)(candev_t *dev, const struct can_filter *filter)
Remove a filter.
Definition: candev.h:174
CANDEV_EVENT_BUS_OFF
@ CANDEV_EVENT_BUS_OFF
bus-off detected
Definition: candev.h:52
CANDEV_EVENT_ERROR_PASSIVE
@ CANDEV_EVENT_ERROR_PASSIVE
driver switched in error passive
Definition: candev.h:53
CANDEV_EVENT_RX_ERROR
@ CANDEV_EVENT_RX_ERROR
there was an error when receiving
Definition: candev.h:51
candev_driver::get
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:139
CANDEV_EVENT_TX_ERROR
@ CANDEV_EVENT_TX_ERROR
there was an error when transmitting
Definition: candev.h:50
CANDEV_EVENT_WAKE_UP
@ CANDEV_EVENT_WAKE_UP
driver has been woken up by bus
Definition: candev.h:46