Loading...
Searching...
No Matches
candev.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 OTA keys S.A.
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <stdint.h>
28#include <stdlib.h>
29
30#include "can/can.h"
31#include "can/common.h"
32#include "mutex.h"
33
52
56typedef struct candev candev_t;
57
65typedef void (*candev_event_cb_t)(candev_t *dev, candev_event_t event, void *arg);
66
73struct candev {
74 const struct candev_driver *driver;
76 void *isr_arg;
79#ifdef MODULE_FDCAN
80 struct can_bittiming fd_data_bittiming;
81 uint16_t loop_delay;
82#endif
83};
84
88typedef struct candev_driver {
98 int (*send)(candev_t *dev, const can_frame_t *frame);
99
109 int (*abort)(candev_t *dev, const can_frame_t *frame);
110
118 int (*init)(candev_t *dev);
119
125 void (*isr)(candev_t *dev);
126
138 int (*get)(candev_t *dev, canopt_t opt, void *value, size_t max_len);
139
151 int (*set)(candev_t *dev, canopt_t opt, void *value, size_t value_len);
152
162 int (*set_filter)(candev_t *dev, const struct can_filter *filter);
163
173 int (*remove_filter)(candev_t *dev, const struct can_filter *filter);
175
176#ifdef __cplusplus
177}
178#endif
179
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:65
candev_event_t
Possible event types that are sent from the device driver to the upper layer.
Definition candev.h:38
struct candev candev_t
Forward declaration for candev struct.
Definition candev.h:56
@ CANDEV_EVENT_RX_ERROR
there was an error when receiving
Definition candev.h:46
@ CANDEV_EVENT_TX_CONFIRMATION
a packet has been sent
Definition candev.h:42
@ CANDEV_EVENT_ISR
driver needs its ISR handled
Definition candev.h:40
@ CANDEV_EVENT_TX_ERROR
there was an error when transmitting
Definition candev.h:45
@ CANDEV_EVENT_WAKE_UP
driver has been woken up by bus
Definition candev.h:41
@ CANDEV_EVENT_NOEVENT
no event, used internally
Definition candev.h:39
@ CANDEV_EVENT_RX_INDICATION
a packet has been received
Definition candev.h:44
@ CANDEV_EVENT_TIMEOUT_TX_CONF
tx conf timeout received
Definition candev.h:43
@ CANDEV_EVENT_BUS_OFF
bus-off detected
Definition candev.h:47
@ CANDEV_EVENT_ERROR_PASSIVE
driver switched in error passive
Definition candev.h:48
@ CANDEV_EVENT_ERROR_WARNING
driver reached error warning
Definition candev.h:49
canopt_t
CAN options.
Definition common.h:53
struct can_frame can_frame_t
CAN frame.
Definition can.h:178
can_state
CAN operational and error states.
Definition can.h:77
Mutex for thread synchronization.
CAN bit-timing parameters.
Definition can.h:143
Controller Area Network filter.
Definition can.h:128
Structure to hold driver interface -> function mapping.
Definition candev.h:88
int(* set_filter)(candev_t *dev, const struct can_filter *filter)
Set a receive filter.
Definition candev.h:162
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:138
int(* send)(candev_t *dev, const can_frame_t *frame)
Send packet.
Definition candev.h:98
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:151
int(* abort)(candev_t *dev, const can_frame_t *frame)
Abort a packet sending.
Definition candev.h:109
int(* init)(candev_t *dev)
the driver's initialization function
Definition candev.h:118
void(* isr)(candev_t *dev)
a driver's user-space ISR handler
Definition candev.h:125
int(* remove_filter)(candev_t *dev, const struct can_filter *filter)
Remove a filter.
Definition candev.h:173
Structure to hold driver state.
Definition candev.h:73
const struct candev_driver * driver
ptr to that driver's interface.
Definition candev.h:74
candev_event_cb_t event_callback
callback for device events
Definition candev.h:75
enum can_state state
device state
Definition candev.h:78
struct can_bittiming bittiming
device bittimings
Definition candev.h:77
void * isr_arg
argument to pass on isr event
Definition candev.h:76
event structure
Definition event.h:145
Definitions high-level CAN interface.
Definitions of high-level CAN interface.