pub struct System;Expand description
System-level operations and utilities.
Provides a collection of static methods for controlling the FreeRTOS scheduler and accessing system-wide information. All methods are static.
§Examples
§Starting the scheduler
use osal_rs::os::{System, SystemFn};
// Create threads, queues, etc.
// ...
// Start the scheduler (never returns in normal operation)
System::start();§Delays and timing
use osal_rs::os::{System, SystemFn};
use core::time::Duration;
// Simple delay
System::delay_with_to_tick(Duration::from_millis(500));
// Get current system time
let now = System::get_current_time_us();
println!("Uptime: {:?}", now);
// Periodic execution using delay_until
let mut last_wake = System::get_tick_count();
loop {
System::delay_until_with_to_tick(&mut last_wake, Duration::from_millis(100));
println!("Periodic task");
}§Critical sections
use osal_rs::os::{System, SystemFn};
// Protect shared data
System::critical_section_enter();
// Access shared data here
// ...
System::critical_section_exit();§Thread enumeration
use osal_rs::os::{System, SystemFn};
let count = System::count_threads();
println!("Active threads: {}", count);
let state = System::get_all_thread();
for thread in &state.tasks {
println!("Thread: {} - Stack high water: {}",
thread.name,
thread.stack_high_water_mark
);
}§Heap monitoring
use osal_rs::os::{System, SystemFn};
let free_heap = System::get_free_heap_size();
println!("Free heap: {} bytes", free_heap);§Scheduler suspend/resume
use osal_rs::os::{System, SystemFn};
// Suspend scheduler for atomic operations
System::suspend_all();
// Perform atomic operations
// ...
System::resume_all();System-level operations and scheduler control.
Provides static methods for controlling the RTOS scheduler, timing, and system-wide operations.
Implementations§
Source§impl System
impl System
Sourcepub fn delay_with_to_tick(ticks: impl ToTick)
pub fn delay_with_to_tick(ticks: impl ToTick)
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, )
Delays until an absolute time point with tick conversion.
Used for precise periodic timing.
§Parameters
previous_wake_time- Previous wake time (updated by this function)time_increment- Time increment for next wake
§Examples
use osal_rs::os::{System, SystemFn};
use core::time::Duration;
let mut last_wake = System::get_tick_count();
loop {
// Do work...
System::delay_until_with_to_tick(&mut last_wake, Duration::from_millis(100));
}Trait Implementations§
Source§impl System for System
impl System for System
Source§fn start()
fn start()
Starts the RTOS scheduler.
This function never returns if successful. All created threads will begin execution according to their priorities.
§Examples
use osal_rs::os::{System, SystemFn, Thread};
// Create threads...
let thread = Thread::new("worker", 2048, 5, || {
loop { /* work */ }
}).unwrap();
thread.start().unwrap();
// Start scheduler (does not return)
System::start();Source§fn get_state() -> ThreadState
fn get_state() -> ThreadState
Source§fn suspend_all()
fn suspend_all()
Source§fn resume_all() -> BaseType
fn resume_all() -> BaseType
Source§fn get_tick_count() -> TickType
fn get_tick_count() -> TickType
Source§fn count_threads() -> usize
fn count_threads() -> usize
Source§fn get_all_thread() -> SystemState
fn get_all_thread() -> SystemState
Retrieves a snapshot of all threads in the system.
Returns detailed metadata for every thread including state, priority, stack usage, and runtime statistics.
§Returns
SystemState containing all thread information
§Examples
use osal_rs::os::{System, SystemFn};
let state = System::get_all_thread();
for thread in &state.tasks {
println!("Thread: {} - Stack remaining: {}",
thread.name,
thread.stack_high_water_mark
);
}Source§fn delay_until(previous_wake_time: &mut TickType, time_increment: TickType)
fn delay_until(previous_wake_time: &mut TickType, time_increment: TickType)
Delays until an absolute time point.
Used for creating precise periodic timing. The previous_wake_time
is updated automatically for the next period.
§Parameters
previous_wake_time- Pointer to last wake time (will be updated)time_increment- Period in ticks
§Examples
use osal_rs::os::{System, SystemFn};
let mut last_wake = System::get_tick_count();
loop {
// Periodic task code...
System::delay_until(&mut last_wake, 100); // 100 tick period
}Source§fn critical_section_enter()
fn critical_section_enter()
Enters a critical section.
Disables interrupts or increments the scheduler lock nesting count.
Must be paired with critical_section_exit().
§Examples
use osal_rs::os::{System, SystemFn};
System::critical_section_enter();
// Critical code - no task switches or interrupts
System::critical_section_exit();Source§fn yield_from_isr(higher_priority_task_woken: BaseType)
fn yield_from_isr(higher_priority_task_woken: BaseType)
Yields to a higher priority task from ISR context.
Should be called when an ISR operation wakes a higher priority task.
§Parameters
higher_priority_task_woken- pdTRUE if higher priority task was woken
§Examples
// In ISR:
let mut woken = pdFALSE;
// ... ISR operations that might wake a task ...
System::yield_from_isr(woken);Source§fn end_switching_isr(switch_required: BaseType)
fn end_switching_isr(switch_required: BaseType)
Ends ISR and performs context switch if needed.
§Parameters
switch_required- pdTRUE if context switch is required