RTEMS CAN/CAN FD Stack
Loading...
Searching...
No Matches
can.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0 OR GPL-2.0-or-later */
2
13/*
14 * Copyright (C) 2023-2024 Michal Lenc <michallenc@seznam.cz>
15 * Implementation is based on original LinCAN - Linux CAN bus driver
16 * Part of OrtCAN project https://ortcan.sourceforge.net/
17 * Copyright (C) 2002-2009 DCE FEE CTU Prague <http://control.fel.cvut.cz>
18 * Copyright (C) 2002-2024 Pavel Pisa <pisa@cmp.felk.cvut.cz>
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#ifndef _DEV_CAN_CAN_H
43#define _DEV_CAN_CAN_H
44
45#include <sys/queue.h>
46
47#include <stdatomic.h>
48#include <rtems.h>
49#include <rtems/seterr.h>
50#include <rtems/thread.h>
51#include <sys/ioccom.h>
52
53#include <dev/can/can-stats.h>
55#include <dev/can/can-frame.h>
56#include <dev/can/can-filter.h>
57
58#define CAN_IOC_MAGIC 'd'
59
78#define RTEMS_CHIP_FLAGS_CONFIGURED ( 1 << 0 )
83#define RTEMS_CHIP_FLAGS_RUNNING ( 1 << 1 )
88#define RTEMS_CHIP_FLAGS_FDCAPABLE ( 1 << 2 )
89
104#define RTEMS_CAN_CHIP_BITRATE ( 1 )
109#define RTEMS_CAN_CHIP_DBITRATE ( 2 )
114#define RTEMS_CAN_CHIP_NUSERS ( 3 )
120#define RTEMS_CAN_CHIP_FLAGS ( 4 )
125#define RTEMS_CAN_CHIP_MODE ( 5 )
130#define RTEMS_CAN_CHIP_MODE_SUPPORTED ( 6 )
131
145#define RTEMS_CAN_QUEUE_RX ( 1 << 0 )
150#define RTEMS_CAN_QUEUE_TX ( 1 << 1 )
151
166#define CAN_CTRLMODE_LOOPBACK ( 1 << 0 )
171#define CAN_CTRLMODE_LISTENONLY ( 1 << 1 )
176#define CAN_CTRLMODE_3_SAMPLES ( 1 << 2 )
181#define CAN_CTRLMODE_ONE_SHOT ( 1 << 3 )
186#define CAN_CTRLMODE_BERR_REPORTING ( 1 << 4 )
191#define CAN_CTRLMODE_FD ( 1 << 5 )
196#define CAN_CTRLMODE_PRESUME_ACK ( 1 << 6 )
201#define CAN_CTRLMODE_FD_NON_ISO ( 1 << 7 )
206#define CAN_CTRLMODE_CC_LEN8_DLC ( 1 << 8 )
211#define CAN_CTRLMODE_TDC_AUTO ( 1 << 9 )
216#define CAN_CTRLMODE_TDC_MANUAL ( 1 << 10 )
217#define CAN_CTRLMODE_MASK ( CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY | \
218 CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_ONE_SHOT | \
219 CAN_CTRLMODE_BERR_REPORTING | CAN_CTRLMODE_FD | \
220 CAN_CTRLMODE_PRESUME_ACK | CAN_CTRLMODE_FD_NON_ISO | \
221 CAN_CTRLMODE_CC_LEN8_DLC | CAN_CTRLMODE_TDC_AUTO | \
222 CAN_CTRLMODE_TDC_MANUAL)
223
245#define RTEMS_CAN_CHIP_START _IO( CAN_IOC_MAGIC, 1 )
250#define RTEMS_CAN_CHIP_STOP _IO( CAN_IOC_MAGIC, 2 )
255#define RTEMS_CAN_CLOSE_NONBLOCK _IO( CAN_IOC_MAGIC, 3 )
261#define RTEMS_CAN_DISCARD_QUEUES _IO( CAN_IOC_MAGIC, 4 )
267#define RTEMS_CAN_FLUSH_QUEUES _IO( CAN_IOC_MAGIC, 5 )
273#define RTEMS_CAN_CHIP_SET_MODE _IO( CAN_IOC_MAGIC, 6 )
278#define RTEMS_CAN_CHIP_GET_INFO _IO( CAN_IOC_MAGIC, 7 )
283#define RTEMS_CAN_WAIT_TX_DONE _IOW( CAN_IOC_MAGIC, 8, struct timespec )
288#define RTEMS_CAN_POLL_TX_READY _IOW( CAN_IOC_MAGIC, 9, struct timespec )
293#define RTEMS_CAN_POLL_RX_AVAIL _IOW( CAN_IOC_MAGIC, 10, struct timespec )
298#define RTEMS_CAN_CREATE_QUEUE _IOW( CAN_IOC_MAGIC, 11, struct can_queue_param )
303#define RTEMS_CAN_SET_BITRATE _IOW( CAN_IOC_MAGIC, 12, struct can_set_bittiming )
307#define RTEMS_CAN_CHIP_GET_TIMESTAMP _IOR( CAN_IOC_MAGIC, 13, uint64_t )
311#define RTEMS_CAN_CHIP_STATISTICS _IOR( CAN_IOC_MAGIC, 14, struct can_stats )
316#define RTEMS_CAN_GET_BITTIMING _IOWR( CAN_IOC_MAGIC, 15, struct can_get_bittiming )
317
329 uint8_t direction;
335 uint8_t priority;
341 uint8_t dlen_max;
346 uint8_t buffer_size;
352};
353
356#endif
This header file is part of CAN/CAN FD bus common support. It defines structures used for bit timing ...
This header file is part of CAN/CAN FD bus common support. It implements structure that represents fi...
This header file is part of CAN/CAN FD bus common support. It implements CAN frame structure and rela...
This header file is part of CAN/CAN FD bus common support. It implements controller's statistics.
This structure is used to represent CAN ID and flags in one unified structure.
Definition: can-filter.h:49
This structure represents parameters of FIFO queue. It is used to setup new queues via RTEMS_CAN_CREA...
Definition: can.h:324
uint8_t buffer_size
This member specifies queue's buffer size. Passing 0 applies default CAN_DEFAULT_FIFO_SIZE value.
Definition: can.h:346
uint8_t priority
This member specifies queue's priority. Maximum priority value is available from RTEMS_CAN_QUEUE_PRIO...
Definition: can.h:335
struct can_filter filter
This member holds a queue's filter. Refer to can_filter for more information.
Definition: can.h:351
uint8_t dlen_max
This member specifies queue's maximum data length. Passing 0 applies default value: CAN_FRAME_STANDAR...
Definition: can.h:341
uint8_t direction
This member specifies queue's direction. Use RTEMS_CAN_QUEUE_RX or RTEMS_CAN_QUEUE_TX.
Definition: can.h:329