|
28 | 28 | #include "freertos/ringbuf.h"
|
29 | 29 | #include "freertos/semphr.h"
|
30 | 30 |
|
| 31 | + |
| 32 | +typedef struct RingbufferDefinition Ringbuffer_t; |
| 33 | +typedef BaseType_t (*CheckItemFitsFunction_t)(Ringbuffer_t *pxRingbuffer, size_t xItemSize); |
| 34 | +typedef void (*CopyItemFunction_t)(Ringbuffer_t *pxRingbuffer, const uint8_t *pcItem, size_t xItemSize); |
| 35 | +typedef BaseType_t (*CheckItemAvailFunction_t) (Ringbuffer_t *pxRingbuffer); |
| 36 | +typedef void *(*GetItemFunction_t)(Ringbuffer_t *pxRingbuffer, BaseType_t *pxIsSplit, size_t xMaxSize, size_t *pxItemSize); |
| 37 | +typedef void (*ReturnItemFunction_t)(Ringbuffer_t *pxRingbuffer, uint8_t *pvItem); |
| 38 | +typedef size_t (*GetCurMaxSizeFunction_t)(Ringbuffer_t *pxRingbuffer); |
| 39 | + |
| 40 | +typedef struct RingbufferDefinition { |
| 41 | + size_t xSize; //Size of the data storage |
| 42 | + size_t xMaxItemSize; //Maximum item size |
| 43 | + UBaseType_t uxRingbufferFlags; //Flags to indicate the type and status of ring buffer |
| 44 | + |
| 45 | + CheckItemFitsFunction_t xCheckItemFits; //Function to check if item can currently fit in ring buffer |
| 46 | + CopyItemFunction_t vCopyItem; //Function to copy item to ring buffer |
| 47 | + GetItemFunction_t pvGetItem; //Function to get item from ring buffer |
| 48 | + ReturnItemFunction_t vReturnItem; //Function to return item to ring buffer |
| 49 | + GetCurMaxSizeFunction_t xGetCurMaxSize; //Function to get current free size |
| 50 | + |
| 51 | + uint8_t *pucAcquire; //Acquire Pointer. Points to where the next item should be acquired. |
| 52 | + uint8_t *pucWrite; //Write Pointer. Points to where the next item should be written |
| 53 | + uint8_t *pucRead; //Read Pointer. Points to where the next item should be read from |
| 54 | + uint8_t *pucFree; //Free Pointer. Points to the last item that has yet to be returned to the ring buffer |
| 55 | + uint8_t *pucHead; //Pointer to the start of the ring buffer storage area |
| 56 | + uint8_t *pucTail; //Pointer to the end of the ring buffer storage area |
| 57 | + |
| 58 | + BaseType_t xItemsWaiting; //Number of items/bytes(for byte buffers) currently in ring buffer that have not yet been read |
| 59 | + List_t xTasksWaitingToSend; //List of tasks that are blocked waiting to send/acquire onto this ring buffer. Stored in priority order. |
| 60 | + List_t xTasksWaitingToReceive; //List of tasks that are blocked waiting to receive from this ring buffer. Stored in priority order. |
| 61 | + QueueSetHandle_t xQueueSet; //Ring buffer's read queue set handle. |
| 62 | + |
| 63 | + portMUX_TYPE mux; //Spinlock required for SMP |
| 64 | +} Ringbuffer_t; |
| 65 | + |
31 | 66 | class cbuf
|
32 | 67 | {
|
33 | 68 | public:
|
|
0 commit comments