common.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 
26 #ifndef CAN_COMMON_H
27 #define CAN_COMMON_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <stdint.h>
34 #include <sys/uio.h>
35 
36 #include "timex.h"
37 #include "thread.h"
38 #ifdef MODULE_CAN_MBOX
39 #include "mbox.h"
40 #endif
41 
45 typedef enum {
54 } canopt_t;
55 
61 typedef enum {
67 
68 
72 typedef struct {
74  uint16_t context;
75  void *data;
76  uint16_t data_len;
77 } can_opt_t;
78 
82 enum can_msg {
83  /* High level messages */
84  CAN_MSG_ACK = 0x100,
93 #if defined(MODULE_CAN_TRX) || defined(DOXYGEN)
95 #endif
96  /* candev internal messages */
97  CAN_MSG_EVENT = 0x200,
106 #if defined(MODULE_CAN_PM) || defined(DOXYGEN)
108 #endif
109  /* isotp messages */
110 #if defined(MODULE_CAN_ISOTP) || defined(DOXYGEN)
113 #endif
114 };
115 
122 typedef struct can_rx_data {
123  struct iovec data;
124  void *arg;
125 } can_rx_data_t;
126 
130 typedef enum {
132 #if defined(MODULE_CAN_MBOX) || defined(DOXYGEN)
134 #endif
136 
143 typedef struct can_reg_entry {
144  struct can_reg_entry *next;
145  int ifnum;
146  union {
148 #if defined(MODULE_CAN_MBOX) || defined(DOXYGEN)
150 #endif
151  } target;
152 #if defined(MODULE_CAN_MBOX) || defined(DOXYGEN)
154 #endif
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif /* CAN_COMMON_H */
162 
canopt_state_t
canopt_state_t
CAN state options.
Definition: common.h:61
kernel_pid_t
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:125
CANOPT_STATE_ON
@ CANOPT_STATE_ON
power on, rx / tx mode
Definition: common.h:65
CANOPT_CLOCK
@ CANOPT_CLOCK
controller main clock
Definition: common.h:51
can_opt_t::context
uint16_t context
(optional) context for that option
Definition: common.h:74
CANOPT_STATE_OFF
@ CANOPT_STATE_OFF
powered off
Definition: common.h:62
can_rx_data
Received data structure.
Definition: common.h:122
CANOPT_LEC
@ CANOPT_LEC
Last Error Code.
Definition: common.h:50
CAN_MSG_EVENT
@ CAN_MSG_EVENT
driver event
Definition: common.h:97
can_reg_entry::ifnum
int ifnum
interface number for the entry
Definition: common.h:145
CAN_MSG_ERROR_PASSIVE
@ CAN_MSG_ERROR_PASSIVE
driver switched in error passive
Definition: common.h:104
CAN_MSG_ERROR_WARNING
@ CAN_MSG_ERROR_WARNING
driver reached error warning
Definition: common.h:105
can_reg_entry::next
struct can_reg_entry * next
next for linked list
Definition: common.h:144
can_opt_t::opt
canopt_t opt
the option to get/set
Definition: common.h:73
can_reg_type_t
can_reg_type_t
registry entry types
Definition: common.h:130
CANOPT_BITTIMING_CONST
@ CANOPT_BITTIMING_CONST
controller bittiming parameters
Definition: common.h:52
CAN_MSG_ACK
@ CAN_MSG_ACK
acknowledgment
Definition: common.h:84
CANOPT_STATE
@ CANOPT_STATE
set controller state canopt_state_t
Definition: common.h:53
can_msg
can_msg
Messages which can be sent through the CAN stack.
Definition: common.h:82
CAN_MSG_TX_ERROR
@ CAN_MSG_TX_ERROR
there was an error when transmitting
Definition: common.h:101
can_reg_entry::pid
kernel_pid_t pid
pid of the thread when using msg
Definition: common.h:147
timex.h
Utility library for comparing and computing timestamps.
can_reg_entry::mbox
mbox_t * mbox
mbox pointer
Definition: common.h:149
can_rx_data_t
struct can_rx_data can_rx_data_t
Received data structure.
mbox_t
Mailbox struct definition.
Definition: mbox.h:41
can_rx_data::data
struct iovec data
iovec containing received data
Definition: common.h:123
mbox.h
Mailbox API.
CAN_MSG_WAKE_UP
@ CAN_MSG_WAKE_UP
driver has been woken up by bus
Definition: common.h:98
CAN_MSG_SET_TRX
@ CAN_MSG_SET_TRX
set a transceiver
Definition: common.h:94
can_opt_t::data_len
uint16_t data_len
size of the data / the buffer
Definition: common.h:76
CAN_MSG_TX_CONFIRMATION
@ CAN_MSG_TX_CONFIRMATION
a frame has been sent
Definition: common.h:99
CAN_MSG_RX_ERROR
@ CAN_MSG_RX_ERROR
there was an error when receiving
Definition: common.h:102
uio.h
libc header for scatter/gather I/O
CANOPT_RX_FILTERS
@ CANOPT_RX_FILTERS
rx filters
Definition: common.h:47
CANOPT_STATE_SLEEP
@ CANOPT_STATE_SLEEP
sleep mode
Definition: common.h:63
CAN_MSG_SET
@ CAN_MSG_SET
set an option
Definition: common.h:87
CAN_MSG_RX_INDICATION
@ CAN_MSG_RX_INDICATION
a frame has been received
Definition: common.h:100
CAN_MSG_ISOTP_RX_TIMEOUT
@ CAN_MSG_ISOTP_RX_TIMEOUT
isotp rx timeout
Definition: common.h:111
CAN_MSG_POWER_UP
@ CAN_MSG_POWER_UP
power up
Definition: common.h:91
CANOPT_BITTIMING
@ CANOPT_BITTIMING
bit timing parameter
Definition: common.h:46
canopt_t
canopt_t
CAN options.
Definition: common.h:45
iovec
Structure for scatter/gather I/O.
Definition: uio.h:33
CAN_MSG_POWER_DOWN
@ CAN_MSG_POWER_DOWN
power down
Definition: common.h:92
CAN_MSG_ABORT_FRAME
@ CAN_MSG_ABORT_FRAME
abort a frame
Definition: common.h:86
CANOPT_STATE_LISTEN_ONLY
@ CANOPT_STATE_LISTEN_ONLY
listen only mode
Definition: common.h:64
CAN_MSG_REMOVE_FILTER
@ CAN_MSG_REMOVE_FILTER
remove a filter
Definition: common.h:90
can_rx_data::arg
void * arg
upper layer private param
Definition: common.h:124
CANOPT_TEC
@ CANOPT_TEC
Transmit Error Counter.
Definition: common.h:48
CAN_MSG_SEND_FRAME
@ CAN_MSG_SEND_FRAME
send a frame
Definition: common.h:85
can_reg_entry
registry entry
Definition: common.h:143
can_reg_entry_t
struct can_reg_entry can_reg_entry_t
registry entry
CAN_MSG_GET
@ CAN_MSG_GET
get an option
Definition: common.h:88
can_reg_entry::target
union can_reg_entry::@249 target
entry target
CAN_MSG_BUS_OFF
@ CAN_MSG_BUS_OFF
bus-off detected
Definition: common.h:103
can_opt_t
Structure to pass a CAN option.
Definition: common.h:72
CAN_MSG_ISOTP_TX_TIMEOUT
@ CAN_MSG_ISOTP_TX_TIMEOUT
isotp tx timeout
Definition: common.h:112
CANOPT_REC
@ CANOPT_REC
Receive Error Counter.
Definition: common.h:49
CAN_TYPE_DEFAULT
@ CAN_TYPE_DEFAULT
default entry (use msg)
Definition: common.h:131
CAN_MSG_SET_FILTER
@ CAN_MSG_SET_FILTER
set a filter
Definition: common.h:89
CAN_TYPE_MBOX
@ CAN_TYPE_MBOX
mbox entry
Definition: common.h:133
CAN_MSG_PM
@ CAN_MSG_PM
power management event
Definition: common.h:107
can_reg_entry::type
can_reg_type_t type
entry type
Definition: common.h:153
can_opt_t::data
void * data
data to set or buffer to read into
Definition: common.h:75