RTEMS 7.0-rc1
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 ( ( TXT_DONE << ( 0 * TXT_BF ) ) | \
55 ( TXT_DONE << ( 1 * TXT_BF ) ) | \
56 ( TXT_DONE << ( 2 * TXT_BF ) ) | \
57 ( TXT_DONE << ( 3 * TXT_BF ) ) | \
58 ( TXT_DONE << ( 4 * TXT_BF ) ) | \
59 ( TXT_DONE << ( 5 * TXT_BF ) ) | \
60 ( TXT_DONE << ( 6 * TXT_BF ) ) | \
61 ( TXT_DONE << ( 7 * TXT_BF ) ) )
62#define TXTB_GET_STATUS( status, id ) ( ( status >> ( id * TXT_BF ) ) & \
63 TXT_MASK)
64
65#define TXB_BF 4
66#define TXB_MASK 0xf
67#define TXB_ALL 0xffffffff
68#define TXB_SH(idx) (idx * TXB_BF)
69
70static inline uint32_t ctucanfd_txb_slot_demote(
71 uint32_t txb_order,
72 int from,
73 int to
74)
75{
76 uint32_t txb_order_new;
77 uint32_t txb_move = ( txb_order >> TXB_SH( from ) ) & TXB_MASK;
78 uint32_t mask_from = TXB_ALL << TXB_SH( from );
79 uint32_t mask_to = TXB_ALL << TXB_SH( to );
80 txb_order_new = txb_move << TXB_SH( to );
81 txb_order_new |= txb_order & ( ~mask_from | ( mask_to << TXB_BF ) );
82 txb_order_new |= ( ( txb_order >> TXB_BF) & ~mask_to ) & mask_from;
83 return txb_order_new;
84}
85
86static inline uint32_t ctucanfd_txb_slot_promote(
87 uint32_t txb_order,
88 int from,
89 int to
90)
91{
92 uint32_t txb_order_new;
93 uint32_t txb_move = ( txb_order >> TXB_SH( from ) ) & TXB_MASK;
94 uint32_t mask_from = TXB_ALL << TXB_SH( from );
95 uint32_t mask_to = TXB_ALL << TXB_SH( to );
96 txb_order_new = txb_move << TXB_SH( to );
97 txb_order_new |= ( txb_order ) & ( ~mask_to | ( mask_from << TXB_BF ) );
98 txb_order_new |= ( ( (txb_order & mask_to ) & ~mask_from ) << TXB_BF );
99 return txb_order_new;
100}
101
102static inline uint32_t ctucanfd_txb_order2prio( uint32_t txb_order )
103{
104 uint32_t prio = 0;
105 int i = RTEMS_CTUCANFD_NTXBUFS_MAX - 1;
106 do {
107 prio |= i << ( 4 * ( txb_order & TXB_MASK ) );
108 txb_order >>= TXB_BF;
109 } while ( i-- );
110
111 return prio;
112}
113
114static inline unsigned int ctucanfd_txb_from_order(
115 uint32_t txb_order,
116 unsigned int at
117)
118{
119 return ( txb_order >> TXB_SH ( at ) ) & TXB_MASK;
120}
121
122#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.