RTEMS 7.0-rc1
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
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_QUEUE_H
44#define __DEV_CAN_CAN_QUEUE_H
45
46#include <stdatomic.h>
47#include <inttypes.h>
48#include <sys/queue.h>
49#include <rtems.h>
50#include <rtems/timespec.h>
51#include <rtems/status-checks.h>
52#include <rtems/thread.h>
53
54#include <dev/can/can-frame.h>
55#include <dev/can/can-filter.h>
56
69 atomic_uint slot_flags;
75};
76
80#define RTEMS_CAN_SLOTF_CMD ( 0x00ff )
81
92 atomic_uint fifo_flags;
103 unsigned int out_taken;
107 unsigned long error_code;
139 rtems_mutex fifo_lock;
140};
141
145#define RTEMS_CAN_FIFOF_DESTROY ( 1 << 15 )
149#define RTEMS_CAN_FIFOF_ERROR ( 1 << 14 )
153#define RTEMS_CAN_FIFOF_ERR2BLOCK ( 1 << 13 )
157#define RTEMS_CAN_FIFOF_BLOCK ( 1 << 12 )
161#define RTEMS_CAN_FIFOF_OVERRUN ( 1 << 11 )
165#define RTEMS_CAN_FIFOF_FULL ( 1 << 10 )
169#define RTEMS_CAN_FIFOF_EMPTY ( 1 << 9 )
173#define RTEMS_CAN_FIFOF_DEAD ( 1 << 8 )
177#define RTEMS_CAN_FIFOF_INACTIVE ( 1 << 7 )
181#define RTEMS_CAN_FIFOF_FREEONEMPTY ( 1 << 6 )
185#define RTEMS_CAN_FIFOF_READY ( 1 << 5 )
189#define RTEMS_CAN_FIFOF_NOTIFYPEND ( 1 << 4 )
190
205
220
222TAILQ_HEAD( rtems_can_queue_edges_list, rtems_can_queue_edge );
223
263 struct rtems_can_queue_edges_list *peershead;
278 atomic_uint edge_used;
289};
290
292TAILQ_HEAD( rtems_can_queue_ends_list, rtems_can_queue_ends );
293
304 struct rtems_can_queue_edges_list active[RTEMS_CAN_QUEUE_PRIO_NR];
309 struct rtems_can_queue_edges_list idle;
313 struct rtems_can_queue_edges_list inlist;
318 struct rtems_can_queue_edges_list outlist;
323 rtems_mutex ends_lock;
350 void (*notify)(
351 struct rtems_can_queue_ends *qends,
352 struct rtems_can_queue_edge *qedge,
353 int what
354 );
360};
361
365#define RTEMS_CAN_QUEUE_NOTIFY_EMPTY ( 1 )
369#define RTEMS_CAN_QUEUE_NOTIFY_SPACE ( 2 )
373#define RTEMS_CAN_QUEUE_NOTIFY_PROC ( 3 )
378#define RTEMS_CAN_QUEUE_NOTIFY_NOUSR ( 4 )
382#define RTEMS_CAN_QUEUE_NOTIFY_DEAD ( 5 )
386#define RTEMS_CAN_QUEUE_NOTIFY_DEAD_WANTED ( 6 )
390#define RTEMS_CAN_QUEUE_NOTIFY_ATTACH ( 7 )
391
408 struct rtems_can_queue_ends *qends,
409 struct rtems_can_queue_edge **qedgep,
410 struct rtems_can_queue_slot **slotp,
411 int cmd
412);
413
436 struct rtems_can_queue_ends *qends,
437 struct rtems_can_queue_edge **qedgep,
438 struct rtems_can_queue_slot **slotp,
439 const struct can_frame_header *header,
440 int cmd,
441 int prio
442);
443
458
475 struct rtems_can_queue_ends *qends,
476 struct rtems_can_queue_edge *qedge,
477 struct rtems_can_queue_slot *slot
478);
479
495 struct rtems_can_queue_ends *qends,
496 struct rtems_can_queue_edge *qedge,
497 struct rtems_can_queue_slot *slot
498);
499
515 struct rtems_can_queue_ends *qends,
516 struct rtems_can_queue_edge *src_edge,
517 struct can_frame *frame,
518 unsigned int flags2add
519);
520
537 struct rtems_can_queue_ends *qends,
538 struct rtems_can_queue_edge **qedgep,
539 struct rtems_can_queue_slot **slotp
540);
541
560 struct rtems_can_queue_ends *qends,
561 int prio_min
562);
563
579 struct rtems_can_queue_ends *qends,
580 struct rtems_can_queue_edge *qedge,
581 struct rtems_can_queue_slot *slot
582);
583
598 struct rtems_can_queue_ends *qends,
599 struct rtems_can_queue_edge *qedge,
600 struct rtems_can_queue_slot *slot
601);
602
617
628
642 struct rtems_can_queue_edge *qedge,
645);
646
657
668
679
692 struct rtems_can_queue_ends *qends,
693 int send_rest
694);
695
706
715
725
735
745
759 int allocated_slot_count,
760 int max_data_length
761);
762
772
784 int allocated_slot_countm,
785 int max_data_length
786);
787
799 struct rtems_can_queue_ends *qends,
800 struct timespec *ts
801);
802
817 struct rtems_can_queue_ends *qends,
818 struct rtems_can_queue_edge *qedge,
819 bool nowait,
820 rtems_interval timeout
821);
822
834 struct rtems_can_queue_ends *qends,
835 bool nonblock
836);
837
845
846#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:520
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:396
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:104
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:248
int rtems_can_queue_disconnect_edge(struct rtems_can_queue_edge *qedge)
This function disconnects edge from communication entities.
Definition: can-queue.c:585
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:401
int rtems_can_queue_kern_initialize(void)
This function provides initialization of kernel queue side.
Definition: can-quekern.c:433
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:132
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:304
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:48
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:534
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:326
void rtems_can_queue_edge_do_dead(struct rtems_can_queue_edge *qedge)
This function disconnects the edge.
Definition: can-quekern.c:138
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:438
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:227
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:278
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:74
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:708
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:207
void rtems_can_queue_do_edge_decref(struct rtems_can_queue_edge *edge)
This function decrements the edge user counter.
Definition: can-queue.c:99
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:349
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:673
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:470
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:722
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:314
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:655
int rtems_can_queue_flush(struct rtems_can_queue_edge *qedge)
This function flushes all ready slots in the edge.
Definition: can-queue.c:498
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:732
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:236
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:664
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:188
Watchdog_Interval rtems_interval
This type represents clock tick intervals.
Definition: types.h:114
Provide printf() PRIxxx Constante Beyond Standards.
This header file defines the RTEMS Classic API.
Header File for Status Checks.
This structure represents the CAN message header.
Definition: can-frame.h:506
This structure represents one CAN frame. It consists of CAN header and data.
Definition: can-frame.h:534
This structure is used to represent CAN ID and flags in one unified structure.
Definition: can-filter.h:50
This structure represents one direction connection from messages source ( input_ends) to message cons...
Definition: can-queue.h:231
struct rtems_can_queue_edges_list * peershead
This member holds the pointer to the activepeers head.
Definition: can-queue.h:263
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:283
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:273
atomic_uint edge_used
This member holds the atomic usage counter, mainly used for safe destruction of the edge.
Definition: can-queue.h:278
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:268
struct rtems_can_queue_fifo fifo
This member holds place where primitive rtems_can_queue_fifo FIFO is located.
Definition: can-queue.h:236
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:288
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:241
This structure represents place to connect edges to for CAN communication entity. The zero,...
Definition: can-queue.h:299
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:304
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:318
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:309
rtems_mutex ends_lock
This member holds the lock synchronizing operations between threads accessing the ends.
Definition: can-queue.h:323
struct rtems_can_queue_edges_list inlist
This member holds the list of outgoing edges input sides.
Definition: can-queue.h:313
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:350
This structure represents CAN FIFO queue. It is implemented as a single linked list of slots prepared...
Definition: can-queue.h:88
int allocated_slot_count
This member holds the number of allocated slots.
Definition: can-queue.h:134
unsigned int out_taken
This member holds the number of elements in the fifo.
Definition: can-queue.h:103
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:121
rtems_mutex fifo_lock
This member holds the lock to ensure atomicity of slot manipulation operations.
Definition: can-queue.h:139
int max_data_length
This member holds maximum data length of one CAN frame.
Definition: can-queue.h:130
struct rtems_can_queue_slot * entry
This member holds the pointer to the memory allocated for the list slots.
Definition: can-queue.h:126
unsigned long error_code
This member holds futher description of error condition.
Definition: can-queue.h:107
struct rtems_can_queue_slot * head
This member holds the pointer to the FIFO head, oldest slot.
Definition: can-queue.h:111
atomic_uint fifo_flags
This field holds global flags describing state of the FIFO.
Definition: can-queue.h:92
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:116
This structure represents one CAN message slot in the CAN FIFO queue.
Definition: can-queue.h:60
atomic_uint slot_flags
Space for flags and optional command describing action associated with slot data.
Definition: can-queue.h:69
struct can_frame frame
This member holds can_frame structure representing one CAN frame/message.
Definition: can-queue.h:74
struct rtems_can_queue_slot * next
Pointer to next/younger slot.
Definition: can-queue.h:64
This header file provides the API of Self-Contained Objects.
Timespec API.