Loading...
Searching...
No Matches
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
9#pragma once
10
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <stdint.h>
31#include <stdlib.h>
32
33#include "can/can.h"
34#include "can/common.h"
35#include "mutex.h"
36
55
59typedef struct candev candev_t;
60
68typedef void (*candev_event_cb_t)(candev_t *dev, candev_event_t event, void *arg);
69
76struct candev {
77 const struct candev_driver *driver;
79 void *isr_arg;
82#ifdef MODULE_FDCAN
83 struct can_bittiming fd_data_bittiming;
84 uint16_t loop_delay;
85#endif
86};
87
91typedef struct candev_driver {
101 int (*send)(candev_t *dev, const can_frame_t *frame);
102
112 int (*abort)(candev_t *dev, const can_frame_t *frame);
113
121 int (*init)(candev_t *dev);
122
128 void (*isr)(candev_t *dev);
129
141 int (*get)(candev_t *dev, canopt_t opt, void *value, size_t max_len);
142
154 int (*set)(candev_t *dev, canopt_t opt, void *value, size_t value_len);
155
165 int (*set_filter)(candev_t *dev, const struct can_filter *filter);
166
176 int (*remove_filter)(candev_t *dev, const struct can_filter *filter);
178
179#ifdef __cplusplus
180}
181#endif
182
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:68
candev_event_t
Possible event types that are sent from the device driver to the upper layer.
Definition candev.h:41
struct candev candev_t
Forward declaration for candev struct.
Definition candev.h:59
@ CANDEV_EVENT_RX_ERROR
there was an error when receiving
Definition candev.h:49
@ CANDEV_EVENT_TX_CONFIRMATION
a packet has been sent
Definition candev.h:45
@ CANDEV_EVENT_ISR
driver needs its ISR handled
Definition candev.h:43
@ CANDEV_EVENT_TX_ERROR
there was an error when transmitting
Definition candev.h:48
@ CANDEV_EVENT_WAKE_UP
driver has been woken up by bus
Definition candev.h:44
@ CANDEV_EVENT_NOEVENT
no event, used internally
Definition candev.h:42
@ CANDEV_EVENT_RX_INDICATION
a packet has been received
Definition candev.h:47
@ CANDEV_EVENT_TIMEOUT_TX_CONF
tx conf timeout received
Definition candev.h:46
@ CANDEV_EVENT_BUS_OFF
bus-off detected
Definition candev.h:50
@ CANDEV_EVENT_ERROR_PASSIVE
driver switched in error passive
Definition candev.h:51
@ CANDEV_EVENT_ERROR_WARNING
driver reached error warning
Definition candev.h:52
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:91
int(* set_filter)(candev_t *dev, const struct can_filter *filter)
Set a receive filter.
Definition candev.h:165
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:141
int(* send)(candev_t *dev, const can_frame_t *frame)
Send packet.
Definition candev.h:101
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:154
int(* abort)(candev_t *dev, const can_frame_t *frame)
Abort a packet sending.
Definition candev.h:112
int(* init)(candev_t *dev)
the driver's initialization function
Definition candev.h:121
void(* isr)(candev_t *dev)
a driver's user-space ISR handler
Definition candev.h:128
int(* remove_filter)(candev_t *dev, const struct can_filter *filter)
Remove a filter.
Definition candev.h:176
Structure to hold driver state.
Definition candev.h:76
const struct candev_driver * driver
ptr to that driver's interface.
Definition candev.h:77
candev_event_cb_t event_callback
callback for device events
Definition candev.h:78
enum can_state state
device state
Definition candev.h:81
struct can_bittiming bittiming
device bittimings
Definition candev.h:80
void * isr_arg
argument to pass on isr event
Definition candev.h:79
event structure
Definition event.h:145
Definitions high-level CAN interface.
Definitions of high-level CAN interface.