Radio Control Layer (RCL)
RCL_Buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2023, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the 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 "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef ti_drivers_RCL_Buffers_h__include
34 #define ti_drivers_RCL_Buffers_h__include
35 
36 #include <stdint.h>
37 #include <ti/drivers/utils/List.h>
38 
39 
43 typedef enum {
48 
49 typedef struct RCL_Buffer_TxBuffer_s RCL_Buffer_TxBuffer;
50 typedef struct RCL_Buffer_DataEntry_s RCL_Buffer_DataEntry;
51 typedef struct RCL_MultiBuffer_s RCL_MultiBuffer;
52 typedef struct RCL_MultiBuffer_ListInfo_s RCL_MultiBuffer_ListInfo;
53 
60  List_Elem __elem__;
62  uint16_t length __attribute__ ((aligned (4)));
63  uint8_t numPad;
64  uint8_t pad0;
65  uint8_t data[];
66 };
67 
75  uint16_t length __attribute__ ((aligned (4)));
76  uint8_t numPad;
77  uint8_t pad0;
78  uint8_t data[];
79 };
80 
88  List_Elem __elem__;
90  uint16_t length;
91  uint16_t headIndex;
92  uint16_t tailIndex;
93  uint8_t data[];
94 };
95 
103  List_List *multiBuffers;
104  RCL_MultiBuffer *nextBuffer;
105  uint16_t nextIndex;
106 };
107 
111 #define RCL_Buffer_bytesToWords(byteLen) (((byteLen) + sizeof(uint32_t) - 1) / sizeof(uint32_t))
112 
116 /* Include the data entry's length field and padding to uint32_t boundary */
117 #define RCL_Buffer_DataEntry_paddedLen(len) (RCL_Buffer_bytesToWords((len) + sizeof(uint16_t)) * sizeof(uint32_t))
118 
134 #define RCL_Buffer_entryLen(numPad, hdrLen, dataLen) (RCL_Buffer_DataEntry_paddedLen(sizeof(uint8_t) + (numPad) + (hdrLen) + (dataLen)))
135 
146 #define RCL_TxBuffer_len(numPad, hdrLen, dataLen) (offsetof(RCL_Buffer_TxBuffer, length) + RCL_Buffer_entryLen(numPad, hdrLen, dataLen))
147 
158 #define RCL_TxBuffer_len_u32(numPad, hdrLen, dataLen) (RCL_Buffer_bytesToWords(RCL_TxBuffer_len(numPad, hdrLen, dataLen)))
159 
166 #define RCL_MultiBuffer_len(dataLen) (offsetof(RCL_MultiBuffer, data) + (dataLen))
167 
174 #define RCL_MultiBuffer_len_u32(dataLen) (RCL_Buffer_bytesToWords(RCL_MultiBuffer_len(dataLen)))
175 
183 static inline RCL_Buffer_TxBuffer *RCL_TxBuffer_get(List_List *list)
184 {
185  return (RCL_Buffer_TxBuffer *)List_get(list);
186 }
187 
198 static inline RCL_Buffer_TxBuffer *RCL_TxBuffer_head(List_List *list)
199 {
200  return (RCL_Buffer_TxBuffer *) (list->head);
201 }
202 
213 static inline RCL_Buffer_TxBuffer *RCL_TxBuffer_next(RCL_Buffer_TxBuffer *elem)
214 {
215  return (RCL_Buffer_TxBuffer *)(((List_Elem *)elem)->next);
216 }
217 
233 extern uint8_t *RCL_TxBuffer_init(RCL_Buffer_TxBuffer *buffer, uint32_t numPad, uint32_t hdrLen,
234  uint32_t dataLen);
235 
245 extern void RCL_TxBuffer_put(List_List *list, RCL_Buffer_TxBuffer *elem);
246 
257 static inline RCL_MultiBuffer *RCL_MultiBuffer_head(List_List *list)
258 {
259  return (RCL_MultiBuffer *) (list->head);
260 }
261 
272 static inline RCL_MultiBuffer *RCL_MultiBuffer_next(RCL_MultiBuffer *elem)
273 {
274  return (RCL_MultiBuffer *)(((List_Elem *)elem)->next);
275 }
276 
288 static inline RCL_MultiBuffer *RCL_MultiBuffer_get(List_List *list)
289 {
290  return (RCL_MultiBuffer *)List_get(list);
291 }
292 
301 extern void RCL_MultiBuffer_clear(RCL_MultiBuffer *buffer);
302 
313 extern void RCL_MultiBuffer_init(RCL_MultiBuffer *buffer, size_t size);
314 
334 extern RCL_Buffer_DataEntry *RCL_MultiBuffer_RxEntry_get(List_List *list, List_List *consumedBuffers);
335 
347 extern bool RCL_MultiBuffer_RxEntry_isEmpty(List_List *list);
348 
362 extern void RCL_MultiBuffer_ListInfo_init(RCL_MultiBuffer_ListInfo *listInfo, List_List *list);
363 
378 extern RCL_Buffer_DataEntry *RCL_MultiBuffer_RxEntry_next(RCL_MultiBuffer_ListInfo *listInfo);
379 
392 extern bool RCL_MultiBuffer_RxEntry_isLast(RCL_MultiBuffer_ListInfo *listInfo);
393 
403 extern void RCL_MultiBuffer_put(List_List *list, RCL_MultiBuffer *elem);
420 RCL_MultiBuffer *RCL_MultiBuffer_findFirstWritableBuffer(RCL_MultiBuffer *head);
421 
441 RCL_MultiBuffer *RCL_MultiBuffer_getBuffer(RCL_MultiBuffer *curBuffer,
442  uint32_t minLength);
443 
457 uint32_t RCL_MultiBuffer_findAvailableRxSpace(const RCL_MultiBuffer *curBuffer);
458 
468 static inline uint8_t *RCL_MultiBuffer_getNextWritableByte(RCL_MultiBuffer *curBuffer)
469 {
470  return & curBuffer->data[curBuffer->tailIndex];
471 }
472 
484 static inline void RCL_MultiBuffer_commitBytes(RCL_MultiBuffer *curBuffer, uint32_t numBytes)
485 {
486  curBuffer->tailIndex += numBytes;
487 }
491 #endif
void RCL_TxBuffer_put(List_List *list, RCL_Buffer_TxBuffer *elem)
Function to atomically put an elem onto the end of a Tx Buffer list.
Definition: RCL_Buffer.c:58
void RCL_MultiBuffer_ListInfo_init(RCL_MultiBuffer_ListInfo *listInfo, List_List *list)
Function to initialize information for traversing a multi buffer list.
Definition: RCL_Buffer.c:188
Information about an RCL_MultiBuffer list being traversed.
Definition: RCL_Buffer.h:102
Definition: RCL_Buffer.h:44
static uint8_t * RCL_MultiBuffer_getNextWritableByte(RCL_MultiBuffer *curBuffer)
Find the first byte to write in an RCL_MultiBuffer.
Definition: RCL_Buffer.h:467
uint8_t numPad
Definition: RCL_Buffer.h:63
List_Elem __elem__
Definition: RCL_Buffer.h:88
Definition of an RCL Rx MultiBuffer.
Definition: RCL_Buffer.h:87
RCL_BufferState state
Definition: RCL_Buffer.h:89
uint16_t tailIndex
Definition: RCL_Buffer.h:92
Definition: RCL_Buffer.h:46
static void RCL_MultiBuffer_commitBytes(RCL_MultiBuffer *curBuffer, uint32_t numBytes)
Update number of bytes written to RCL_MultiBuffer.
Definition: RCL_Buffer.h:483
RCL_MultiBuffer * RCL_MultiBuffer_getBuffer(RCL_MultiBuffer *curBuffer, uint32_t minLength)
Returns a buffer with at least minLength bytes remaining capacity.
Definition: RCL_Buffer.c:313
List_Elem __elem__
Definition: RCL_Buffer.h:60
RCL_BufferState state
Definition: RCL_Buffer.h:61
Definition of an RCL Rx Buffer Entry.
Definition: RCL_Buffer.h:74
uint8_t numPad
Definition: RCL_Buffer.h:76
uint8_t data[]
Definition: RCL_Buffer.h:65
void RCL_MultiBuffer_put(List_List *list, RCL_MultiBuffer *elem)
Function to atomically put an elem onto the end of a multi buffer list.
Definition: RCL_Buffer.c:117
RCL_Buffer_DataEntry * RCL_MultiBuffer_RxEntry_get(List_List *list, List_List *consumedBuffers)
Function to get the first entry in a MultiBuffer list.
Definition: RCL_Buffer.c:127
uint8_t * RCL_TxBuffer_init(RCL_Buffer_TxBuffer *buffer, uint32_t numPad, uint32_t hdrLen, uint32_t dataLen)
Function to initialize a TX buffer entry for use by RCL.
Definition: RCL_Buffer.c:69
void RCL_MultiBuffer_clear(RCL_MultiBuffer *buffer)
Function to clear a multi buffer entry for re-use by RCL.
Definition: RCL_Buffer.c:95
uint16_t length __attribute__((aligned(4)))
static RCL_MultiBuffer * RCL_MultiBuffer_get(List_List *list)
Function to get the first elem in a MultiBuffer list.
Definition: RCL_Buffer.h:288
RCL_Buffer_DataEntry * RCL_MultiBuffer_RxEntry_next(RCL_MultiBuffer_ListInfo *listInfo)
Function to return the next entry in a list of multi buffers.
Definition: RCL_Buffer.c:208
bool RCL_MultiBuffer_RxEntry_isLast(RCL_MultiBuffer_ListInfo *listInfo)
Function to check a traversed entry was the last one.
Definition: RCL_Buffer.c:258
uint8_t pad0
Definition: RCL_Buffer.h:77
static RCL_Buffer_TxBuffer * RCL_TxBuffer_head(List_List *list)
Function to return the head of a TxBuffer list.
Definition: RCL_Buffer.h:198
static RCL_MultiBuffer * RCL_MultiBuffer_head(List_List *list)
Function to return the head of a MultiBuffer list.
Definition: RCL_Buffer.h:257
RCL_MultiBuffer * nextBuffer
Definition: RCL_Buffer.h:104
uint16_t nextIndex
Definition: RCL_Buffer.h:105
uint16_t headIndex
Definition: RCL_Buffer.h:91
static RCL_Buffer_TxBuffer * RCL_TxBuffer_next(RCL_Buffer_TxBuffer *elem)
Function to return the next elem in a linked list of Tx Buffers.
Definition: RCL_Buffer.h:213
uint16_t length
Definition: RCL_Buffer.h:90
List_List * multiBuffers
Definition: RCL_Buffer.h:103
Definition: RCL_Buffer.h:45
void RCL_MultiBuffer_init(RCL_MultiBuffer *buffer, size_t size)
Function to initialize a multi buffer entry for use by RCL.
Definition: RCL_Buffer.c:105
RCL_BufferState
Buffer state.
Definition: RCL_Buffer.h:43
Definition of an RCL Tx Buffer.
Definition: RCL_Buffer.h:59
uint32_t RCL_MultiBuffer_findAvailableRxSpace(const RCL_MultiBuffer *curBuffer)
Find the minumum number of bytes that can be stored in available MultiBuffers.
Definition: RCL_Buffer.c:367
bool RCL_MultiBuffer_RxEntry_isEmpty(List_List *list)
Function to check if the MultiBuffer List is out of entries.
Definition: RCL_Buffer.c:172
static RCL_MultiBuffer * RCL_MultiBuffer_next(RCL_MultiBuffer *elem)
Function to return the next elem in a linked list of MultiBuffers.
Definition: RCL_Buffer.h:272
RCL_MultiBuffer * RCL_MultiBuffer_findFirstWritableBuffer(RCL_MultiBuffer *head)
Find the first writable buffer in a list of MultiBuffers.
Definition: RCL_Buffer.c:300
static RCL_Buffer_TxBuffer * RCL_TxBuffer_get(List_List *list)
Function to atomically get the first elem in a Tx Buffer list.
Definition: RCL_Buffer.h:183
uint8_t pad0
Definition: RCL_Buffer.h:64