embassy-executor

Crates

git

Versions

cortex-m

Flavors

embassy_executor

Struct InterruptExecutor

Source
pub struct InterruptExecutor { /* private fields */ }
Expand description

Interrupt mode executor.

This executor runs tasks in interrupt mode. The interrupt handler is set up to poll tasks, and when a task is woken the interrupt is pended from software.

This allows running async tasks at a priority higher than thread mode. One use case is to leave thread mode free for non-async tasks. Another use case is to run multiple executors: one in thread mode for low priority tasks and another in interrupt mode for higher priority tasks. Higher priority tasks will preempt lower priority ones.

It is even possible to run multiple interrupt mode executors at different priorities, by assigning different priorities to the interrupts. For an example on how to do this, See the ‘multiprio’ example for ‘embassy-nrf’.

To use it, you have to pick an interrupt that won’t be used by the hardware. Some chips reserve some interrupts for this purpose, sometimes named “software interrupts” (SWI). If this is not the case, you may use an interrupt from any unused peripheral.

It is somewhat more complex to use, it’s recommended to use the thread-mode [Executor] instead, if it works for your use case.

Implementations§

Source§

impl InterruptExecutor

Source

pub const fn new() -> Self

Create a new, not started InterruptExecutor.

Source

pub unsafe fn on_interrupt(&'static self)

Executor interrupt callback.

§Safety
  • You MUST call this from the interrupt handler, and from nowhere else.
  • You must not call this before calling start().
Source

pub fn start(&'static self, irq: impl InterruptNumber) -> SendSpawner

Start the executor.

This initializes the executor, enables the interrupt, and returns. The executor keeps running in the background through the interrupt.

This returns a [SendSpawner] you can use to spawn tasks on it. A [SendSpawner] is returned instead of a Spawner because the executor effectively runs in a different “thread” (the interrupt), so spawning tasks on it is effectively sending them.

To obtain a Spawner for this executor, use Spawner::for_current_executor() from a task running in it.

§Interrupt requirements

You must write the interrupt handler yourself, and make it call on_interrupt().

This method already enables (unmasks) the interrupt, you must NOT do it yourself.

You must set the interrupt priority before calling this method. You MUST NOT do it after.

Source

pub fn spawner(&'static self) -> SendSpawner

Get a SendSpawner for this executor

This returns a [SendSpawner] you can use to spawn tasks on this executor.

This MUST only be called on an executor that has already been started. The function will panic otherwise.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.