PDK API Guide for J721E
bufpool.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Texas Instruments Incorporated 2021
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 
39 #ifndef BUFPOOL_H_
40 #define BUFPOOL_H_
41 
42 /* ========================================================================== */
43 /* Include Files */
44 /* ========================================================================== */
45 #include <stdio.h>
46 #include <stdlib.h>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /* ========================================================================== */
53 /* Macros */
54 /* ========================================================================== */
55 
57 #define BUFPOOL_MEM_LEN (BUFPOOL_MAX_POOLS * sizeof(BufPool_Pool))
58 
60 #define ETH_MAX_PAYLOAD (1514)
61 
62 #define VLAN_TAG_SIZE (4U)
63 
65 #define ETH_FRAME_SIZE (ETH_MAX_PAYLOAD + VLAN_TAG_SIZE)
66 
68 #define BUFPOOL_MCU2_0_R5 (0)
69 
70 #define BUFPOOL_MCU2_1 (1)
71 
72 #define BUFPOOL_A72 (2)
73 
74 #define BUFPOOL_MCU2_0_A72 (3)
75 
76 #define BUFPOOL_MAX_POOLS (4)
77 
79 #define BUFPOOL_BUF_MAX (1280U)
80 
82 #define BUFPOOL_OK (0)
83 
84 #define BUFPOOL_ERROR (-1)
85 
86 /* ========================================================================== */
87 /* Structures and Enums */
88 /* ========================================================================== */
89 
93 typedef struct BufPool_Buf_s
94 {
96  uint8_t payload[ETH_FRAME_SIZE];
97 
99  uint16_t payloadLen;
100 
102  int16_t refCount;
103 
105  int16_t isUsed;
106 
108  uint32_t poolId;
109 
111  uint8_t pad[8];
112 
113 } BufPool_Buf;
114 
118 typedef struct BufPool_Pool_s
119 {
121  uint32_t poolId;
122 
124  int32_t lastFreed;
125 
127  int32_t lastAlloc;
128 
130  uint32_t magic;
131 
133  uint32_t maxSize;
134 
136  uint32_t numBufGet;
137 
139  uint32_t numBufFree;
140 
142  uint32_t numBufGetErr;
143 
146 
147 } BufPool_Pool;
148 
154 typedef struct BufPool_Pool_s* BufPool_Handle;
155 
157 #define BUF_OBJ_SIZE_IN_BYTES (sizeof(BufPool_Buf))
158 
159 /* ========================================================================== */
160 /* External Variable Declarations */
161 /* ========================================================================== */
162 
164 
165 /* ========================================================================== */
166 /* API/Public Function Declarations */
167 /* ========================================================================== */
168 
181 int32_t BufPool_init(BufPool_Handle hBufPool,
182  uint32_t poolId,
183  uint32_t maxSize);
184 
197 
209 int32_t BufPool_freeBuf(BufPool_Buf* hBuf);
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 
215 #endif /* BUFPOOL_H_ */
int32_t BufPool_freeBuf(BufPool_Buf *hBuf)
Decrements the ref count of a buffer object.
#define ETH_FRAME_SIZE
Definition: bufpool.h:65
int32_t lastFreed
Definition: bufpool.h:124
int32_t lastAlloc
Definition: bufpool.h:127
uint16_t payloadLen
Definition: bufpool.h:99
uint32_t maxSize
Definition: bufpool.h:133
BufPool_Buf * BufPool_getBuf(BufPool_Handle hBufPool)
Returns a pointer to a free buffer.
Fixed size buffer pool.
Definition: bufpool.h:118
uint32_t numBufGetErr
Definition: bufpool.h:142
struct BufPool_Pool_s * BufPool_Handle
BufPool handle.
Definition: bufpool.h:154
int16_t refCount
Definition: bufpool.h:102
Fixed size data buffer.
Definition: bufpool.h:93
int32_t BufPool_init(BufPool_Handle hBufPool, uint32_t poolId, uint32_t maxSize)
Initializes a buffer pool.
uint32_t numBufGet
Definition: bufpool.h:136
int16_t isUsed
Definition: bufpool.h:105
uint32_t magic
Definition: bufpool.h:130
uint32_t poolId
Definition: bufpool.h:108
uint32_t poolId
Definition: bufpool.h:121
uint32_t numBufFree
Definition: bufpool.h:139
BufPool_Handle BufPoolTable_Handle
#define BUFPOOL_BUF_MAX
Definition: bufpool.h:79