Skip to content

Commit 292f5c0

Browse files
committed
peek method
1 parent 76710cf commit 292f5c0

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

Diff for: cores/esp32/cbuf.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,23 @@ bool cbuf::full() const
160160

161161
int cbuf::peek()
162162
{
163-
return -1;
163+
CBUF_MUTEX_LOCK();
164+
Ringbuffer_t *pxRingbuffer = (Ringbuffer_t *)_buf;
165+
size_t bytes_available = available();
166+
if(!bytes_available){
167+
CBUF_MUTEX_UNLOCK();
168+
return 0;
169+
}
170+
171+
int c = *(pxRingbuffer->pucRead);
172+
CBUF_MUTEX_UNLOCK();
173+
174+
return c;
164175
}
165176

166177
size_t cbuf::peek(char *dst, size_t size)
167178
{
179+
/* TO DO */
168180
return 0;
169181
}
170182

Diff for: cores/esp32/cbuf.h

+35
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,41 @@
2828
#include "freertos/ringbuf.h"
2929
#include "freertos/semphr.h"
3030

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+
3166
class cbuf
3267
{
3368
public:

0 commit comments

Comments
 (0)