Crate os_trait

Crate os_trait 

Source
Expand description

Traits used to adapter different embedded RTOS. It defines a trait OsInterface.

We use the mutex-traits crate to provide mutex functionality. You can implement your own mutex by implementing the RawMutex trait from the mutex-traits crate.

§Example

use os_trait::{prelude::*, FakeOs, StdOs, Duration, Timeout, Instant};

fn use_os<OS: OsInterface>() {
    let mutex = OS::mutex(2);

    let mut guard = mutex.try_lock().unwrap();
    assert_eq!(*guard, 2);

    OS::yield_thread();
    OS::delay().delay_ms(1);

    let mut t = Timeout::<OS>::millis(1);
    if t.timeout() {
        // handle timeout
    }

    let mut now = Instant::<OS>::now();
    now.elapsed();
    if now.timeout(&Duration::<OS>::millis(1)) {}

    let (notifier, waiter) = OS::notify();
    assert!(notifier.notify());
    assert!(waiter.wait(&Duration::<OS>::millis(1)));
}

fn select_os() {
    use_os::<FakeOs>();
    use_os::<StdOs>();
}

Use alias for convenience:

use os_trait::{prelude::*, StdOs as OS, os_type_alias};

os_type_alias!(OS);

fn use_os_type() {
    let mutex = Mutex::new(2);
    OS::yield_thread();
    OS::delay().delay_ms(1);

    let t = Timeout::millis(1);
    let dur = Duration::millis(1);
    let mut now = Instant::now();
    if now.timeout(&dur) {}

    let (notifier, waiter) = OS::notify();
    assert!(notifier.notify());
    assert!(waiter.wait(&Duration::millis(1)));
}

Re-exports§

pub use mutex::BlockingMutex;
pub use mutex::FakeRawMutex;
pub use os_impls::FakeOs;
pub use os_impls::StdOs;
pub use fugit;
pub use mutex_traits;
pub use timeout_trait;
pub use notifier::*;
pub use notifier_impls::*;

Modules§

delay
duration
fake_impls
fugit
fugit provides a comprehensive library of Duration and Instant for the handling of time in embedded systems. The library is specifically designed to maximize const-ification which allows for most comparisons and changes of time-base to be made at compile time, rather than run time.
mutex
notifier
notifier_impls
os_impls
prelude
std_impls
timeout

Macros§

os_type_alias
Use this macro to alias the OS-specific types for greater convenience, or manually alias only the ones you need.

Structs§

TickDelay
DelayNs implementation
TickDuration
TickTimeout

Traits§

ConstInit
Const Init Trait
DelayNs
Delay with up to nanosecond precision.
OsInterface
The interface for different operating systems.
RawMutex
Raw mutex trait.
TickInstant
It doesn’t require operation interfaces on TickInstant itself. Embedded systems can thus implement only the relative time version, which means you can not use it as a global timestamp.

Type Aliases§

Delay
Duration
Instant
KilohertzU32
Alias for kilohertz rate (u32 backing storage)
Mutex
Notifier
NotifyWaiter
Timeout