VSF Documented
esp_ringbuf.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "freertos/ringbuf.h".
20 *
21 * Authored from the ESP-IDF v5.x public API reference only. No ESP-IDF /
22 * FreeRTOS source code or data is copied.
23 *
24 * This initial drop supports RINGBUF_TYPE_BYTEBUF end-to-end. The split /
25 * no-split item-oriented modes are accepted by xRingbufferCreate() but
26 * currently fall back to byte-buffer behavior; their item framing contract
27 * will be honored in a follow-up as tests are added.
28 *
29 * Because VSF's ESP-IDF port does not include a full FreeRTOS layer, this
30 * header exposes a minimal subset of the FreeRTOS value types that the
31 * ring buffer API signature references. The guards allow code that does
32 * include real FreeRTOS headers to compile side-by-side.
33 */
34
35#ifndef __VSF_ESPIDF_ESP_RINGBUF_H__
36#define __VSF_ESPIDF_ESP_RINGBUF_H__
37
38#include <stdint.h>
39#include <stdbool.h>
40#include <stddef.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/*============================ TYPES =========================================*/
47
48#ifndef __VSF_ESPIDF_FREERTOS_TYPES_DEFINED__
49#define __VSF_ESPIDF_FREERTOS_TYPES_DEFINED__
50typedef long BaseType_t;
52# ifndef pdTRUE
53# define pdTRUE ((BaseType_t)1)
54# endif
55# ifndef pdFALSE
56# define pdFALSE ((BaseType_t)0)
57# endif
58# ifndef pdPASS
59# define pdPASS pdTRUE
60# endif
61# ifndef pdFAIL
62# define pdFAIL pdFALSE
63# endif
64# ifndef portMAX_DELAY
65# define portMAX_DELAY ((TickType_t)0xFFFFFFFFu)
66# endif
67#endif // __VSF_ESPIDF_FREERTOS_TYPES_DEFINED__
68
69typedef enum {
74
77
78/*============================ PROTOTYPES ====================================*/
79
80/* Allocate a ring buffer of the requested byte capacity. Returns NULL on
81 * allocation failure. The returned handle must be released via
82 * vRingbufferDelete(). */
84
85/* Release a previously created ring buffer. Passing NULL is a no-op. */
87
88/* Enqueue `data_size` bytes. Returns pdTRUE on success, pdFALSE if there
89 * is not enough free space. The VSF port's timeout semantics are poll-only
90 * on the host (no task blocking); any non-zero ticks value is treated as
91 * a single in-place retry. */
93 size_t data_size, TickType_t ticks_to_wait);
94
95/* Pull up to `max_size` bytes from the buffer, copying internally so the
96 * caller does not need to invoke vRingbufferReturnItem(). Returns NULL if
97 * nothing is available. On success sets *item_size to the number of bytes
98 * copied. The returned pointer must be released via vPortFree()-compatible
99 * means; in this port it is allocated from the VSF heap and must be freed
100 * with vRingbufferReturnItem(). */
101void * xRingbufferReceive(RingbufHandle_t handle, size_t *item_size,
102 TickType_t ticks_to_wait);
103
104/* Same as xRingbufferReceive() but caps the number of bytes returned. */
106 TickType_t ticks_to_wait, size_t wanted_size);
107
108/* Release a buffer previously returned by xRingbufferReceive(). */
109void vRingbufferReturnItem(RingbufHandle_t handle, void *item);
110
111/* Bytes currently free for writing. */
113
114/* Bytes currently queued for reading. */
116
117/* Total buffer capacity in bytes as passed to xRingbufferCreate(). */
119
120#ifdef __cplusplus
121}
122#endif
123
124#endif // __VSF_ESPIDF_ESP_RINGBUF_H__
struct __vsf_espidf_ringbuf * RingbufHandle_t
Definition esp_ringbuf.h:76
size_t xRingbufferGetMaxItemSize(RingbufHandle_t handle)
Definition esp_ringbuf_port.c:240
void vRingbufferReturnItem(RingbufHandle_t handle, void *item)
Definition esp_ringbuf_port.c:199
void vRingbufferDelete(RingbufHandle_t handle)
Definition esp_ringbuf_port.c:96
long BaseType_t
Definition esp_ringbuf.h:50
void * xRingbufferReceiveUpTo(RingbufHandle_t handle, size_t *item_size, TickType_t ticks_to_wait, size_t wanted_size)
Definition esp_ringbuf_port.c:192
BaseType_t xRingbufferSend(RingbufHandle_t handle, const void *data, size_t data_size, TickType_t ticks_to_wait)
Definition esp_ringbuf_port.c:107
RingbufferType_t
Definition esp_ringbuf.h:69
@ RINGBUF_TYPE_NOSPLIT
Definition esp_ringbuf.h:70
@ RINGBUF_TYPE_ALLOWSPLIT
Definition esp_ringbuf.h:71
@ RINGBUF_TYPE_BYTEBUF
Definition esp_ringbuf.h:72
uint32_t TickType_t
Definition esp_ringbuf.h:51
RingbufHandle_t xRingbufferCreate(size_t buffer_size, RingbufferType_t type)
Definition esp_ringbuf_port.c:76
size_t xRingbufferGetCurFilledSize(RingbufHandle_t handle)
Definition esp_ringbuf_port.c:229
void * xRingbufferReceive(RingbufHandle_t handle, size_t *item_size, TickType_t ticks_to_wait)
Definition esp_ringbuf_port.c:182
size_t xRingbufferGetCurFreeSize(RingbufHandle_t handle)
Definition esp_ringbuf_port.c:218
struct ieee80211_ext_chansw_ie data
Definition ieee80211.h:80
uint32_t TickType_t
Definition rtos_al.h:59
unsigned uint32_t
Definition stdint.h:9
Definition esp_ringbuf_port.c:55
vk_av_control_type_t type
Definition vsf_audio.h:170
uintptr_t uint_fast32_t item_size
Definition vsf_pool.h:477
Generated from commit: vsfteam/vsf@015f4d1