22#include <idfxx/chrono>
24#include <idfxx/memory>
29#include <freertos/FreeRTOS.h>
30#include <freertos/idf_additions.h>
31#include <freertos/queue.h>
66 requires std::is_trivially_copyable_v<T>
69#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
85 if (_handle ==
nullptr) {
105 if (
q._handle ==
nullptr) {
117 if (_handle !=
nullptr) {
127 : _handle(std::exchange(other._handle,
nullptr)) {}
131 if (
this != &other) {
132 if (_handle !=
nullptr) {
135 _handle = std::exchange(other._handle,
nullptr);
144#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
169 template<
typename Rep,
typename Period>
170 void send(
const T& item,
const std::chrono::duration<Rep, Period>&
timeout) {
187 template<
typename Clock,
typename Duration>
218 template<
typename Rep,
typename Period>
237 template<
typename Clock,
typename Duration>
266 template<
typename Rep,
typename Period>
283 template<
typename Clock,
typename Duration>
287 return _try_send(item, 0);
317 template<
typename Rep,
typename Period>
335 template<
typename Clock,
typename Duration>
340 return _try_send_to_front(item, 0);
361 if (_handle ==
nullptr) {
371#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
396 template<
typename Rep,
typename Period>
414 template<
typename Clock,
typename Duration>
441 template<
typename Rep,
typename Period>
457 template<
typename Clock,
typename Duration>
461 return _try_receive(0);
470#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
496 template<
typename Rep,
typename Period>
515 template<
typename Clock,
typename Duration>
543 template<
typename Rep,
typename Period>
560 template<
typename Clock,
typename Duration>
609 if (_handle ==
nullptr) {
610 return {
false,
false};
635 if (_handle ==
nullptr) {
636 return {
false,
false};
663 if (_handle ==
nullptr) {
691 if (_handle ==
nullptr) {
692 return {std::nullopt,
false};
716 if (_handle ==
nullptr) {
736 if (_handle ==
nullptr) {
748 if (_handle ==
nullptr) {
760 if (_handle ==
nullptr) {
772 if (_handle ==
nullptr) {
794 if (_handle ==
nullptr) {
802 : _handle(
nullptr) {}
805 if (_handle ==
nullptr) {
815 if (_handle ==
nullptr) {
825 if (_handle ==
nullptr) {
836 if (_handle ==
nullptr) {
Type-safe inter-task message queue.
void send_to_front(const T &item, const std::chrono::duration< Rep, Period > &timeout)
Sends an item to the front of the queue with a timeout.
T peek_until(const std::chrono::time_point< Clock, Duration > &deadline)
Peeks at the front item in the queue without removing it, with a deadline.
size_t size() const noexcept
Returns the number of items currently in the queue.
void send_to_front_until(const T &item, const std::chrono::time_point< Clock, Duration > &deadline)
Sends an item to the front of the queue with a deadline.
queue(size_t length, flags< memory_caps > mem_caps=memory_caps::dram)
Creates a queue with the specified capacity.
queue & operator=(const queue &)=delete
bool empty() const noexcept
Checks if the queue is empty.
T peek(const std::chrono::duration< Rep, Period > &timeout)
Peeks at the front item in the queue without removing it, with a timeout.
bool full() const noexcept
Checks if the queue is full.
result< void > try_send_to_front_until(const T &item, const std::chrono::time_point< Clock, Duration > &deadline)
Sends an item to the front of the queue with a deadline.
isr_send_result IRAM_ATTR send_to_front_from_isr(const T &item) noexcept
Sends an item to the front of the queue from ISR context.
result< T > try_peek_until(const std::chrono::time_point< Clock, Duration > &deadline)
Peeks at the front item in the queue without removing it, with a deadline.
T receive()
Receives an item from the queue, blocking indefinitely.
void send_to_front(const T &item)
Sends an item to the front of the queue, blocking indefinitely.
void reset() noexcept
Removes all items from the queue.
void send(const T &item)
Sends an item to the back of the queue, blocking indefinitely.
~queue()
Destroys the queue and releases all resources.
queue(const queue &)=delete
result< void > try_send(const T &item)
Sends an item to the back of the queue, blocking indefinitely.
size_t available() const noexcept
Returns the number of free spaces in the queue.
result< void > try_send_to_front(const T &item)
Sends an item to the front of the queue, blocking indefinitely.
queue(queue &&other) noexcept
Move constructor.
result< T > try_peek(const std::chrono::duration< Rep, Period > &timeout)
Peeks at the front item in the queue without removing it, with a timeout.
std::optional< T > IRAM_ATTR peek_from_isr() const noexcept
Peeks at the front item in the queue from ISR context without removing it.
T receive_until(const std::chrono::time_point< Clock, Duration > &deadline)
Receives an item from the queue with a deadline.
QueueHandle_t idf_handle() const noexcept
Returns the underlying FreeRTOS queue handle.
queue & operator=(queue &&other) noexcept
Move assignment.
isr_receive_result IRAM_ATTR receive_from_isr() noexcept
Receives an item from the queue in ISR context.
result< void > try_send(const T &item, const std::chrono::duration< Rep, Period > &timeout)
Sends an item to the back of the queue with a timeout.
result< void > try_send_to_front(const T &item, const std::chrono::duration< Rep, Period > &timeout)
Sends an item to the front of the queue with a timeout.
void send_until(const T &item, const std::chrono::time_point< Clock, Duration > &deadline)
Sends an item to the back of the queue with a deadline.
result< T > try_receive()
Receives an item from the queue, blocking indefinitely.
T peek()
Peeks at the front item in the queue without removing it, blocking indefinitely.
result< T > try_receive(const std::chrono::duration< Rep, Period > &timeout)
Receives an item from the queue with a timeout.
bool IRAM_ATTR overwrite_from_isr(const T &item) noexcept
Overwrites the last item in the queue from ISR context.
isr_send_result IRAM_ATTR send_from_isr(const T &item) noexcept
Sends an item to the back of the queue from ISR context.
result< T > try_peek()
Peeks at the front item in the queue without removing it, blocking indefinitely.
result< void > try_send_until(const T &item, const std::chrono::time_point< Clock, Duration > &deadline)
Sends an item to the back of the queue with a deadline.
T receive(const std::chrono::duration< Rep, Period > &timeout)
Receives an item from the queue with a timeout.
result< T > try_receive_until(const std::chrono::time_point< Clock, Duration > &deadline)
Receives an item from the queue with a deadline.
void send(const T &item, const std::chrono::duration< Rep, Period > &timeout)
Sends an item to the back of the queue with a timeout.
void overwrite(const T &item) noexcept
Overwrites the last item in the queue, or sends if the queue is not full.
static result< queue > make(size_t length, flags< memory_caps > mem_caps=memory_caps::dram)
Creates a queue with the specified capacity.
constexpr TickType_t ticks(const std::chrono::duration< Rep, Period > &d)
Converts a std::chrono duration to TickType_t ticks.
@ dram
Internal DRAM (8-bit accessible)
constexpr std::unexpected< std::error_code > error(E e) noexcept
Creates an unexpected error from an error code enum.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
@ invalid_state
Invalid state.
@ timeout
Operation timed out.
@ invalid_arg
Invalid argument.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
constexpr auto to_underlying(flags< E > f) noexcept
Returns the underlying integral value of a flags object.
Result of an ISR receive operation.
std::optional< T > item
The received item, or std::nullopt if the queue was empty.
bool yield
true if a context switch should be requested.
Result of an ISR send operation.
bool success
true if the item was sent successfully.
bool yield
true if a context switch should be requested.