VSF Documented
queue.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// Clean-room FreeRTOS queue.h shim for VSF.
19//
20// Exposes the FreeRTOS queue primitive subset required by ESP-IDF v5.x and
21// typical middleware / networking stacks. The backing store is a plain
22// ring buffer with a vsf_eda_queue_t attached for blocking semantics.
23//
24// Subset covered (MVP):
25// xQueueCreate / vQueueDelete
26// xQueueSend / xQueueSendToBack (aliases)
27// xQueueSendFromISR
28// xQueueReceive
29// xQueueReceiveFromISR
30// uxQueueMessagesWaiting
31// uxQueueSpacesAvailable
32// xQueueReset
33//
34// Not covered yet (add on demand):
35// xQueueSendToFront / xQueuePeek.
36
37#ifndef __VSF_FREERTOS_QUEUE_H__
38#define __VSF_FREERTOS_QUEUE_H__
39
40#include "FreeRTOS.h"
41
42#if defined(__VSF_FREERTOS_QUEUE_CLASS_IMPLEMENT)
43# undef __VSF_FREERTOS_QUEUE_CLASS_IMPLEMENT
44# define __VSF_CLASS_IMPLEMENT__
45#endif
46
47#include "utilities/ooc_class.h"
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/*============================ TYPES =========================================*/
54
55// Forward-declared vsf_class. QueueHandle_t is a StaticQueue_t *; the
56// inline ring cursors, state flags and embedded vsf_eda_queue_t are all
57// private to the implementation (see port/freertos_queue_port.c).
60
61#if VSF_FREERTOS_CFG_USE_QUEUESET == ENABLED
62#ifndef __VSF_FREERTOS_QUEUESET_TYPES_DEFINED__
63# define __VSF_FREERTOS_QUEUESET_TYPES_DEFINED__
64typedef void * QueueSetHandle_t;
66#endif
67#endif
68
70 private_member(
71 // vsf_eda_queue_t MUST stay first in the layout: the kernel
72 // walks container_of via the op vtable, which relies on an
73 // offset-0 embedding. `implement()` produces an anonymous
74 // union giving the implementation file transparent access.
75 implement(vsf_eda_queue_t)
76
77 uint16_t head; // write cursor (next enqueue slot)
78 uint16_t tail; // read cursor (next dequeue slot)
79 uint16_t node_num; // ring capacity in slots
80 uint16_t node_size; // bytes per slot
81 bool is_static; // control block is user-owned
82 bool is_storage_static; // item storage is user-owned
83
84 uint8_t * node_buffer; // ring storage (heap or user-supplied)
85
86#if VSF_FREERTOS_CFG_USE_QUEUESET == ENABLED
87 QueueSetHandle_t pxQueueSetContainer; // NULL if not in a set
88#endif
89 )
90};
91
92/*============================ PROTOTYPES ====================================*/
93
94// Allocate a queue that stores uxQueueLength items of uxItemSize bytes each.
95// Returns NULL on failure (invalid args or heap exhaustion).
96extern QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength,
97 UBaseType_t uxItemSize);
98
99// Zero-heap create. The caller provides BOTH the item storage buffer
100// (uxQueueLength * uxItemSize bytes, any alignment) and the state
101// buffer. Neither is freed by vQueueDelete.
102extern QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength,
103 UBaseType_t uxItemSize,
104 uint8_t *pucQueueStorage,
105 StaticQueue_t *pxQueueBuffer);
106
107// Free a queue. Any pending senders/receivers are woken with failure.
108extern void vQueueDelete(QueueHandle_t xQueue);
109
110// Copy one item into the queue (tail). If the queue is full and
111// xTicksToWait > 0 the caller is blocked up to that many ticks.
112// Returns pdTRUE on success, pdFALSE on timeout / invalid args.
114 const void *pvItemToQueue,
115 TickType_t xTicksToWait);
116
117// Alias required by FreeRTOS API.
118#define xQueueSendToBack(q, item, ticks) xQueueSend((q), (item), (ticks))
119
120// ISR-context enqueue. pxHigherPriorityTaskWoken may be NULL; when non-NULL
121// it is set to pdFALSE on success / pdTRUE when a waiter was released.
123 const void *pvItemToQueue,
124 BaseType_t *pxHigherPriorityTaskWoken);
125
126// Copy one item out of the queue (head). Blocks up to xTicksToWait ticks
127// if the queue is empty. Returns pdTRUE on success.
129 void *pvBuffer,
130 TickType_t xTicksToWait);
131
132// ISR-context dequeue. Semantics mirror xQueueSendFromISR.
134 void *pvBuffer,
135 BaseType_t *pxHigherPriorityTaskWoken);
136
137// Number of items currently stored in the queue.
139
140// Number of free slots in the queue.
142
143// Discard all pending items. Returns pdPASS.
145
146#if VSF_FREERTOS_CFG_USE_QUEUESET == ENABLED
147// ── QueueSet (queue of member pointers) ─────────────────────────────────
148
149extern QueueSetHandle_t xQueueCreateSet(const UBaseType_t uxEventQueueLength);
150
151extern BaseType_t xQueueAddToSet(QueueSetMemberHandle_t xQueueOrSemaphore,
152 QueueSetHandle_t xQueueSet);
153
155 QueueSetHandle_t xQueueSet);
156
158 TickType_t xTicksToWait);
159
161 QueueSetHandle_t xQueueSet);
162#endif
163
164#ifdef __cplusplus
165}
166#endif
167
168#endif // __VSF_FREERTOS_QUEUE_H__
Definition queue.h:69
Definition vsf_eda.h:999
struct esp_netif_obj * head
Definition esp_netif_port.c:117
void * QueueSetHandle_t
Definition esp_ringbuf.h:79
long BaseType_t
Definition esp_ringbuf.h:57
void * QueueSetMemberHandle_t
Definition esp_ringbuf.h:80
#define vsf_dcl_class
Definition ooc_class.h:50
#define vsf_class(__name)
Definition ooc_class.h:52
QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize)
Definition freertos_queue_port.c:103
QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength, UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxQueueBuffer)
Definition freertos_queue_port.c:132
QueueSetMemberHandle_t xQueueSelectFromSetFromISR(QueueSetHandle_t xQueueSet)
Definition freertos_queue_port.c:396
void * QueueSetHandle_t
Definition queue.h:64
void vQueueDelete(QueueHandle_t xQueue)
Definition freertos_queue_port.c:157
BaseType_t xQueueReceiveFromISR(QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxHigherPriorityTaskWoken)
Definition freertos_queue_port.c:300
UBaseType_t uxQueueSpacesAvailable(QueueHandle_t xQueue)
Definition freertos_queue_port.c:325
BaseType_t xQueueSendFromISR(QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
Definition freertos_queue_port.c:233
void * QueueSetMemberHandle_t
Definition queue.h:65
BaseType_t xQueueRemoveFromSet(QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet)
Definition freertos_queue_port.c:374
BaseType_t xQueueAddToSet(QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet)
Definition freertos_queue_port.c:357
QueueSetHandle_t xQueueCreateSet(const UBaseType_t uxEventQueueLength)
Definition freertos_queue_port.c:352
UBaseType_t uxQueueMessagesWaiting(QueueHandle_t xQueue)
Definition freertos_queue_port.c:317
BaseType_t xQueueSend(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
Definition freertos_queue_port.c:173
BaseType_t xQueueReset(QueueHandle_t xQueue)
Definition freertos_queue_port.c:334
QueueSetMemberHandle_t xQueueSelectFromSet(QueueSetHandle_t xQueueSet, TickType_t xTicksToWait)
Definition freertos_queue_port.c:388
BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait)
Definition freertos_queue_port.c:259
uint32_t TickType_t
Definition rtos_al.h:59
uint32_t UBaseType_t
Definition rtos_al.h:60
unsigned short uint16_t
Definition stdint.h:7
unsigned char uint8_t
Definition stdint.h:5
uint16_t tail
Definition vsf_queue.h:632
Generated from commit: vsfteam/vsf@c3767bf