riot_wrappers::thread::tokenparts

Struct ValueInThread

Source
pub struct ValueInThread<T> {
    value: T,
    _in_thread: InThread,
}
Expand description

A value combined with an InThread marker

This does barely implement anything on its own, but the module implementing T might provide extra methods.

This makes the wrapped value not Send.

Fields§

§value: T§_in_thread: InThread

Implementations§

Source§

impl<T> ValueInThread<T>

Source

pub fn into_inner(self) -> T

Extract the wrapped value

This does not produce the original in_thread value; these are easy enough to re-obtain or to keep a copy of around.

Source§

impl<const HZ: u32> ValueInThread<Clock<HZ>>

Source

pub fn sleep(&self, duration: Ticks<HZ>)

Available on riot_module_ztimer only.

Pause the current thread for the duration of ticks in the timer’s time scale.

Wraps ztimer_sleep

Source

pub fn spin(&self, duration: Ticks<HZ>)

Available on riot_module_ztimer only.

Keep the current thread in a busy loop until the duration of ticks in the timer’s tim scale has passed

Quoting the original documentation, “This blocks lower priority threads. Use only for very short delays.”.

Wraps ztimer_spin

Note that this would not technically require the self to be a ValueInThread (as spinning is doable in an ISR), but it’s so discouraged that the Rust wrapper takes the position that it’s best done using a ValueInThread.

Source

pub fn sleep_extended(&self, duration: Duration)

Available on riot_module_ztimer only.

Pause the current thread for the given duration, possibly exceeding values expressible in Ticks<HZ>.

The duration is converted into ticks (rounding up), and overflows are caught by sleeping multiple times.

It is up to the caller to select the Clock suitable for efficiency. (Even sleeping for seconds on the microseconds timer would not overflow the timer’s interface’s u32, but the same multiple-sleeps trick may need to be employed by the implementation, and would keep the system from entering deeper sleep modes).

Source

pub fn set_during<I: FnOnce() + Send, M: FnOnce() -> R, R>( &self, callback: I, ticks: Ticks<HZ>, in_thread: M, ) -> R

Available on riot_module_ztimer only.

Set the given callback to be executed in an interrupt some ticks in the future.

Then, start the in_thread function from in the thread this is called from (as a regular function call).

After the in_thread function terminates, the callback is dropped if it has not already triggered.

Further Development:

  • This could probably be done with some sort of pinning instead, thus avoiding the nested scope – but getting the Drop right is comparatively tricky, because when done naively it needs runtime state.

  • The callback could be passed something extra that enables it to set the timer again and again. Granted, there’s ztimer_periodic for these cases (and it has better drifting properties), but for something like exponential retransmission it could be convenient.

    (Might make sense to do this without an extra function variant: if the callback ignores the timer argument and always returns None, that’s all in the caller type and probebly inlined right away).

While (unless with sleep) nothing would break if this were called from an interrupt context, it would not work either: As RIOT uses flat interrupt priorities, any code executed in the in_thread handler would still be run in the original interrupt, and while the configured ZTimer would fire its interrupt during that time, the interrupt would not be serviced, and the timer would be removed already by the time the original interrupt completes and ZTimer is serviced (finding no actually pending callback).

Source§

impl<'a, T> ValueInThread<&'a Mutex<T>>

Source

pub fn lock(self) -> MutexGuard<'a, T>

Get an accessor to the mutex when the mutex is available

Through the crate::thread::ValueInThread, this is already guaranteed to run in a thread context, so no additional check is performed.

Trait Implementations§

Source§

impl<T: Clone> Clone for ValueInThread<T>

Source§

fn clone(&self) -> ValueInThread<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const F: u32> DelayNs for ValueInThread<Clock<F>>

Available on riot_module_ztimer only.
Source§

fn delay_ns(&mut self, ns: u32)

Pauses execution for at minimum ns nanoseconds. Pause can be longer if the implementation requires it due to precision/timing issues.
Source§

fn delay_us(&mut self, us: u32)

Pauses execution for at minimum us microseconds. Pause can be longer if the implementation requires it due to precision/timing issues.
Source§

fn delay_ms(&mut self, ms: u32)

Pauses execution for at minimum ms milliseconds. Pause can be longer if the implementation requires it due to precision/timing issues.
Source§

impl<T> Deref for ValueInThread<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T> DerefMut for ValueInThread<T>

Source§

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

Mutably dereferences the value.
Source§

impl<T: Copy> Copy for ValueInThread<T>

Auto Trait Implementations§

§

impl<T> Freeze for ValueInThread<T>
where T: Freeze,

§

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

§

impl<T> !Send for ValueInThread<T>

§

impl<T> !Sync for ValueInThread<T>

§

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

§

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoSwitch for T

Source§

fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>

Consumes the IoPin returning a Switch of the appropriate ActiveLevel. Read more
Source§

fn into_active_low_switch(self) -> Switch<Self, ActiveLow>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveLow>. Read more
Source§

fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveHigh>. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.