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-impl.h>
54
72 rtems_binary_semaphore worker_sem;
73};
74
75struct rtems_can_user;
76TAILQ_HEAD( rtems_can_user_list_t, rtems_can_user );
77
78struct rtems_can_chip;
79
97 int ( *start_chip )( struct rtems_can_chip *chip );
115 int ( *stop_chip )( struct rtems_can_chip *chip, struct timespec *ts );
127 int ( *chip_ioctl )(
128 struct rtems_can_chip *chip,
129 ioctl_command_t command,
130 void *arg
131 );
142 struct rtems_can_chip *chip,
143 uint64_t *timestamp
144 );
153 int ( *get_chip_info )( struct rtems_can_chip *chip, int what );
169 struct rtems_can_chip *chip,
170 int type,
171 struct rtems_can_bittiming *bt
172 );
187 struct rtems_can_chip *chip,
188 int type,
189 struct rtems_can_bittiming *bt
190 );
199 int ( *set_chip_mode )( struct rtems_can_chip *chip, uint32_t mode );
200};
201
209 const char *type;
213 rtems_vector_number irq;
217 uint32_t freq;
226 atomic_uint flags;
230 atomic_uint used;
235 uint32_t ctrlmode;
245 uint32_t capabilities;
249 rtems_mutex lock;
254 rtems_binary_semaphore stop_sem;
282 struct rtems_can_user_list_t can_users;
291 void *internal;
292};
293
306 rtems_binary_semaphore sem_read;
311 rtems_binary_semaphore sem_write;
316 rtems_binary_semaphore sem_sync;
317};
318
326 unsigned long flags;
343 int magic;
344};
345
358
377 struct rtems_can_chip *chip,
378 struct rtems_can_bittiming *bt,
379 const struct rtems_can_bittiming_const *btc
380);
381
388uint64_t rtems_can_fill_timestamp( void );
389
399 struct rtems_can_queue_ends_user_t *qends
400);
401
414 struct rtems_can_chip *chip,
415 const char *name
416);
417
418#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 rtems_can_queue_ends_init_user(struct rtems_can_queue_ends_user_t *qends)
Userspace clients specific ends initialization.
Definition: can-quekern.c:208
int rtems_can_chip_start(struct rtems_can_chip *chip)
This function starts the controller.
Definition: can-devcommon.c:110
int rtems_can_queue_ends_init_chip(struct rtems_can_chip *chip, const char *name)
This function initializes ends from chip's side.
Definition: can-devcommon.c:84
uint64_t rtems_can_fill_timestamp(void)
This function fills timestamping with current monotonic time.
Definition: can-devcommon.c:103
int rtems_can_bitrate2bittiming(struct rtems_can_chip *chip, struct rtems_can_bittiming *bt, const struct rtems_can_bittiming_const *btc)
This function calculates CAN bit timing for given bit rate.
Definition: can-bittiming.c:109
This file is part of CAN/CAN FD bus common support and implements internal functions for CAN queues h...
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 rtems_can_chip * chip
This member holds the pointer to rtems_can_chip structure. Controller specific initialization functio...
Definition: can-bus.h:65
This structure represents CAN controller operations. These provides interface from IOCTL calls to con...
Definition: can-devcommon.h:85
int(* chip_ioctl)(struct rtems_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:127
int(* get_chip_timestamp)(struct rtems_can_chip *chip, uint64_t *timestamp)
Obtains timestamp from the controller. Called with RTEMS_CAN_CHIP_GET_TIMESTAMP ioctl.
Definition: can-devcommon.h:141
int(* start_chip)(struct rtems_can_chip *chip)
Starts the chip. Called with RTEMS_CAN_CHIP_START ioctl.
Definition: can-devcommon.h:97
int(* set_chip_mode)(struct rtems_can_chip *chip, uint32_t mode)
Sets controller mode defined in input argument. Called with RTEMS_CAN_CHIP_SET_MODE.
Definition: can-devcommon.h:199
int(* calc_bittiming)(struct rtems_can_chip *chip, int type, struct rtems_can_bittiming *bt)
Calculates bit timing from given bit rate and saves the values to controller's registers....
Definition: can-devcommon.h:168
int(* get_chip_info)(struct rtems_can_chip *chip, int what)
Obtains controller's information specified by input integer argument. Called with RTEMS_CAN_CHIP_GET_...
Definition: can-devcommon.h:153
int(* stop_chip)(struct rtems_can_chip *chip, struct timespec *ts)
Stops the chip. Called with RTEMS_CAN_CHIP_STOP ioctl.
Definition: can-devcommon.h:115
int(* check_and_set_bittiming)(struct rtems_can_chip *chip, int type, struct rtems_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:186
This structure represents one CAN controller.
Definition: can-devcommon.h:205
struct rtems_can_queue_ends_dev * qends_dev
This member holds chip's side of queue ends.
Definition: can-devcommon.h:278
uint32_t ctrlmode
This member holds the currently set mode. Controller's device driver may set initial modes if needed.
Definition: can-devcommon.h:235
atomic_uint flags
This member holds controller's flags.
Definition: can-devcommon.h:226
struct rtems_can_chip_ops chip_ops
This member holds chip operations.
Definition: can-devcommon.h:274
rtems_vector_number irq
This member holds controller's interrupt number.
Definition: can-devcommon.h:213
const struct rtems_can_bittiming_const * bittiming_const
This member holds nominal bit timing constants (max/min values)
Definition: can-devcommon.h:258
struct rtems_can_stats chip_stats
This member holds the chip's statistics.
Definition: can-devcommon.h:286
const char * type
This member holds controller's type/name.
Definition: can-devcommon.h:209
rtems_binary_semaphore stop_sem
This member is used by the worker to notify the closed operation is finished.
Definition: can-devcommon.h:254
uint32_t capabilities
This member holds controller's capabilities.
Definition: can-devcommon.h:245
bool close_nonblock
This member informs whether close operation is blocking or nonblocking. This can be set with RTEMS_CA...
Definition: can-devcommon.h:222
void * internal
This member holds chip's specific private structure. This structure defines non generic fields and se...
Definition: can-devcommon.h:291
const struct rtems_can_bittiming_const * data_bittiming_const
This member holds data bit timing constants (max/min values)
Definition: can-devcommon.h:262
atomic_uint used
This member holds the number of users using the controller.
Definition: can-devcommon.h:230
struct rtems_can_user_list_t can_users
This member holds the list of chip's users.
Definition: can-devcommon.h:282
rtems_mutex lock
This member holds the lock to ensure atomicity of chip operations.
Definition: can-devcommon.h:249
struct rtems_can_bittiming bittiming
This member holds currently set nominal btt timing values.
Definition: can-devcommon.h:266
uint32_t freq
This member holds controller's base clock frequency.
Definition: can-devcommon.h:217
struct rtems_can_bittiming data_bittiming
This member holds currently set data btt timing values.
Definition: can-devcommon.h:270
uint32_t ctrlmode_supported
This member holds modes supported by the controller. Controller's device driver should set this field...
Definition: can-devcommon.h:241
This structure holds the controller's (application) side of queue's ends.
Definition: can-devcommon.h:59
struct rtems_can_queue_ends base
This member holds base rtems_can_queue_ends structure.
Definition: can-devcommon.h:63
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:72
struct rtems_can_chip * chip
This member holds the chip's structure.
Definition: can-devcommon.h:67
This structure holds the user's (application) side of queue's ends.
Definition: can-devcommon.h:297
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:306
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:311
struct rtems_can_queue_ends base
This member holds base rtems_can_queue_ends structure.
Definition: can-devcommon.h:301
rtems_binary_semaphore sem_sync
This member holds semaphore synchronizing queues during close operation. It informs all messages were...
Definition: can-devcommon.h:316
This structure represents place to connect edges to for CAN communication entity. The zero,...
Definition: can-queue.h:298
This structure is used to represent CAN statistics.
Definition: can-stats.h:89
This structure represents one CAN user (application).
Definition: can-devcommon.h:322
unsigned long flags
This member holds user's flags.
Definition: can-devcommon.h:326
struct rtems_can_queue_ends_user_t * qends_user
This member holds user's side of queue's ends.
Definition: can-devcommon.h:334
TAILQ_ENTRY(rtems_can_user) peers
This member holds TAILQ entry.
int magic
This member holds user magic value. It should be set to RTEMS_CAN_USER_MAGIC value.
Definition: can-devcommon.h:343
struct rtems_can_bus * bus
This member holds pointer to rtems_can_bus structure.
Definition: can-devcommon.h:338