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) {
106 if (
q._handle ==
nullptr) {
118 if (_handle !=
nullptr) {
128 : _handle(std::exchange(other._handle,
nullptr)) {}
132 if (
this != &other) {
133 if (_handle !=
nullptr) {
136 _handle = std::exchange(other._handle,
nullptr);
145#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
170 template<
typename Rep,
typename Period>
171 void send(
const T& item,
const std::chrono::duration<Rep, Period>&
timeout) {
188 template<
typename Clock,
typename Duration>
219 template<
typename Rep,
typename Period>
238 template<
typename Clock,
typename Duration>
267 template<
typename Rep,
typename Period>
284 template<
typename Clock,
typename Duration>
288 return _try_send(item, 0);
318 template<
typename Rep,
typename Period>
336 template<
typename Clock,
typename Duration>
341 return _try_send_to_front(item, 0);
362 if (_handle ==
nullptr) {
372#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
397 template<
typename Rep,
typename Period>
415 template<
typename Clock,
typename Duration>
442 template<
typename Rep,
typename Period>
458 template<
typename Clock,
typename Duration>
462 return _try_receive(0);
471#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
497 template<
typename Rep,
typename Period>
516 template<
typename Clock,
typename Duration>
544 template<
typename Rep,
typename Period>
561 template<
typename Clock,
typename Duration>
610 if (_handle ==
nullptr) {
611 return {
false,
false};
636 if (_handle ==
nullptr) {
637 return {
false,
false};
664 if (_handle ==
nullptr) {
692 if (_handle ==
nullptr) {
693 return {std::nullopt,
false};
717 if (_handle ==
nullptr) {
737 if (_handle ==
nullptr) {
749 if (_handle ==
nullptr) {
761 if (_handle ==
nullptr) {
773 if (_handle ==
nullptr) {
795 if (_handle ==
nullptr) {
803 : _handle(
nullptr) {}
806 if (_handle ==
nullptr) {
816 if (_handle ==
nullptr) {
826 if (_handle ==
nullptr) {
837 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 & 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.
queue(size_t length, flags< memory::capabilities > mem_caps=memory::capabilities::dram)
Creates a queue with the specified capacity.
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.
static result< queue > make(size_t length, flags< memory::capabilities > mem_caps=memory::capabilities::dram)
Creates a queue with the specified capacity.
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.
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.