Skip to main content

System

Struct System 

Source
pub struct System;
Expand description

System-level functions (scheduler, timing, critical sections). Namespace for system-level operations (scheduler control, timing, thread introspection) - see the module docs for an overview and a runnable example. Zero-sized: never instantiated, only used as System::function(...).

Implementations§

Source§

impl System

Source

pub fn delay_with_to_tick(ticks: impl ToTick)

Blocks like System::delay, but accepts any ToTick duration (e.g. a core::time::Duration) instead of a raw tick count.

§Examples
use osal_rs::os::*;
use core::time::Duration;

let before = System::get_tick_count();
System::delay_with_to_tick(Duration::from_millis(10));
assert!(System::get_tick_count() >= before);
Source

pub fn delay_until_with_to_tick( previous_wake_time: &mut TickType, time_increment: impl ToTick, )

Blocks like System::delay_until, but accepts any ToTick increment (e.g. a core::time::Duration) instead of a raw tick count.

§Examples
use osal_rs::os::*;
use core::time::Duration;

let mut previous = System::get_tick_count();
System::delay_until_with_to_tick(&mut previous, Duration::from_millis(5));

Trait Implementations§

Source§

impl System for System

Source§

fn start()

Spins until System::stop is called from another thread. There is no real scheduler on POSIX to hand control to, so this is just a busy loop over an atomic flag - unlike FreeRTOS, where the equivalent call never returns.

§Examples
use osal_rs::os::*;
use std::sync::Arc;

let mut stopper = Thread::new("stopper", 1024, 1);
stopper.spawn_simple(|| {
    System::delay(10);
    System::stop();
    Ok(Arc::new(()))
}).unwrap();

System::start(); // blocks here until `stop()` runs above
Source§

fn suspend_all()

Suspends every currently Ready/Running thread spawned through this crate’s crate::os::Thread API (see crate::os::ThreadFn::suspend).

§Examples
use osal_rs::os::*;
use std::sync::Arc;

let mut worker = Thread::new("worker", 1024, 1);
worker.spawn_simple(|| {
    System::delay(200);
    Ok(Arc::new(()))
}).unwrap();

System::delay(10); // give it a moment to start running
System::suspend_all();
assert!(System::resume_all() >= 1);
Source§

fn resume_all() -> BaseType

Resumes every currently Suspended thread spawned through this crate’s crate::os::Thread API, returning how many were resumed.

See System::suspend_all for a complete example.

Source§

fn stop()

Signals System::start’s spin loop to return. See System::start for a complete example.

Source§

fn get_tick_count() -> TickType

Returns the number of ticks elapsed since the first time any of System::get_tick_count/System::get_current_time_us was called in this process (that first call defines tick 0).

§Examples
use osal_rs::os::*;

let before = System::get_tick_count();
System::delay(5);
assert!(System::get_tick_count() >= before);
Source§

fn get_current_time_us() -> Duration

Same reference point as System::get_tick_count, but returned as a Duration instead of a raw tick count.

§Examples
use osal_rs::os::*;

let before = System::get_current_time_us();
System::delay(5);
assert!(System::get_current_time_us() >= before);
Source§

fn get_ms_from_tick(duration: &Duration) -> TickType

Converts a Duration to POSIX ticks (milliseconds); see crate::posix::duration for the same conversion via ToTick.

§Examples
use osal_rs::os::*;
use core::time::Duration;

assert_eq!(System::get_ms_from_tick(&Duration::from_millis(250)), 250);
Source§

fn count_threads() -> usize

Number of threads known to the system: every thread spawned through this crate’s crate::os::Thread API, plus the calling thread itself.

§Examples
use osal_rs::os::*;

// Just the calling thread: nothing else has been spawned yet.
assert_eq!(System::count_threads(), 1);
Source§

fn get_all_thread() -> SystemState

Returns a SystemState snapshot of every thread known to the system, mirroring System::count_threads’s “+1 for the caller” accounting.

§Examples
use osal_rs::os::*;

let state = System::get_all_thread();
assert_eq!(state.len(), System::count_threads());
Source§

fn delay(ticks: TickType)

Blocks the calling thread for ticks (milliseconds on this backend), automatically resuming the sleep if interrupted by a signal before it elapsed.

§Examples
use osal_rs::os::*;

let before = System::get_tick_count();
System::delay(20);
assert!(System::get_tick_count() - before >= 20);
Source§

fn delay_until(previous_wake_time: &mut TickType, time_increment: TickType)

Blocks until *previous_wake_time + time_increment (absolute ticks), then advances *previous_wake_time by time_increment - a fixed period loop that doesn’t drift with the time spent doing work each iteration, unlike calling System::delay with the same increment every time.

§Examples
use osal_rs::os::*;

let before = System::get_tick_count();
let mut previous = before;
System::delay_until(&mut previous, 20);

assert_eq!(previous, before + 20);
assert!(System::get_tick_count() >= previous);
Source§

fn check_timer(timestamp: &Duration, time: &Duration) -> OsalRsBool

Returns OsalRsBool::True once at least time has elapsed since timestamp (both measured against System::get_current_time_us’s clock).

§Examples
use osal_rs::os::*;
use osal_rs::utils::OsalRsBool;
use core::time::Duration;

let start = System::get_current_time_us();
assert_eq!(System::check_timer(&start, &Duration::from_millis(500)), OsalRsBool::False);

System::delay(20);
assert_eq!(System::check_timer(&start, &Duration::from_millis(10)), OsalRsBool::True);
Source§

fn yield_from_isr(higher_priority_task_woken: BaseType)

Yields the processor (sched_yield(2)) if higher_priority_task_woken is non-zero, a no-op otherwise. On FreeRTOS this triggers a context switch to a just-woken higher-priority task from within an ISR; POSIX has no real interrupt context, so this exists purely for API compatibility.

§Examples
use osal_rs::os::*;

System::yield_from_isr(1); // yields
System::yield_from_isr(0); // no-op
Source§

fn end_switching_isr(switch_required: BaseType)

Identical to System::yield_from_isr under a different name, matching FreeRTOS’s portEND_SWITCHING_ISR naming convention.

§Examples
use osal_rs::os::*;

System::end_switching_isr(1);
Source§

fn critical_section_enter()

No-op on POSIX: there is no real interrupt/scheduler state to guard, unlike FreeRTOS where this disables interrupts/the scheduler.

§Examples
use osal_rs::os::*;

System::critical_section_enter();
System::critical_section_exit();
Source§

fn critical_section_exit()

Source§

fn critical_section_enter_from_isr() -> UBaseType

ISR-context counterpart of System::critical_section_enter; always returns 0 (nothing to restore) since it’s a no-op on POSIX.

§Examples
use osal_rs::os::*;

let saved = System::critical_section_enter_from_isr();
System::critical_section_exit_from_isr(saved);
Source§

fn critical_section_exit_from_isr(_: UBaseType)

Source§

fn get_free_heap_size() -> usize

POSIX processes don’t have a fixed heap the way FreeRTOS does (the allocator can keep extending it via mmap/brk), so this reports available physical memory as the closest analogue.

§Examples
use osal_rs::os::*;

assert!(System::get_free_heap_size() > 0);

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.