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 / QueueSet / static variants.
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
62 private_member(
63 // vsf_eda_queue_t MUST stay first in the layout: the kernel
64 // walks container_of via the op vtable, which relies on an
65 // offset-0 embedding. `implement()` produces an anonymous
66 // union giving the implementation file transparent access.
67 implement(vsf_eda_queue_t)
68
69 uint16_t head; // write cursor (next enqueue slot)
70 uint16_t tail; // read cursor (next dequeue slot)
71 uint16_t node_num; // ring capacity in slots
72 uint16_t node_size; // bytes per slot
73 bool is_static; // control block is user-owned
74 bool is_storage_static; // item storage is user-owned
75
76 uint8_t * node_buffer; // ring storage (heap or user-supplied)
77 )
78};
79
80/*============================ PROTOTYPES ====================================*/
81
82// Allocate a queue that stores uxQueueLength items of uxItemSize bytes each.
83// Returns NULL on failure (invalid args or heap exhaustion).
84extern QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength,
85 UBaseType_t uxItemSize);
86
87// Zero-heap create. The caller provides BOTH the item storage buffer
88// (uxQueueLength * uxItemSize bytes, any alignment) and the state
89// buffer. Neither is freed by vQueueDelete.
91 UBaseType_t uxItemSize,
92 uint8_t *pucQueueStorage,
93 StaticQueue_t *pxQueueBuffer);
94
95// Free a queue. Any pending senders/receivers are woken with failure.
96extern void vQueueDelete(QueueHandle_t xQueue);
97
98// Copy one item into the queue (tail). If the queue is full and
99// xTicksToWait > 0 the caller is blocked up to that many ticks.
100// Returns pdTRUE on success, pdFALSE on timeout / invalid args.
102 const void *pvItemToQueue,
103 TickType_t xTicksToWait);
104
105// Alias required by FreeRTOS API.
106#define xQueueSendToBack(q, item, ticks) xQueueSend((q), (item), (ticks))
107
108// ISR-context enqueue. pxHigherPriorityTaskWoken may be NULL; when non-NULL
109// it is set to pdFALSE on success / pdTRUE when a waiter was released.
111 const void *pvItemToQueue,
112 BaseType_t *pxHigherPriorityTaskWoken);
113
114// Copy one item out of the queue (head). Blocks up to xTicksToWait ticks
115// if the queue is empty. Returns pdTRUE on success.
117 void *pvBuffer,
118 TickType_t xTicksToWait);
119
120// ISR-context dequeue. Semantics mirror xQueueSendFromISR.
122 void *pvBuffer,
123 BaseType_t *pxHigherPriorityTaskWoken);
124
125// Number of items currently stored in the queue.
127
128// Number of free slots in the queue.
130
131// Discard all pending items. Returns pdPASS.
133
134#ifdef __cplusplus
135}
136#endif
137
138#endif // __VSF_FREERTOS_QUEUE_H__
Definition queue.h:61
Definition vsf_eda.h:999
long BaseType_t
Definition esp_ringbuf.h:50
#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
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:281
UBaseType_t uxQueueSpacesAvailable(QueueHandle_t xQueue)
Definition freertos_queue_port.c:306
BaseType_t xQueueSendFromISR(QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
Definition freertos_queue_port.c:219
UBaseType_t uxQueueMessagesWaiting(QueueHandle_t xQueue)
Definition freertos_queue_port.c:298
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:315
BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait)
Definition freertos_queue_port.c:239
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
uint16_t head
Definition vsf_queue.h:632
Generated from commit: vsfteam/vsf@015f4d1