RTEMS CAN/CAN FD Stack
Loading...
Searching...
No Matches
can-queue.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_QUEUE_H
43#define __DEV_CAN_CAN_QUEUE_H
44
45#include <stdatomic.h>
46#include <inttypes.h>
47#include <sys/queue.h>
48#include <rtems.h>
49#include <rtems/timespec.h>
50#include <rtems/status-checks.h>
51#include <rtems/thread.h>
52
53#include <dev/can/can-frame.h>
54#include <dev/can/can-filter.h>
55
68 atomic_uint slot_flags;
74};
75
79#define RTEMS_CAN_SLOTF_CMD ( 0x00ff )
80
91 atomic_uint fifo_flags;
102 unsigned int out_taken;
106 unsigned long error_code;
138 rtems_mutex fifo_lock;
139};
140
144#define RTEMS_CAN_FIFOF_DESTROY ( 1 << 15 )
148#define RTEMS_CAN_FIFOF_ERROR ( 1 << 14 )
152#define RTEMS_CAN_FIFOF_ERR2BLOCK ( 1 << 13 )
156#define RTEMS_CAN_FIFOF_BLOCK ( 1 << 12 )
160#define RTEMS_CAN_FIFOF_OVERRUN ( 1 << 11 )
164#define RTEMS_CAN_FIFOF_FULL ( 1 << 10 )
168#define RTEMS_CAN_FIFOF_EMPTY ( 1 << 9 )
172#define RTEMS_CAN_FIFOF_DEAD ( 1 << 8 )
176#define RTEMS_CAN_FIFOF_INACTIVE ( 1 << 7 )
180#define RTEMS_CAN_FIFOF_FREEONEMPTY ( 1 << 6 )
184#define RTEMS_CAN_FIFOF_READY ( 1 << 5 )
188#define RTEMS_CAN_FIFOF_NOTIFYPEND ( 1 << 4 )
189
204
219
221TAILQ_HEAD( rtems_can_queue_edges_list, rtems_can_queue_edge );
222
262 struct rtems_can_queue_edges_list *peershead;
277 atomic_uint edge_used;
288};
289
291TAILQ_HEAD( rtems_can_queue_ends_list, rtems_can_queue_ends );
292
303 struct rtems_can_queue_edges_list active[RTEMS_CAN_QUEUE_PRIO_NR];
308 struct rtems_can_queue_edges_list idle;
312 struct rtems_can_queue_edges_list inlist;
317 struct rtems_can_queue_edges_list outlist;
322 rtems_mutex ends_lock;
349 void (*notify)(
350 struct rtems_can_queue_ends *qends,
351 struct rtems_can_queue_edge *qedge,
352 int what
353 );
359};
360
364#define RTEMS_CAN_QUEUE_NOTIFY_EMPTY ( 1 )
368#define RTEMS_CAN_QUEUE_NOTIFY_SPACE ( 2 )
372#define RTEMS_CAN_QUEUE_NOTIFY_PROC ( 3 )
377#define RTEMS_CAN_QUEUE_NOTIFY_NOUSR ( 4 )
381#define RTEMS_CAN_QUEUE_NOTIFY_DEAD ( 5 )
385#define RTEMS_CAN_QUEUE_NOTIFY_DEAD_WANTED ( 6 )
389#define RTEMS_CAN_QUEUE_NOTIFY_ATTACH ( 7 )
390
407 struct rtems_can_queue_ends *qends,
408 struct rtems_can_queue_edge **qedgep,
409 struct rtems_can_queue_slot **slotp,
410 int cmd
411);
412
435 struct rtems_can_queue_ends *qends,
436 struct rtems_can_queue_edge **qedgep,
437 struct rtems_can_queue_slot **slotp,
438 const struct can_frame_header *header,
439 int cmd,
440 int prio
441);
442
457
474 struct rtems_can_queue_ends *qends,
475 struct rtems_can_queue_edge *qedge,
476 struct rtems_can_queue_slot *slot
477);
478
494 struct rtems_can_queue_ends *qends,
495 struct rtems_can_queue_edge *qedge,
496 struct rtems_can_queue_slot *slot
497);
498
514 struct rtems_can_queue_ends *qends,
515 struct rtems_can_queue_edge *src_edge,
516 struct can_frame *frame,
517 unsigned int flags2add
518);
519
536 struct rtems_can_queue_ends *qends,
537 struct rtems_can_queue_edge **qedgep,
538 struct rtems_can_queue_slot **slotp
539);
540
559 struct rtems_can_queue_ends *qends,
560 int prio_min
561);
562
578 struct rtems_can_queue_ends *qends,
579 struct rtems_can_queue_edge *qedge,
580 struct rtems_can_queue_slot *slot
581);
582
597 struct rtems_can_queue_ends *qends,
598 struct rtems_can_queue_edge *qedge,
599 struct rtems_can_queue_slot *slot
600);
601
616
627
641 struct rtems_can_queue_edge *qedge,
644);
645
656
667
678
691 struct rtems_can_queue_ends *qends,
692 int send_rest
693);
694
705
714
724
734
744
758 int allocated_slot_count,
759 int max_data_length
760);
761
771
783 int allocated_slot_countm,
784 int max_data_length
785);
786
798 struct rtems_can_queue_ends *qends,
799 struct timespec *ts
800);
801
816 struct rtems_can_queue_ends *qends,
817 struct rtems_can_queue_edge *qedge,
818 bool nowait,
819 rtems_interval timeout
820);
821
833 struct rtems_can_queue_ends *qends,
834 bool nonblock
835);
836
844
845#endif /* __DEV_CAN_CAN_QUEUE_H */
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...
int rtems_can_queue_ends_init(struct rtems_can_queue_ends *qends)
This function implements subsystem independent routine to initialize ends state.
Definition: can-queue.c:517
int rtems_can_queue_pending_outslot_prio(struct rtems_can_queue_ends *qends, int prio_min)
This function tests ready outslot with minimum priority.
Definition: can-queue.c:393
int rtems_can_queue_get_inslot(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge **qedgep, struct rtems_can_queue_slot **slotp, int cmd)
This function finds one outgoing edge and allocates slot from it.
Definition: can-queue.c:103
int rtems_can_queue_filter_frame_to_edges(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge *src_edge, struct can_frame *frame, unsigned int flags2add)
This function sends message into all edges which accept its ID.
Definition: can-queue.c:245
int rtems_can_queue_disconnect_edge(struct rtems_can_queue_edge *qedge)
This function disconnects edge from communication entities.
Definition: can-queue.c:582
int rtems_can_queue_ends_dispose_kern(struct rtems_can_queue_ends *qends, bool nonblock)
This function provides finalizing of the ends structure for clients.
Definition: can-quekern.c:398
int rtems_can_queue_kern_initialize(void)
This function provides initialization of kernel queue side.
Definition: can-quekern.c:430
int rtems_can_queue_get_inslot_for_prio(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge **qedgep, struct rtems_can_queue_slot **slotp, const struct can_frame_header *header, int cmd, int prio)
This function finds best outgoing edge and slot for given priority.
Definition: can-queue.c:131
int rtems_can_queue_fifo_done_kern(struct rtems_can_queue_fifo *fifo)
This function frees slots allocated for CAN FIFO.
Definition: can-quekern.c:301
int rtems_can_queue_fifo_flush_slots(struct rtems_can_queue_fifo *fifo)
This function frees all ready slots from the FIFO.
Definition: can-queue.c:47
int rtems_can_queue_connect_edge(struct rtems_can_queue_edge *qedge, struct rtems_can_queue_ends *input_ends, struct rtems_can_queue_ends *output_ends)
This function connects edge between two communication entities.
Definition: can-queue.c:531
int rtems_can_queue_test_outslot(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge **qedgep, struct rtems_can_queue_slot **slotp)
This function tests and retrieves ready slot for given ends.
Definition: can-queue.c:323
void rtems_can_queue_edge_do_dead(struct rtems_can_queue_edge *qedge)
This function disconnects the edge.
Definition: can-quekern.c:135
int rtems_can_queue_free_outslot(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge *qedge, struct rtems_can_queue_slot *slot)
This function frees processed output slot.
Definition: can-queue.c:435
int rtems_can_queue_abort_inslot(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge *qedge, struct rtems_can_queue_slot *slot)
This function aborts preparation of the message in the slot.
Definition: can-queue.c:226
int rtems_can_queue_fifo_init_kern(struct rtems_can_queue_fifo *fifo, int allocated_slot_count, int max_data_length)
This function initializes one CAN FIFO.
Definition: can-quekern.c:275
int rtems_can_queue_fifo_init_slots(struct rtems_can_queue_fifo *fifo)
This function initializes slot chain of one CAN FIFO.
Definition: can-queue.c:73
int rtems_can_queue_ends_kill_outlist(struct rtems_can_queue_ends *qends)
This function sends request to die to all incomming edges.
Definition: can-queue.c:705
int rtems_can_queue_put_inslot(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge *qedge, struct rtems_can_queue_slot *slot)
This function schedules filled slot for processing.
Definition: can-queue.c:206
void rtems_can_queue_do_edge_decref(struct rtems_can_queue_edge *edge)
This function decrements the edge user counter.
Definition: can-queue.c:98
int rtems_can_queue_ends_sync_all_kern(struct rtems_can_queue_ends *qends, struct timespec *ts)
This function waits for all ends to TX their messages.
Definition: can-quekern.c:346
int rtems_can_queue_ends_kill_inlist(struct rtems_can_queue_ends *qends, int send_rest)
This function sends request to die to all outgoing edges.
Definition: can-queue.c:670
int rtems_can_queue_push_back_outslot(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge *qedge, struct rtems_can_queue_slot *slot)
This function reschedules output slot to process it again later.
Definition: can-queue.c:467
int rtems_can_queue_ends_flush_inlist(struct rtems_can_queue_ends *qends)
This function flushes all messages in incoming edges.
Definition: can-queue.c:719
struct rtems_can_queue_edge * rtems_can_queue_new_edge_kern(int allocated_slot_countm, int max_data_length)
This function allocates new edge structure.
Definition: can-quekern.c:311
void rtems_can_queue_block_inlist(struct rtems_can_queue_ends *qends)
This function blocks slot allocation of all outgoing edges of specified ends.
Definition: can-queue.c:652
int rtems_can_queue_flush(struct rtems_can_queue_edge *qedge)
This function flushes all ready slots in the edge.
Definition: can-queue.c:495
int rtems_can_queue_ends_flush_outlist(struct rtems_can_queue_ends *qends)
This function flushes all messages in outgoing edges.
Definition: can-queue.c:729
int rtems_can_queue_sync_wait_kern(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge *qedge, bool nowait, rtems_interval timeout)
This function waits for all slots processing.
Definition: can-quekern.c:233
void rtems_can_queue_block_outlist(struct rtems_can_queue_ends *qends)
This function blocks slot allocation of all incoming edges of specified ends.
Definition: can-queue.c:661
int rtems_can_queue_test_inslot(struct rtems_can_queue_ends *qends)
This function tests whether there is a free space in any outgoing edge.
Definition: can-queue.c:187
This structure represents the CAN message header.
Definition: can-frame.h:505
This structure represents one CAN frame. It consists of CAN header and data.
Definition: can-frame.h:533
This structure is used to represent CAN ID and flags in one unified structure.
Definition: can-filter.h:49
This structure represents one direction connection from messages source ( input_ends) to message cons...
Definition: can-queue.h:230
struct rtems_can_queue_edges_list * peershead
This member holds the pointer to the activepeers head.
Definition: can-queue.h:262
int edge_prio
This member holds the the assigned queue priority from the range 0 to RTEMS_CAN_QUEUE_PRIO_NR - 1.
Definition: can-queue.h:282
struct rtems_can_queue_ends * output_ends
This member holds the pointer to the FIFO output side terminal ( rtems_can_queue_ends ).
Definition: can-queue.h:272
atomic_uint edge_used
This member holds the atomic usage counter, mainly used for safe destruction of the edge.
Definition: can-queue.h:277
TAILQ_ENTRY(rtems_can_queue_edge) input_peers
This member holds the lists of all peers FIFOs connected by their input side ( input_ends ) to the sa...
struct rtems_can_queue_ends * input_ends
This member holds the pointer to the FIFO input side terminal ( rtems_can_queue_ends ).
Definition: can-queue.h:267
struct rtems_can_queue_fifo fifo
This member holds place where primitive rtems_can_queue_fifo FIFO is located.
Definition: can-queue.h:235
TAILQ_ENTRY(rtems_can_queue_edge) output_peers
This member holds the lists of all peers FIFOs connected by their output side ( output_ends ) to the ...
int edge_num
This member holds the edge sequential number intended for debugging purposes only.
Definition: can-queue.h:287
TAILQ_ENTRY(rtems_can_queue_edge) activepeers
This member holds the lists of peers FIFOs connected by their output side ( output_ends ) to the same...
struct rtems_can_filter filter
This member holds place where primitive rtems_can_filter is located.
Definition: can-queue.h:240
This structure represents place to connect edges to for CAN communication entity. The zero,...
Definition: can-queue.h:298
struct rtems_can_queue_edges_list active[RTEMS_CAN_QUEUE_PRIO_NR]
This member holds the array of the lists of active edges directed to the ends structure.
Definition: can-queue.h:303
struct rtems_can_queue_edges_list outlist
This member holds the list of all incoming edges output sides. Each of there edges is listed on one o...
Definition: can-queue.h:317
TAILQ_ENTRY(rtems_can_queue_ends) dead_peers
This member is used to chain ends wanting for postponed destruction.
struct rtems_can_queue_edges_list idle
This member holds the list of the edges directed to the ends structure with empty FIFOs.
Definition: can-queue.h:308
rtems_mutex ends_lock
This member holds the lock synchronizing operations between threads accessing the ends.
Definition: can-queue.h:322
struct rtems_can_queue_edges_list inlist
This member holds the list of outgoing edges input sides.
Definition: can-queue.h:312
void(* notify)(struct rtems_can_queue_ends *qends, struct rtems_can_queue_edge *qedge, int what)
pointer to notify procedure. The next state changes are notified.
Definition: can-queue.h:349
This structure represents CAN FIFO queue. It is implemented as a single linked list of slots prepared...
Definition: can-queue.h:87
int allocated_slot_count
This member holds the number of allocated slots.
Definition: can-queue.h:133
unsigned int out_taken
This member holds the number of elements in the fifo.
Definition: can-queue.h:102
struct rtems_can_queue_slot * free_list
This member holds the pointer to list of the free slots associated with queue.
Definition: can-queue.h:120
rtems_mutex fifo_lock
This member holds the lock to ensure atomicity of slot manipulation operations.
Definition: can-queue.h:138
int max_data_length
This member holds maximum data length of one CAN frame.
Definition: can-queue.h:129
struct rtems_can_queue_slot * entry
This member holds the pointer to the memory allocated for the list slots.
Definition: can-queue.h:125
unsigned long error_code
This member holds futher description of error condition.
Definition: can-queue.h:106
struct rtems_can_queue_slot * head
This member holds the pointer to the FIFO head, oldest slot.
Definition: can-queue.h:110
atomic_uint fifo_flags
This field holds global flags describing state of the FIFO.
Definition: can-queue.h:91
struct rtems_can_queue_slot ** tail
This member holds the pointer to the location, where pointer to newly inserted slot should be added.
Definition: can-queue.h:115
This structure represents one CAN message slot in the CAN FIFO queue.
Definition: can-queue.h:59
atomic_uint slot_flags
Space for flags and optional command describing action associated with slot data.
Definition: can-queue.h:68
struct can_frame frame
This member holds can_frame structure representing one CAN frame/message.
Definition: can-queue.h:73
struct rtems_can_queue_slot * next
Pointer to next/younger slot.
Definition: can-queue.h:63