2#include "TinyRobotics/utils/AllocatorPSRAM.h"
3#include "TinyRobotics/utils/Config.h"
6#include <freertos/queue.h>
8#include "freertos/FreeRTOS.h"
16namespace tinyrobotics {
19
20
21
22
23
24
25
26
30 QueueRTOS(
int size, TickType_t writeMaxWait = portMAX_DELAY,
31 TickType_t readMaxWait = portMAX_DELAY) {
33 read_max_wait = readMaxWait;
34 write_max_wait = writeMaxWait;
44 void setReadMaxWait(TickType_t ticks) { read_max_wait = ticks; }
46 void setWriteMaxWait(TickType_t ticks) { write_max_wait = ticks; }
52 if (size != queue_size) {
60 bool enqueue(T& data) {
62 if (xQueue ==
nullptr)
return false;
63 return xQueueSend(xQueue, (
void*)&data, (TickType_t)write_max_wait);
68 if (xQueue ==
nullptr)
return false;
69 return xQueuePeek(xQueue, &data, (TickType_t)read_max_wait);
72 bool dequeue(T& data) {
74 if (xQueue ==
nullptr)
return false;
75 return xQueueReceive(xQueue, &data, (TickType_t)read_max_wait);
78 size_t size() {
return queue_size; }
82 if (xQueue ==
nullptr)
return false;
88 if (xQueue !=
nullptr) vQueueDelete(xQueue);
89 if (p_data !=
nullptr) allocator.deallocate((T*)p_data, allocated_size);
92 bool isEmpty() {
return size() == 0; }
95 QueueHandle_t xQueue =
nullptr;
99 StaticQueue_t queue_buffer;
100 TAllocator allocator;
101 size_t allocated_size = 0;
102 uint8_t* p_data =
nullptr;
105 if (queue_size > 0) {
106#if configSUPPORT_STATIC_ALLOCATION
107 allocated_size = (queue_size + 1) *
sizeof(T);
108 p_data = (uint8_t*)allocator.allocate(allocated_size);
109 if (p_data ==
nullptr)
return false;
110 xQueue = xQueueCreateStatic(queue_size,
sizeof(T), p_data, &queue_buffer);
112 xQueue = xQueueCreate(queue_size,
sizeof(T));
114 if (xQueue ==
nullptr)
return false;
Custom allocator that uses ESP32's PSRAM for memory allocation.
Definition: AllocatorPSRAM.h:21
FIFO Queue whch is based on the FreeRTOS queue API. The default allocator will allocate the memory fr...
Definition: QueueRTOS.h:28
bool resize(int size)
(Re-)defines the size
Definition: QueueRTOS.h:49