RTEMS CAN/CAN FD Stack
Loading...
Searching...
No Matches
ctucanfd_txb.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
11/*
12 * Copyright (C) 2024 Michal Lenc <michallenc@seznam.cz> FEE CTU
13 * Copyright (C) 2024 Pavel Pisa <pisa@cmp.felk.cvut.cz> FEE CTU
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _DEV_CTUCANFD_CTUCANFD_TXB_H
38#define _DEV_CTUCANFD_CTUCANFD_TXB_H
39
40#include "ctucanfd_internal.h"
41
42#undef TXT_DONE
43#undef TXT_BF
44#undef TXT_MASK
45#undef TXT_ANY_DONE
46#undef TXB_BF
47#undef TXB_M
48#undef TXB_ALL
49#undef TXB_SH
50
51#define TXT_DONE 0x4
52#define TXT_BF 4
53#define TXT_MASK 0xf
54#define TXT_ANY_DONE \
55 ( ( TXT_DONE << ( 0 * TXT_BF ) ) | ( TXT_DONE << ( 1 * TXT_BF ) ) | \
56 ( TXT_DONE << ( 2 * TXT_BF ) ) | ( TXT_DONE << ( 3 * TXT_BF ) ) | \
57 ( TXT_DONE << ( 4 * TXT_BF ) ) | ( TXT_DONE << ( 5 * TXT_BF ) ) | \
58 ( TXT_DONE << ( 6 * TXT_BF ) ) | ( TXT_DONE << ( 7 * TXT_BF ) ) )
59#define TXTB_GET_STATUS( status, id ) \
60 ( ( status >> ( id * TXT_BF ) ) & TXT_MASK )
61
62#define TXB_BF 4
63#define TXB_MASK 0xf
64#define TXB_ALL 0xffffffff
65#define TXB_SH( idx ) ( idx * TXB_BF )
66
67static inline uint32_t ctucanfd_txb_slot_demote(
68 uint32_t txb_order,
69 int from,
70 int to
71)
72{
73 uint32_t txb_order_new;
74 uint32_t txb_move = ( txb_order >> TXB_SH( from ) ) & TXB_MASK;
75 uint32_t mask_from = TXB_ALL << TXB_SH( from );
76 uint32_t mask_to = TXB_ALL << TXB_SH( to );
77 txb_order_new = txb_move << TXB_SH( to );
78 txb_order_new |= txb_order & ( ~mask_from | ( mask_to << TXB_BF ) );
79 txb_order_new |= ( ( txb_order >> TXB_BF ) & ~mask_to ) & mask_from;
80 return txb_order_new;
81}
82
83static inline uint32_t ctucanfd_txb_slot_promote(
84 uint32_t txb_order,
85 int from,
86 int to
87)
88{
89 uint32_t txb_order_new;
90 uint32_t txb_move = ( txb_order >> TXB_SH( from ) ) & TXB_MASK;
91 uint32_t mask_from = TXB_ALL << TXB_SH( from );
92 uint32_t mask_to = TXB_ALL << TXB_SH( to );
93 txb_order_new = txb_move << TXB_SH( to );
94 txb_order_new |= ( txb_order ) & ( ~mask_to | ( mask_from << TXB_BF ) );
95 txb_order_new |= ( ( ( txb_order & mask_to ) & ~mask_from ) << TXB_BF );
96 return txb_order_new;
97}
98
99static inline uint32_t ctucanfd_txb_order2prio( uint32_t txb_order )
100{
101 uint32_t prio = 0;
102 int i = RTEMS_CTUCANFD_NTXBUFS_MAX - 1;
103 do {
104 prio |= i << ( 4 * ( txb_order & TXB_MASK ) );
105 txb_order >>= TXB_BF;
106 } while ( i-- );
107
108 return prio;
109}
110
111static inline unsigned int ctucanfd_txb_from_order(
112 uint32_t txb_order,
113 unsigned int at
114)
115{
116 return ( txb_order >> TXB_SH( at ) ) & TXB_MASK;
117}
118
119#endif /* _DEV_CTUCANFD_CTUCANFD_TXB_H */
#define RTEMS_CTUCANFD_NTXBUFS_MAX
This defines the maximum number of TX buffers.
Definition: ctucanfd.h:53
This file is part of CTU CAN FD core driver implementation.