arduino-audio-tools
Loading...
Searching...
No Matches
QueueZephyr.h
Go to the documentation of this file.
1#pragma once
2
4#include "AudioToolsConfig.h"
5
6#include <limits.h>
7#include <zephyr/kernel.h>
8
9#ifndef AUDIO_TOOLS_RTOS_TICK_TYPES_DEFINED
10#define AUDIO_TOOLS_RTOS_TICK_TYPES_DEFINED
11using TickType_t = uint32_t;
12using BaseType_t = int;
13#ifndef portMAX_DELAY
14#define portMAX_DELAY UINT32_MAX
15#endif
16#ifndef pdMS_TO_TICKS
17#define pdMS_TO_TICKS(ms) (ms)
18#endif
19#ifndef pdTRUE
20#define pdTRUE 1
21#endif
22#ifndef pdFALSE
23#define pdFALSE 0
24#endif
25#endif
26
27namespace audio_tools {
28
32
41template <class T>
43 public:
53
55
57
59
61 bool resize(size_t size) {
62 bool result = true;
63 if (size != queue_size) {
64 end();
66 result = setup();
67 }
68 return result;
69 }
70
71 bool enqueue(T &data) {
72 if (!is_active) return false;
74 }
75
76 bool peek(T &data) {
77 if (!is_active) return false;
78 return k_msgq_peek(&msgq, &data) == 0;
79 }
80
81 bool dequeue(T &data) {
82 if (!is_active) return false;
84 }
85
86 size_t size() { return queue_size; }
87
88 bool clear() {
89 if (!is_active) return false;
91 return true;
92 }
93
94 bool empty() {
95 return k_msgq_num_used_get(&msgq) == 0;
96 }
97
98 protected:
99 struct k_msgq msgq;
103 int queue_size = 0;
104 uint8_t *p_data = nullptr;
105 bool is_active = false;
106
107 bool setup() {
108 if (queue_size <= 0) {
109 is_active = false;
110 return true;
111 }
113 if (p_data == nullptr) return false;
114
115 k_msgq_init(&msgq, p_data, sizeof(T), queue_size);
116 is_active = true;
117 return true;
118 }
119
120 void end() {
121 if (p_data != nullptr) {
123 p_data = nullptr;
124 }
125 is_active = false;
126 }
127};
128
130template <class T>
132
133} // namespace audio_tools
#define portMAX_DELAY
Definition QueueZephyr.h:14
int BaseType_t
Definition QueueZephyr.h:12
uint32_t TickType_t
Definition QueueZephyr.h:11
Memory allocateator which uses malloc.
Definition Allocator.h:24
virtual void free(void *memory)
frees memory
Definition Allocator.h:83
virtual void * allocate(size_t size)
Allocates memory.
Definition Allocator.h:71
FIFO Queue whch is based on the FreeRTOS queue API. The default allocator will allocate the memory fr...
Definition QueueRTOS.h:30
FIFO Queue implementation based on Zephyr message queues.
Definition QueueZephyr.h:42
size_t size()
Definition QueueZephyr.h:86
TickType_t write_max_wait
Definition QueueZephyr.h:100
~QueueZephyr()
Definition QueueZephyr.h:54
QueueZephyr(int size, TickType_t writeMaxWait=UINT32_MAX, TickType_t readMaxWait=UINT32_MAX, Allocator &allocator=DefaultAllocator)
Definition QueueZephyr.h:44
Allocator * p_allocator
Definition QueueZephyr.h:102
bool empty()
Definition QueueZephyr.h:94
bool is_active
Definition QueueZephyr.h:105
struct k_msgq msgq
Definition QueueZephyr.h:99
void setWriteMaxWait(TickType_t ticks)
Definition QueueZephyr.h:58
bool peek(T &data)
Definition QueueZephyr.h:76
bool dequeue(T &data)
Definition QueueZephyr.h:81
uint8_t * p_data
Definition QueueZephyr.h:104
bool clear()
Definition QueueZephyr.h:88
void setReadMaxWait(TickType_t ticks)
Definition QueueZephyr.h:56
void end()
Definition QueueZephyr.h:120
int queue_size
Definition QueueZephyr.h:103
bool enqueue(T &data)
Definition QueueZephyr.h:71
TickType_t read_max_wait
Definition QueueZephyr.h:101
bool resize(size_t size)
(Re-)defines the size
Definition QueueZephyr.h:61
bool setup()
Definition QueueZephyr.h:107
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
static TAllocatorExt DefaultAllocator
Definition Allocator.h:207
k_timeout_t rtosTimeoutFromTicks(TickType_t ticks)
Definition QueueZephyr.h:29
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition AudioTypes.h:508