Struct esp_idf_hal::task::queue::Queue

source ·
pub struct Queue<T> { /* private fields */ }
Expand description

Thin wrapper on top of the FreeRTOS queue.

This may be preferable over a Rust channel in cases where an ISR needs to send or receive data as it is safe to use in ISR contexts.

Implementations§

source§

impl<T> Queue<T>
where T: Copy,

source

pub fn new(size: usize) -> Self

Allocate a new queue on the heap.

source

pub unsafe fn new_borrowed(ptr: QueueHandle_t) -> Self

Create a new queue which is not deleted on Drop, but owned by somebody else.

§Safety

Care must be taken that the queue is valid for the constructed lifetime.

source

#[link_section = "iram1.queue_as_raw"]
pub fn as_raw(&self) -> QueueHandle_t

Retrieves the underlying FreeRTOS handle.

source

#[link_section = "iram1.queue_send_back"]
pub fn send_back(&self, item: T, timeout: TickType_t) -> Result<bool, EspError>

Copy item to back of queue, blocking for timeout ticks if full.

§ISR safety

This function is safe to call in ISR contexts.

§Parameters
  • item the item to push onto the back of the queue
  • timeout specifies how long to block. Ignored in ISR context.
§Returns

Will return an error if queue is full. If this function is executed in an ISR context, it will return true if a higher priority task was awoken. In non-ISR contexts, the function will always return false. In this case the interrupt should call crate::task::do_yield.

source

#[link_section = "iram1.queue_send_front"]
pub fn send_front(&self, item: T, timeout: TickType_t) -> Result<bool, EspError>

Copy item to front of queue, blocking for timeout ticks if full. This can be used for hight priority messages which should be processed sooner.

§ISR safety

This function is safe to call in ISR contexts.

§Parameters
  • item the item to push to front of the queue
  • timeout specifies how long to block. Ignored in ISR context.
§Returns

Will return an error if queue is full. If this function is executed in an ISR context, it will return true if a higher priority task was awoken. In non-ISR contexts, the function will always return false. In this case the interrupt should call crate::task::do_yield.

source

#[link_section = "iram1.queue_recv_front"]
pub fn recv_front(&self, timeout: TickType_t) -> Option<(T, bool)>

Receive a message from the queue and remove it.

§ISR safety

This function is safe to use in ISR contexts

§Parameters
  • timeout specifies how long to block. Ignored in ISR contexts.
§Returns
  • None if no message could be received in time
  • Some((message, higher_priority_task_awoken)) otherwise

The boolean is used for ISRs and indicates if a higher priority task was awoken. In this case the interrupt should call crate::task::do_yield. In non-ISR contexts, the function will always return false.

source

#[link_section = "iram1.queue_peek_front"]
pub fn peek_front(&self, timeout: TickType_t) -> Option<T>

Copy the first message from the queue without removing it.

§ISR safety

This function is safe to use in ISR contexts

§Parameters
  • timeout specifies how long to block. Ignored in ISR contexts.
§Returns
  • None if no message could be received in time
  • Some(message) otherwise

This function does not return a boolean to indicate if a higher priority task was awoken since we don’t free up space in the queue and thus cannot unblock anyone.

Trait Implementations§

source§

impl<T> Drop for Queue<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T> Send for Queue<T>
where T: Send + Sync,

source§

impl<T> Sync for Queue<T>
where T: Send + Sync,

Auto Trait Implementations§

§

impl<T> Freeze for Queue<T>

§

impl<T> RefUnwindSafe for Queue<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Queue<T>
where T: Unpin,

§

impl<T> UnwindSafe for Queue<T>
where T: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.