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
impl System
Sourcepub fn delay_with_to_tick(ticks: impl ToTick)
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);Sourcepub fn delay_until_with_to_tick(
previous_wake_time: &mut TickType,
time_increment: impl ToTick,
)
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
impl System for System
Source§fn start()
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 aboveSource§fn suspend_all()
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
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()
fn stop()
Signals System::start’s spin loop to return. See
System::start for a complete example.
Source§fn get_tick_count() -> TickType
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
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
fn get_ms_from_tick(duration: &Duration) -> TickType
Source§fn count_threads() -> usize
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
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)
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)
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
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)
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-opSource§fn end_switching_isr(switch_required: BaseType)
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()
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_enter_from_isr() -> UBaseType
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 get_free_heap_size() -> usize
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);