RTEMS 7.0-rc1
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
16/*
17 * Copyright (C) 2023-2024 Michal Lenc <michallenc@seznam.cz>
18 * Copyright (C) 2002-2009 DCE FEE CTU Prague
19 * Copyright (C) 2002-2024 Pavel Pisa <pisa@cmp.felk.cvut.cz>
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
41 */
42
43#ifndef _DEV_CAN_CAN_DEVCOMMON_H
44#define _DEV_CAN_CAN_DEVCOMMON_H
45
46#include <rtems.h>
47#include <stdint.h>
48#include <stdatomic.h>
49#include <sys/ioccom.h>
50#include <rtems/thread.h>
51
52#include <dev/can/can.h>
53#include <dev/can/can-bus.h>
54#include <dev/can/can-impl.h>
55
74};
75
76struct rtems_can_user;
77TAILQ_HEAD( rtems_can_user_list_t, rtems_can_user );
78
79struct rtems_can_chip;
80
98 int ( *start_chip )( struct rtems_can_chip *chip );
116 int ( *stop_chip )( struct rtems_can_chip *chip, struct timespec *ts );
128 int ( *chip_ioctl )(
129 struct rtems_can_chip *chip,
130 ioctl_command_t command,
131 void *arg
132 );
143 struct rtems_can_chip *chip,
144 uint64_t *timestamp
145 );
154 int ( *get_chip_info )( struct rtems_can_chip *chip, int what );
170 struct rtems_can_chip *chip,
171 int type,
172 struct rtems_can_bittiming *bt
173 );
188 struct rtems_can_chip *chip,
189 int type,
190 struct rtems_can_bittiming *bt
191 );
200 int ( *set_chip_mode )( struct rtems_can_chip *chip, uint32_t mode );
201};
202
210 const char *type;
218 uint32_t freq;
227 atomic_uint flags;
231 atomic_uint used;
236 uint32_t ctrlmode;
246 uint32_t capabilities;
250 rtems_mutex lock;
283 struct rtems_can_user_list_t can_users;
292 void *internal;
293};
294
318};
319
327 unsigned long flags;
344 int magic;
345};
346
359
378 struct rtems_can_chip *chip,
379 struct rtems_can_bittiming *bt,
380 const struct rtems_can_bittiming_const *btc
381);
382
389uint64_t rtems_can_fill_timestamp( void );
390
400 struct rtems_can_queue_ends_user_t *qends
401);
402
415 struct rtems_can_chip *chip,
416 const char *name
417);
418
419#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:211
int rtems_can_chip_start(struct rtems_can_chip *chip)
This function starts the controller.
Definition: can-devcommon.c:111
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:85
uint64_t rtems_can_fill_timestamp(void)
This function fills timestamping with current monotonic time.
Definition: can-devcommon.c:104
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:112
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...
ISR_Vector_number rtems_vector_number
This integer type represents interrupt vector numbers.
Definition: intr.h:102
This header file defines the RTEMS Classic API.
Definition: thread.h:280
This structure is used to represent CAN bit timing constants.
Definition: can-bittiming.h:86
This structure is used to represent CAN bit timing.
Definition: can-bittiming.h:130
This structure represents CAN bus device. This is the main structure passed throught file system duri...
Definition: can-bus.h:60
struct rtems_can_chip * chip
This member holds the pointer to rtems_can_chip structure. Controller specific initialization functio...
Definition: can-bus.h:66
This structure represents CAN controller operations. These provides interface from IOCTL calls to con...
Definition: can-devcommon.h:86
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:128
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:142
int(* start_chip)(struct rtems_can_chip *chip)
Starts the chip. Called with RTEMS_CAN_CHIP_START ioctl.
Definition: can-devcommon.h:98
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:200
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:169
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:154
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:116
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:187
This structure represents one CAN controller.
Definition: can-devcommon.h:206
struct rtems_can_queue_ends_dev * qends_dev
This member holds chip's side of queue ends.
Definition: can-devcommon.h:279
uint32_t ctrlmode
This member holds the currently set mode. Controller's device driver may set initial modes if needed.
Definition: can-devcommon.h:236
atomic_uint flags
This member holds controller's flags.
Definition: can-devcommon.h:227
struct rtems_can_chip_ops chip_ops
This member holds chip operations.
Definition: can-devcommon.h:275
rtems_vector_number irq
This member holds controller's interrupt number.
Definition: can-devcommon.h:214
const struct rtems_can_bittiming_const * bittiming_const
This member holds nominal bit timing constants (max/min values)
Definition: can-devcommon.h:259
struct rtems_can_stats chip_stats
This member holds the chip's statistics.
Definition: can-devcommon.h:287
const char * type
This member holds controller's type/name.
Definition: can-devcommon.h:210
rtems_binary_semaphore stop_sem
This member is used by the worker to notify the closed operation is finished.
Definition: can-devcommon.h:255
uint32_t capabilities
This member holds controller's capabilities.
Definition: can-devcommon.h:246
bool close_nonblock
This member informs whether close operation is blocking or nonblocking. This can be set with RTEMS_CA...
Definition: can-devcommon.h:223
void * internal
This member holds chip's specific private structure. This structure defines non generic fields and se...
Definition: can-devcommon.h:292
const struct rtems_can_bittiming_const * data_bittiming_const
This member holds data bit timing constants (max/min values)
Definition: can-devcommon.h:263
atomic_uint used
This member holds the number of users using the controller.
Definition: can-devcommon.h:231
struct rtems_can_user_list_t can_users
This member holds the list of chip's users.
Definition: can-devcommon.h:283
rtems_mutex lock
This member holds the lock to ensure atomicity of chip operations.
Definition: can-devcommon.h:250
struct rtems_can_bittiming bittiming
This member holds currently set nominal btt timing values.
Definition: can-devcommon.h:267
uint32_t freq
This member holds controller's base clock frequency.
Definition: can-devcommon.h:218
struct rtems_can_bittiming data_bittiming
This member holds currently set data btt timing values.
Definition: can-devcommon.h:271
uint32_t ctrlmode_supported
This member holds modes supported by the controller. Controller's device driver should set this field...
Definition: can-devcommon.h:242
This structure holds the controller's (application) side of queue's ends.
Definition: can-devcommon.h:60
struct rtems_can_queue_ends base
This member holds base rtems_can_queue_ends structure.
Definition: can-devcommon.h:64
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:73
struct rtems_can_chip * chip
This member holds the chip's structure.
Definition: can-devcommon.h:68
This structure holds the user's (application) side of queue's ends.
Definition: can-devcommon.h:298
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:307
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:312
struct rtems_can_queue_ends base
This member holds base rtems_can_queue_ends structure.
Definition: can-devcommon.h:302
rtems_binary_semaphore sem_sync
This member holds semaphore synchronizing queues during close operation. It informs all messages were...
Definition: can-devcommon.h:317
This structure represents place to connect edges to for CAN communication entity. The zero,...
Definition: can-queue.h:299
This structure is used to represent CAN statistics.
Definition: can-stats.h:90
This structure represents one CAN user (application).
Definition: can-devcommon.h:323
unsigned long flags
This member holds user's flags.
Definition: can-devcommon.h:327
struct rtems_can_queue_ends_user_t * qends_user
This member holds user's side of queue's ends.
Definition: can-devcommon.h:335
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:344
struct rtems_can_bus * bus
This member holds pointer to rtems_can_bus structure.
Definition: can-devcommon.h:339
This header file provides the API of Self-Contained Objects.