RTEMS CAN/CAN FD Stack
Loading...
Searching...
No Matches
can-devcommon.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_DEVCOMMON_H
43#define _DEV_CAN_CAN_DEVCOMMON_H
44
45#include <rtems.h>
46#include <stdint.h>
47#include <stdatomic.h>
48#include <sys/ioccom.h>
49#include <rtems/thread.h>
50
51#include <dev/can/can.h>
52#include <dev/can/can-bus.h>
53#include <dev/can/can-queue.h>
54
66 struct can_chip *chip;
71 rtems_binary_semaphore worker_sem;
72};
73
74struct can_user;
75TAILQ_HEAD( can_user_list_t, can_user );
76
77struct can_chip;
78
88 int ( *start_chip )( struct can_chip *chip );
92 int ( *stop_chip )( struct can_chip *chip );
98 int ( *chip_ioctl )(
99 struct can_chip *chip,
100 ioctl_command_t command,
101 void *arg
102 );
107 int ( *get_chip_timestamp )( struct can_chip *chip, uint64_t *timestamp );
112 int ( *get_chip_info )( struct can_chip *chip, int what );
120 struct can_chip *chip,
121 int type,
122 struct can_bittiming *bt
123 );
130 struct can_chip *chip,
131 int type,
132 struct can_bittiming *bt
133 );
138 int ( *set_chip_mode )( struct can_chip *chip, uint32_t mode );
139};
140
144struct can_chip {
148 const char *type;
152 rtems_vector_number irq;
156 unsigned freq;
165 atomic_uint flags;
169 atomic_uint used;
174 uint32_t ctrlmode;
208 struct can_user_list_t can_users;
217 void *priv;
218};
219
232 rtems_binary_semaphore sem_read;
237 rtems_binary_semaphore sem_write;
242 rtems_binary_semaphore sem_sync;
243};
244
248struct can_user {
252 unsigned long flags;
264 struct can_bus *bus;
269 int magic;
270};
271
272int rtems_can_chip_start( struct can_chip *chip );
274 struct can_chip *chip,
275 struct can_bittiming *bt,
276 const struct can_bittiming_const *btc
277);
278void rtems_can_filltimestamp( uint64_t *timestamp );
279
282 struct canque_ends_dev_t *qends_dev,
283 struct can_chip *chip,
284 rtems_binary_semaphore worker_sem
285);
286
287#endif /* _DEV_CAN_CAN_DEVCOMMON_H */
This header file is part of CAN/CAN FD bus common support. It declares structures and functions used ...
int canqueue_ends_init_chip(struct canque_ends_dev_t *qends_dev, struct can_chip *chip, rtems_binary_semaphore worker_sem)
This function initializes ends from chip's side.
Definition: can-devcommon.c:88
int canqueue_ends_init_user(struct canque_ends_user_t *qends)
Userspace clients specific ends initialization.
Definition: can-quekern.c:210
int rtems_can_bitrate2bittiming(struct can_chip *chip, struct can_bittiming *bt, const struct can_bittiming_const *btc)
This function calculates CAN bit timing for given bit rate.
Definition: can-bittiming.c:125
void rtems_can_filltimestamp(uint64_t *timestamp)
This function fills timestamping with current monotonic time.
Definition: can-devcommon.c:116
int rtems_can_chip_start(struct can_chip *chip)
This function starts the controller.
Definition: can-devcommon.c:134
This file is part of CAN/CAN FD bus common support and implements CAN FIFOs and generic hubs/ends for...
This file is part of CAN/CAN FD bus common support and defines generic CAN structures used for common...
This structure is used to represent CAN bit timing constants.
Definition: can-bittiming.h:85
This structure is used to represent CAN bit timing.
Definition: can-bittiming.h:129
This structure represents CAN bus device. This is the main structure passed throught file system duri...
Definition: can-bus.h:59
struct can_chip * chip
This member holds the pointer to can_chip structure. Controller specific initialization function shou...
Definition: can-bus.h:65
This structure represents CAN controller operations. These provides interface from IOCTL calls to con...
Definition: can-devcommon.h:84
int(* set_chip_mode)(struct can_chip *chip, uint32_t mode)
Sets controller mode defined in input argument. Called with RTEMS_CAN_CHIP_SET_MODE.
Definition: can-devcommon.h:138
int(* stop_chip)(struct can_chip *chip)
Stops the chip. Called with RTEMS_CAN_CHIP_STOP ioctl.
Definition: can-devcommon.h:92
int(* start_chip)(struct can_chip *chip)
Starts the chip. Called with RTEMS_CAN_CHIP_START ioctl.
Definition: can-devcommon.h:88
int(* calc_bittiming)(struct can_chip *chip, int type, struct can_bittiming *bt)
Calculates bit timing from given bit rate and saves the values to controller's registers....
Definition: can-devcommon.h:119
int(* check_and_set_bittiming)(struct can_chip *chip, int type, struct can_bittiming *bt)
Checks bit timing given by user and saves it to controller's registers. Called with RTEMS_CAN_SET_BIT...
Definition: can-devcommon.h:129
int(* get_chip_info)(struct can_chip *chip, int what)
Obtains controller's information specified by input integer argument. Called with RTEMS_CAN_CHIP_GET_...
Definition: can-devcommon.h:112
int(* get_chip_timestamp)(struct can_chip *chip, uint64_t *timestamp)
Obtains timestamp from the controller. Called with RTEMS_CAN_CHIP_GET_TIMESTAMP ioctl.
Definition: can-devcommon.h:107
int(* chip_ioctl)(struct can_chip *chip, ioctl_command_t command, void *arg)
Unrecognized ioctl calls are passed to chip specific function to handle them. This way chip specific ...
Definition: can-devcommon.h:98
This structure represents one CAN controller.
Definition: can-devcommon.h:144
const struct can_bittiming_const * data_bittiming_const
This member holds data bit timing constants (max/min values)
Definition: can-devcommon.h:188
struct can_user_list_t can_users
This member holds the list of chip's users.
Definition: can-devcommon.h:208
struct canque_ends_dev_t * qends_dev
This member holds chip's side of queue ends.
Definition: can-devcommon.h:204
uint32_t ctrlmode_supported
This member holds modes supported by the controller. Controller's device driver should set this field...
Definition: can-devcommon.h:180
const char * type
This member holds controller's type/name.
Definition: can-devcommon.h:148
atomic_uint used
This member holds the number of users using the controller.
Definition: can-devcommon.h:169
bool close_nonblock
This member informs whether close operation is blocking or nonblocking. This can be set with RTEMS_CA...
Definition: can-devcommon.h:161
struct can_stats chip_stats
This member holds the chip's statistics.
Definition: can-devcommon.h:212
atomic_uint flags
This member holds controller's flags.
Definition: can-devcommon.h:165
uint32_t ctrlmode
This member holds the currently set mode. Controller's device driver may set initial modes if needed.
Definition: can-devcommon.h:174
const struct can_bittiming_const * bittiming_const
This member holds nominal bit timing constants (max/min values)
Definition: can-devcommon.h:184
struct can_chip_ops chip_ops
This member holds chip operations.
Definition: can-devcommon.h:200
struct can_bittiming bittiming
This member holds currently set nominal btt timing values.
Definition: can-devcommon.h:192
struct can_bittiming data_bittiming
This member holds currently set data btt timing values.
Definition: can-devcommon.h:196
rtems_vector_number irq
This member holds controller's interrupt number.
Definition: can-devcommon.h:152
void * priv
This member holds chip's specific private structure. This structur defines non generic fields and set...
Definition: can-devcommon.h:217
unsigned freq
This member holds controller's base clock frequency.
Definition: can-devcommon.h:156
This structure is used to represent CAN statistics.
Definition: can-stats.h:51
This structure represents one CAN user (application).
Definition: can-devcommon.h:248
TAILQ_ENTRY(can_user) peers
This member holds TAILQ entry.
struct can_bus * bus
This member holds pointer to can_bus structure.
Definition: can-devcommon.h:264
int magic
This member holds user magic value. It should be set to RTEMS_CAN_USER_MAGIC value.
Definition: can-devcommon.h:269
unsigned long flags
This member holds user's flags.
Definition: can-devcommon.h:252
struct canque_ends_user_t * qends_user
This member holds user's side of queue's ends.
Definition: can-devcommon.h:260
This structure holds the controller's (application) side of queue's ends.
Definition: can-devcommon.h:58
struct can_chip * chip
This member holds the chip's structure.
Definition: can-devcommon.h:66
struct canque_ends_t base
This member holds base canque_ends_t structure.
Definition: can-devcommon.h:62
rtems_binary_semaphore worker_sem
This member holds the worker semaphore used to trigger controller when there is a new message to be t...
Definition: can-devcommon.h:71
This structure represents place to connect edges to for CAN communication entity. The zero,...
Definition: can-queue.h:603
This structure holds the user's (application) side of queue's ends.
Definition: can-devcommon.h:223
rtems_binary_semaphore sem_sync
This member holds semaphore synchronizing queues during close operation. It informs all messages were...
Definition: can-devcommon.h:242
rtems_binary_semaphore sem_write
This member holds semaphore informing the user's side there is a free space to write message.
Definition: can-devcommon.h:237
struct canque_ends_t base
This member holds base canque_ends_t structure.
Definition: can-devcommon.h:227
rtems_binary_semaphore sem_read
This member holds semaphore informing the user's side there is a new message to be read.
Definition: can-devcommon.h:232