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,
impl<T> Queue<T>where
T: Copy,
sourcepub unsafe fn new_borrowed(ptr: *mut QueueDefinition) -> Queue<T>
pub unsafe fn new_borrowed(ptr: *mut QueueDefinition) -> Queue<T>
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.
sourcepub fn as_raw(&self) -> *mut QueueDefinition
pub fn as_raw(&self) -> *mut QueueDefinition
Retrieves the underlying FreeRTOS handle.
sourcepub fn send_back(&self, item: T, timeout: u32) -> Result<bool, EspError>
pub fn send_back(&self, item: T, timeout: u32) -> 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 queuetimeout
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
.
sourcepub fn send_front(&self, item: T, timeout: u32) -> Result<bool, EspError>
pub fn send_front(&self, item: T, timeout: u32) -> 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 queuetimeout
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
.
sourcepub fn recv_front(&self, timeout: u32) -> Option<(T, bool)>
pub fn recv_front(&self, timeout: u32) -> 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 timeSome((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
.
sourcepub fn peek_front(&self, timeout: u32) -> Option<T>
pub fn peek_front(&self, timeout: u32) -> 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 timeSome(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.