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_CAN_CHIP_CONFIGURED ( 0 )
83#define RTEMS_CAN_CHIP_RUNNING ( 1 )
84
95#define RTEMS_CAN_CHIP_CAPABILITIES_FD ( 1 << 0 )
100#define RTEMS_CAN_CHIP_CAPABILITIES_TX_TIMESTAMP ( 1 << 1 )
105#define RTEMS_CAN_CHIP_CAPABILITIES_RX_TIMESTAMP ( 1 << 2 )
106
121#define RTEMS_CAN_CHIP_BITRATE ( 1 )
126#define RTEMS_CAN_CHIP_DBITRATE ( 2 )
131#define RTEMS_CAN_CHIP_NUSERS ( 3 )
137#define RTEMS_CAN_CHIP_FLAGS ( 4 )
142#define RTEMS_CAN_CHIP_MODE ( 5 )
147#define RTEMS_CAN_CHIP_MODE_SUPPORTED ( 6 )
148
162#define RTEMS_CAN_QUEUE_RX ( 1 << 0 )
167#define RTEMS_CAN_QUEUE_TX ( 1 << 1 )
168
183#define CAN_CTRLMODE_LOOPBACK ( 1 << 0 )
188#define CAN_CTRLMODE_LISTENONLY ( 1 << 1 )
193#define CAN_CTRLMODE_3_SAMPLES ( 1 << 2 )
198#define CAN_CTRLMODE_ONE_SHOT ( 1 << 3 )
203#define CAN_CTRLMODE_BERR_REPORTING ( 1 << 4 )
208#define CAN_CTRLMODE_FD ( 1 << 5 )
213#define CAN_CTRLMODE_PRESUME_ACK ( 1 << 6 )
218#define CAN_CTRLMODE_FD_NON_ISO ( 1 << 7 )
223#define CAN_CTRLMODE_CC_LEN8_DLC ( 1 << 8 )
228#define CAN_CTRLMODE_TDC_AUTO ( 1 << 9 )
233#define CAN_CTRLMODE_TDC_MANUAL ( 1 << 10 )
234#define CAN_CTRLMODE_MASK ( CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY | \
235 CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_ONE_SHOT | \
236 CAN_CTRLMODE_BERR_REPORTING | CAN_CTRLMODE_FD | \
237 CAN_CTRLMODE_PRESUME_ACK | CAN_CTRLMODE_FD_NON_ISO | \
238 CAN_CTRLMODE_CC_LEN8_DLC | CAN_CTRLMODE_TDC_AUTO | \
239 CAN_CTRLMODE_TDC_MANUAL)
240
262#define RTEMS_CAN_CHIP_START _IO( CAN_IOC_MAGIC, 1 )
267#define RTEMS_CAN_CHIP_STOP _IOW( CAN_IOC_MAGIC, 2, struct timespec )
272#define RTEMS_CAN_CLOSE_NONBLOCK _IO( CAN_IOC_MAGIC, 3 )
278#define RTEMS_CAN_DISCARD_QUEUES _IO( CAN_IOC_MAGIC, 4 )
284#define RTEMS_CAN_FLUSH_QUEUES _IO( CAN_IOC_MAGIC, 5 )
290#define RTEMS_CAN_CHIP_SET_MODE _IO( CAN_IOC_MAGIC, 6 )
295#define RTEMS_CAN_CHIP_GET_INFO _IO( CAN_IOC_MAGIC, 7 )
302#define RTEMS_CAN_WAIT_TX_DONE _IOW( CAN_IOC_MAGIC, 8, struct timespec )
309#define RTEMS_CAN_POLL_TX_READY _IOW( CAN_IOC_MAGIC, 9, struct timespec )
316#define RTEMS_CAN_POLL_RX_AVAIL _IOW( CAN_IOC_MAGIC, 10, struct timespec )
321#define RTEMS_CAN_CREATE_QUEUE _IOW( CAN_IOC_MAGIC, 11, struct rtems_can_queue_param )
326#define RTEMS_CAN_SET_BITRATE _IOW( CAN_IOC_MAGIC, 12, struct rtems_can_set_bittiming )
330#define RTEMS_CAN_CHIP_GET_TIMESTAMP _IOR( CAN_IOC_MAGIC, 13, uint64_t )
335#define RTEMS_CAN_CHIP_STATISTICS _IOR( CAN_IOC_MAGIC, 14, struct rtems_can_stats )
340#define RTEMS_CAN_GET_BITTIMING _IOWR( CAN_IOC_MAGIC, 15, struct rtems_can_get_bittiming )
341
353 uint8_t direction;
359 uint8_t priority;
365 uint8_t dlen_max;
370 uint8_t buffer_size;
376};
377
380#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:348
uint8_t direction
This member specifies queue's direction. Use RTEMS_CAN_QUEUE_RX or RTEMS_CAN_QUEUE_TX.
Definition: can.h:353
struct rtems_can_filter filter
This member holds a queue's filter. Refer to rtems_can_filter for more information.
Definition: can.h:375
uint8_t buffer_size
This member specifies queue's buffer size. Passing 0 applies default RTEMS_CAN_FIFO_SIZE value.
Definition: can.h:370
uint8_t priority
This member specifies queue's priority. Maximum priority value is available from RTEMS_CAN_QUEUE_PRIO...
Definition: can.h:359
uint8_t dlen_max
This member specifies queue's maximum data length. Passing 0 applies default value: CAN_FRAME_STANDAR...
Definition: can.h:365