AM263Px MCU+ SDK: enet_dma_pktutils.h Source File

| AM263Px MCU+ SDK 26.00.00 |

enet_dma_pktutils.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) Texas Instruments Incorporated 2020
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
46 #ifndef ENET_DMA_PKTUTILS_H_
47 #define ENET_DMA_PKTUTILS_H_
48
49 /* ========================================================================== */
50 /* Include Files */
51 /* ========================================================================== */
52
53 #include <stdarg.h>
54 #include <include/core/enet_utils.h>
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 /* ========================================================================== */
61 /* Macros & Typedefs */
62 /* ========================================================================== */
63
64 #define ENET_UTILS_GET_STATE(state, mask, bitshift) ((*(state) & (mask)) >> (bitshift))
65 #define ENET_UTILS_SET_STATE(state, mask, bitshift, value) \
66 ({ \
67 *(state) &= ~(mask); \
68 *(state) |= ((value) << (bitshift)); \
69 })
70
71 #define ENET_UTILS_DRIVER_STATE_MASK (0x000000FFU)
72 #define ENET_UTILS_DRIVER_STATE_BIT_SHIFT (0U)
73
74 #define ENET_DMA_MEMMGR_STATE_MASK (0x0000FF00U)
75 #define ENET_DMA_MEMMGR_STATE_BIT_SHIFT (8U)
76
77 #define ENET_UTILS_APP_STATE_MASK (0x00FF0000U)
78 #define ENET_UTILS_APP_STATE_BIT_SHIFT (16U)
79
80 #define ENET_UTILS_GET_PKT_DRIVER_STATE(state) \
81 (ENET_UTILS_GET_STATE(state, \
82 ENET_UTILS_DRIVER_STATE_MASK, \
83 ENET_UTILS_DRIVER_STATE_BIT_SHIFT))
84
85 #define ENET_UTILS_SET_PKT_DRIVER_STATE(state, value) \
86 (ENET_UTILS_SET_STATE(state, \
87 ENET_UTILS_DRIVER_STATE_MASK, \
88 ENET_UTILS_DRIVER_STATE_BIT_SHIFT, \
89 value))
90
91 #define ENET_UTILS_GET_PKT_MEMMGR_STATE(state) \
92 (ENET_UTILS_GET_STATE(state, \
93 ENET_DMA_MEMMGR_STATE_MASK, \
94 ENET_DMA_MEMMGR_STATE_BIT_SHIFT))
95
96 #define ENET_UTILS_SET_PKT_MEMMGR_STATE(state, value) \
97 (ENET_UTILS_SET_STATE(state, \
98 ENET_DMA_MEMMGR_STATE_MASK, \
99 ENET_DMA_MEMMGR_STATE_BIT_SHIFT, \
100 value))
101
102 #define ENET_UTILS_GET_PKT_APP_STATE(state) \
103 (ENET_UTILS_GET_STATE(state, \
104 ENET_UTILS_APP_STATE_MASK, \
105 ENET_UTILS_APP_STATE_BIT_SHIFT))
106
107 #define ENET_UTILS_SET_PKT_APP_STATE(state, value) \
108 (ENET_UTILS_SET_STATE(state, \
109 ENET_UTILS_APP_STATE_MASK, \
110 ENET_UTILS_APP_STATE_BIT_SHIFT, \
111 value))
112
113 #define ENET_DMA_MEMMGR_DESCSTATE_MASK (0x000000FFU)
114 #define ENET_DMA_MEMMGR_DESCSTATE_SHIFT (0U)
115
116 #define ENET_UTILS_GET_DESC_MEMMGR_STATE(state) \
117 (ENET_UTILS_GET_STATE(state, \
118 ENET_DMA_MEMMGR_DESCSTATE_MASK, \
119 ENET_DMA_MEMMGR_DESCSTATE_SHIFT))
120
121 #define ENET_UTILS_SET_DESC_MEMMGR_STATE(state, value) \
122 (ENET_UTILS_SET_STATE(state, \
123 ENET_DMA_MEMMGR_DESCSTATE_MASK, \
124 ENET_DMA_MEMMGR_DESCSTATE_SHIFT, \
125 value))
126
132 typedef enum EnetDma_DescStateMemMgr_e
133 {
135 ENET_DESCSTATE_MEMMGR_FREE = 0U,
136
138 ENET_DESCSTATE_MEMMGR_ALLOC
139 } EnetDma_DescStateMemMgr;
140
146 typedef enum EnetDma_PktStateApp_e
147 {
149 ENET_PKTSTATE_APP_WITH_FREEQ = 0U,
150
152 ENET_PKTSTATE_APP_WITH_READYQ,
153
155 ENET_PKTSTATE_APP_WITH_DRIVER
156 } EnetDma_PktStateApp;
157
163 typedef enum EnetDma_PktStateDma_e
164 {
166 ENET_PKTSTATE_DMA_WITH_HW = 0U,
167
169 ENET_PKTSTATE_DMA_NOT_WITH_HW
170 } EnetDma_PktStateDma;
171
177 typedef enum EnetDma_PktStateMemMgr_e
178 {
180 ENET_PKTSTATE_MEMMGR_FREE = 0U,
181
183 ENET_PKTSTATE_MEMMGR_ALLOC,
184 } EnetDma_PktStateMemMgr;
185
191 typedef enum EnetDma_PktStateModuleType_e
192 {
194 ENET_PKTSTATE_MODULE_APP = 0U,
195
197 ENET_PKTSTATE_MODULE_DRIVER,
198
200 ENET_PKTSTATE_MODULE_MEMMGR,
201 } EnetDma_PktStateModuleType;
202
203 /* ========================================================================== */
204 /* Structure Declarations */
205 /* ========================================================================== */
206
207 /* ========================================================================== */
208 /* Function Declarations */
209 /* ========================================================================== */
210
229 static inline void EnetDma_checkPktState(uint32_t *pStateVar,
230 EnetDma_PktStateModuleType module,
231 uint32_t expectedState,
232 uint32_t newState);
233
249 static inline void EnetDma_checkDescState(uint32_t *pStateVar,
250 EnetDma_DescStateMemMgr expectedState,
251 EnetDma_DescStateMemMgr newState);
252
253 /* ========================================================================== */
254 /* Static Function Definitions */
255 /* ========================================================================== */
256
257 static inline void EnetDma_checkDescState(uint32_t *pStateVar,
258 EnetDma_DescStateMemMgr expectedState,
259 EnetDma_DescStateMemMgr newState)
260 {
261 Enet_assert(ENET_UTILS_GET_DESC_MEMMGR_STATE(pStateVar) == expectedState);
262 ENET_UTILS_SET_DESC_MEMMGR_STATE(pStateVar, newState);
263 }
264
265 static inline void EnetDma_checkPktState(uint32_t *pStateVar,
266 EnetDma_PktStateModuleType module,
267 uint32_t expectedState,
268 uint32_t newState)
269 {
270 switch (module)
271 {
272 case ENET_PKTSTATE_MODULE_APP:
273 Enet_assert(ENET_UTILS_GET_PKT_APP_STATE(pStateVar) == expectedState);
274 ENET_UTILS_SET_PKT_APP_STATE(pStateVar, newState);
275 break;
276
277 case ENET_PKTSTATE_MODULE_DRIVER:
278 Enet_assert(ENET_UTILS_GET_PKT_DRIVER_STATE(pStateVar) == expectedState);
279 ENET_UTILS_SET_PKT_DRIVER_STATE(pStateVar, newState);
280 break;
281
282 case ENET_PKTSTATE_MODULE_MEMMGR:
283 Enet_assert(ENET_UTILS_GET_PKT_MEMMGR_STATE(pStateVar) == expectedState);
284 ENET_UTILS_SET_PKT_MEMMGR_STATE(pStateVar, newState);
285 break;
286
287 default:
288 break;
289 }
290 }
291
292 #ifdef __cplusplus
293 }
294 #endif
295
296 #endif /* #ifndef ENET_DMA_PKTUTILS_H_ */
297
ENET_UTILS_GET_PKT_MEMMGR_STATE
#define ENET_UTILS_GET_PKT_MEMMGR_STATE(state)
Definition: enet_dma_pktutils.h:91
ENET_PKTSTATE_APP_WITH_DRIVER
@ ENET_PKTSTATE_APP_WITH_DRIVER
Definition: enet_dma_pktutils.h:155
ENET_UTILS_SET_PKT_APP_STATE
#define ENET_UTILS_SET_PKT_APP_STATE(state, value)
Definition: enet_dma_pktutils.h:107
EnetDma_PktStateModuleType
EnetDma_PktStateModuleType
Enet DMA Pkt state.
Definition: enet_dma_pktutils.h:192
ENET_PKTSTATE_APP_WITH_READYQ
@ ENET_PKTSTATE_APP_WITH_READYQ
Definition: enet_dma_pktutils.h:152
ENET_PKTSTATE_DMA_NOT_WITH_HW
@ ENET_PKTSTATE_DMA_NOT_WITH_HW
Definition: enet_dma_pktutils.h:169
ENET_UTILS_GET_PKT_DRIVER_STATE
#define ENET_UTILS_GET_PKT_DRIVER_STATE(state)
Definition: enet_dma_pktutils.h:80
ENET_PKTSTATE_APP_WITH_FREEQ
@ ENET_PKTSTATE_APP_WITH_FREEQ
Definition: enet_dma_pktutils.h:149
ENET_PKTSTATE_DMA_WITH_HW
@ ENET_PKTSTATE_DMA_WITH_HW
Definition: enet_dma_pktutils.h:166
ENET_PKTSTATE_MEMMGR_ALLOC
@ ENET_PKTSTATE_MEMMGR_ALLOC
Definition: enet_dma_pktutils.h:183
ENET_UTILS_SET_PKT_MEMMGR_STATE
#define ENET_UTILS_SET_PKT_MEMMGR_STATE(state, value)
Definition: enet_dma_pktutils.h:96
ENET_UTILS_SET_DESC_MEMMGR_STATE
#define ENET_UTILS_SET_DESC_MEMMGR_STATE(state, value)
Definition: enet_dma_pktutils.h:121
EnetDma_checkPktState
static void EnetDma_checkPktState(uint32_t *pStateVar, EnetDma_PktStateModuleType module, uint32_t expectedState, uint32_t newState)
Packet state check & set API for app, memory manager and dma driver.
Definition: enet_dma_pktutils.h:265
EnetDma_PktStateDma
EnetDma_PktStateDma
DMA Pkt state.
Definition: enet_dma_pktutils.h:164
ENET_PKTSTATE_MODULE_DRIVER
@ ENET_PKTSTATE_MODULE_DRIVER
Definition: enet_dma_pktutils.h:197
EnetDma_checkDescState
static void EnetDma_checkDescState(uint32_t *pStateVar, EnetDma_DescStateMemMgr expectedState, EnetDma_DescStateMemMgr newState)
Descriptor state check & set API for descriptor memory manager.
Definition: enet_dma_pktutils.h:257
ENET_DESCSTATE_MEMMGR_FREE
@ ENET_DESCSTATE_MEMMGR_FREE
Definition: enet_dma_pktutils.h:135
ENET_UTILS_GET_PKT_APP_STATE
#define ENET_UTILS_GET_PKT_APP_STATE(state)
Definition: enet_dma_pktutils.h:102
ENET_PKTSTATE_MODULE_MEMMGR
@ ENET_PKTSTATE_MODULE_MEMMGR
Definition: enet_dma_pktutils.h:200
ENET_PKTSTATE_MEMMGR_FREE
@ ENET_PKTSTATE_MEMMGR_FREE
Definition: enet_dma_pktutils.h:180
EnetDma_PktStateApp
EnetDma_PktStateApp
App Pkt state.
Definition: enet_dma_pktutils.h:147
ENET_DESCSTATE_MEMMGR_ALLOC
@ ENET_DESCSTATE_MEMMGR_ALLOC
Definition: enet_dma_pktutils.h:138
ENET_UTILS_GET_DESC_MEMMGR_STATE
#define ENET_UTILS_GET_DESC_MEMMGR_STATE(state)
Definition: enet_dma_pktutils.h:116
ENET_UTILS_SET_PKT_DRIVER_STATE
#define ENET_UTILS_SET_PKT_DRIVER_STATE(state, value)
Definition: enet_dma_pktutils.h:85
EnetDma_DescStateMemMgr
EnetDma_DescStateMemMgr
Enet DMA Descriptor state.
Definition: enet_dma_pktutils.h:133
Enet_assert
#define Enet_assert(cond,...)
Assertion.
Definition: enet_utils.h:122
EnetDma_PktStateMemMgr
EnetDma_PktStateMemMgr
Enet DMA Pkt state.
Definition: enet_dma_pktutils.h:178
ENET_PKTSTATE_MODULE_APP
@ ENET_PKTSTATE_MODULE_APP
Definition: enet_dma_pktutils.h:194
enet_utils.h
This file contains the type definitions and function prototypes of the Enet Utils functionality.