Radio Control Layer (RCL)
RCL_Buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2025, 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 
42 typedef enum {
47 
48 typedef struct RCL_Buffer_TxBuffer_s RCL_Buffer_TxBuffer;
49 typedef struct RCL_Buffer_DataEntry_s RCL_Buffer_DataEntry;
50 typedef struct RCL_MultiBuffer_s RCL_MultiBuffer;
51 typedef struct RCL_MultiBuffer_ListInfo_s RCL_MultiBuffer_ListInfo;
52 
59  List_Elem __elem__;
61  uint16_t length __attribute__ ((aligned (4)));
62  uint8_t numPad;
63  uint8_t pad0;
64  uint8_t data[];
65 };
66 
74  uint16_t length __attribute__ ((aligned (4)));
75  uint8_t numPad;
76  uint8_t pad0;
77  uint8_t data[];
78 };
79 
87  List_Elem __elem__;
89  uint16_t length;
90  uint16_t headIndex;
91  uint16_t tailIndex;
92  uint8_t data[];
93 };
94 
102  List_List *multiBuffers;
103  RCL_MultiBuffer *nextBuffer;
104  uint16_t nextIndex;
105 };
106 
110 #define RCL_Buffer_bytesToWords(byteLen) (((byteLen) + sizeof(uint32_t) - 1) / sizeof(uint32_t))
111 
115 /* Include the data entry's length field and padding to uint32_t boundary */
116 #define RCL_Buffer_DataEntry_paddedLen(len) (RCL_Buffer_bytesToWords((len) + sizeof(uint16_t)) * sizeof(uint32_t))
117 
133 #define RCL_Buffer_entryLen(numPad, hdrLen, dataLen) (RCL_Buffer_DataEntry_paddedLen(sizeof(uint8_t) + (numPad) + (hdrLen) + (dataLen)))
134 
145 #define RCL_TxBuffer_len(numPad, hdrLen, dataLen) (offsetof(RCL_Buffer_TxBuffer, length) + RCL_Buffer_entryLen(numPad, hdrLen, dataLen))
146 
157 #define RCL_TxBuffer_len_u32(numPad, hdrLen, dataLen) (RCL_Buffer_bytesToWords(RCL_TxBuffer_len(numPad, hdrLen, dataLen)))
158 
165 #define RCL_MultiBuffer_len(dataLen) (offsetof(RCL_MultiBuffer, data) + (dataLen))
166 
173 #define RCL_MultiBuffer_len_u32(dataLen) (RCL_Buffer_bytesToWords(RCL_MultiBuffer_len(dataLen)))
174 
182 static inline RCL_Buffer_TxBuffer *RCL_TxBuffer_get(List_List *list)
183 {
184  return (RCL_Buffer_TxBuffer *)List_get(list);
185 }
186 
197 static inline RCL_Buffer_TxBuffer *RCL_TxBuffer_head(List_List *list)
198 {
199  return (RCL_Buffer_TxBuffer *) (list->head);
200 }
201 
212 static inline RCL_Buffer_TxBuffer *RCL_TxBuffer_next(RCL_Buffer_TxBuffer *elem)
213 {
214  return (RCL_Buffer_TxBuffer *)(((List_Elem *)elem)->next);
215 }
216 
232 extern uint8_t *RCL_TxBuffer_init(RCL_Buffer_TxBuffer *buffer, uint32_t numPad, uint32_t hdrLen,
233  uint32_t dataLen);
234 
244 extern void RCL_TxBuffer_put(List_List *list, RCL_Buffer_TxBuffer *elem);
245 
256 static inline RCL_MultiBuffer *RCL_MultiBuffer_head(List_List *list)
257 {
258  return (RCL_MultiBuffer *) (list->head);
259 }
260 
271 static inline RCL_MultiBuffer *RCL_MultiBuffer_next(RCL_MultiBuffer *elem)
272 {
273  return (RCL_MultiBuffer *)(((List_Elem *)elem)->next);
274 }
275 
287 static inline RCL_MultiBuffer *RCL_MultiBuffer_get(List_List *list)
288 {
289  return (RCL_MultiBuffer *)List_get(list);
290 }
291 
300 extern void RCL_MultiBuffer_clear(RCL_MultiBuffer *buffer);
301 
312 extern void RCL_MultiBuffer_init(RCL_MultiBuffer *buffer, size_t size);
313 
333 extern RCL_Buffer_DataEntry *RCL_MultiBuffer_RxEntry_get(List_List *list, List_List *consumedBuffers);
334 
346 extern bool RCL_MultiBuffer_RxEntry_isEmpty(List_List *list);
347 
361 extern void RCL_MultiBuffer_ListInfo_init(RCL_MultiBuffer_ListInfo *listInfo, List_List *list);
362 
377 extern RCL_Buffer_DataEntry *RCL_MultiBuffer_RxEntry_next(RCL_MultiBuffer_ListInfo *listInfo);
378 
391 extern bool RCL_MultiBuffer_RxEntry_isLast(RCL_MultiBuffer_ListInfo *listInfo);
392 
402 extern void RCL_MultiBuffer_put(List_List *list, RCL_MultiBuffer *elem);
403 
420  size_t RCL_Buffer_readPartialRxBuffer(RCL_Buffer_DataEntry *dataEntry, size_t entrySize);
437 RCL_MultiBuffer *RCL_MultiBuffer_findFirstWritableBuffer(RCL_MultiBuffer *head);
438 
458 RCL_MultiBuffer *RCL_MultiBuffer_getBuffer(RCL_MultiBuffer *curBuffer,
459  uint32_t minLength);
460 
474 uint32_t RCL_MultiBuffer_findAvailableRxSpace(const RCL_MultiBuffer *curBuffer);
475 
485 static inline uint8_t *RCL_MultiBuffer_getNextWritableByte(RCL_MultiBuffer *curBuffer)
486 {
487  return & curBuffer->data[curBuffer->tailIndex];
488 }
489 
501 static inline void RCL_MultiBuffer_commitBytes(RCL_MultiBuffer *curBuffer, uint32_t numBytes)
502 {
503  curBuffer->tailIndex += numBytes;
504 }
508 #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:194
Information about an RCL_MultiBuffer list being traversed.
Definition: RCL_Buffer.h:101
Definition: RCL_Buffer.h:43
static uint8_t * RCL_MultiBuffer_getNextWritableByte(RCL_MultiBuffer *curBuffer)
Find the first byte to write in an RCL_MultiBuffer.
Definition: RCL_Buffer.h:484
uint8_t numPad
Definition: RCL_Buffer.h:62
List_Elem __elem__
Definition: RCL_Buffer.h:87
Definition of an RCL Rx MultiBuffer.
Definition: RCL_Buffer.h:86
RCL_BufferState state
Definition: RCL_Buffer.h:88
uint16_t tailIndex
Definition: RCL_Buffer.h:91
Definition: RCL_Buffer.h:45
static void RCL_MultiBuffer_commitBytes(RCL_MultiBuffer *curBuffer, uint32_t numBytes)
Update number of bytes written to RCL_MultiBuffer.
Definition: RCL_Buffer.h:500
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:328
List_Elem __elem__
Definition: RCL_Buffer.h:59
RCL_BufferState state
Definition: RCL_Buffer.h:60
Definition of an RCL Rx Buffer Entry.
Definition: RCL_Buffer.h:73
uint8_t numPad
Definition: RCL_Buffer.h:75
uint8_t data[]
Definition: RCL_Buffer.h:64
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:123
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:133
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:101
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:287
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:214
bool RCL_MultiBuffer_RxEntry_isLast(RCL_MultiBuffer_ListInfo *listInfo)
Function to check a traversed entry was the last one.
Definition: RCL_Buffer.c:264
uint8_t pad0
Definition: RCL_Buffer.h:76
static RCL_Buffer_TxBuffer * RCL_TxBuffer_head(List_List *list)
Function to return the head of a TxBuffer list.
Definition: RCL_Buffer.h:197
static RCL_MultiBuffer * RCL_MultiBuffer_head(List_List *list)
Function to return the head of a MultiBuffer list.
Definition: RCL_Buffer.h:256
RCL_MultiBuffer * nextBuffer
Definition: RCL_Buffer.h:103
uint16_t nextIndex
Definition: RCL_Buffer.h:104
uint16_t headIndex
Definition: RCL_Buffer.h:90
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:212
uint16_t length
Definition: RCL_Buffer.h:89
List_List * multiBuffers
Definition: RCL_Buffer.h:102
Definition: RCL_Buffer.h:44
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:111
RCL_BufferState
Buffer state.
Definition: RCL_Buffer.h:42
size_t RCL_Buffer_readPartialRxBuffer(RCL_Buffer_DataEntry *dataEntry, size_t entrySize)
Read partially received packet into buffer.
Definition: RCL_Buffer.c:283
Definition of an RCL Tx Buffer.
Definition: RCL_Buffer.h:58
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:382
bool RCL_MultiBuffer_RxEntry_isEmpty(List_List *list)
Function to check if the MultiBuffer List is out of entries.
Definition: RCL_Buffer.c:178
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:271
RCL_MultiBuffer * RCL_MultiBuffer_findFirstWritableBuffer(RCL_MultiBuffer *head)
Find the first writable buffer in a list of MultiBuffers.
Definition: RCL_Buffer.c:315
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:182
uint8_t pad0
Definition: RCL_Buffer.h:63