pub struct System;Expand description
System-level functions (scheduler, timing, critical sections). 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 get_current_time_us() -> Duration
fn get_current_time_us() -> Duration
Returns the current system time as a Duration.
Converts the current tick count to microseconds and returns it as
a standard Duration type.
§Returns
Current system uptime as Duration
§Examples
use osal_rs::os::{System, SystemFn};
let uptime = System::get_current_time_us();
println!("System uptime: {:?}", uptime);Source§fn get_us_from_tick(duration: &Duration) -> TickType
fn get_us_from_tick(duration: &Duration) -> TickType
Converts a Duration to microsecond ticks.
Helper function for converting duration values to system tick counts in microsecond resolution.
§Parameters
duration- Duration to convert
§Returns
Equivalent tick count in microseconds
§Examples
use osal_rs::os::{System, SystemFn};
use core::time::Duration;
let duration = Duration::from_millis(100);
let us_ticks = System::get_us_from_tick(&duration);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 check_timer(timestamp: &Duration, time: &Duration) -> OsalRsBool
fn check_timer(timestamp: &Duration, time: &Duration) -> OsalRsBool
Checks if a timer has elapsed.
Compares the elapsed time since a timestamp against a target duration, handling tick counter overflow correctly for both 32-bit and 64-bit systems.
§Parameters
timestamp- Starting time referencetime- Target duration to wait for
§Returns
OsalRsBool::True- Timer has elapsedOsalRsBool::False- Timer has not yet elapsed
§Examples
use osal_rs::os::{System, SystemFn};
use core::time::Duration;
let start = System::get_current_time_us();
let timeout = Duration::from_secs(1);
// Later...
if System::check_timer(&start, &timeout).into() {
println!("Timeout occurred");
}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.
This function should be called at the end of an interrupt service routine to trigger a context switch if a higher priority task was woken during the ISR.
§Parameters
switch_required-pdTRUEif context switch is required,pdFALSEotherwise
§Examples
use osal_rs::os::{System, SystemFn};
use osal_rs::os::ffi::pdTRUE;
// In ISR:
let mut switch_required = pdFALSE;
// ... ISR operations that might require context switch ...
System::end_switching_isr(switch_required);Source§fn enter_critical()
fn enter_critical()
Enters a critical section at task level.
Disables scheduler and interrupts to protect shared resources.
Must be paired with exit_critical().
This is the task-level version; for ISR context use
enter_critical_from_isr().
§Examples
use osal_rs::os::{System, SystemFn};
System::enter_critical();
// Access shared resource safely
System::exit_critical();Source§fn exit_critical()
fn exit_critical()
Exits a critical section at task level.
Re-enables scheduler and interrupts after enter_critical().
Must be called from the same task that called enter_critical().
§Examples
use osal_rs::os::{System, SystemFn};
System::enter_critical();
// Critical section code
System::exit_critical();Source§fn enter_critical_from_isr() -> UBaseType
fn enter_critical_from_isr() -> UBaseType
Enters a critical section from an ISR context.
ISR-safe version of critical section entry. Returns the interrupt mask state
that must be passed to exit_critical_from_isr().
Use this instead of enter_critical() when in interrupt context.
§Returns
Saved interrupt status to be restored on exit
§Examples
use osal_rs::os::{System, SystemFn};
// In an interrupt handler
let saved_status = System::enter_critical_from_isr();
// Critical ISR code
System::exit_critical_from_isr(saved_status);Source§fn exit_critical_from_isr(saved_interrupt_status: UBaseType)
fn exit_critical_from_isr(saved_interrupt_status: UBaseType)
Exits a critical section from an ISR context.
Restores the interrupt mask to the state saved by
enter_critical_from_isr().
§Parameters
saved_interrupt_status- Interrupt status returned byenter_critical_from_isr()
§Examples
use osal_rs::os::{System, SystemFn};
let saved = System::enter_critical_from_isr();
// Protected ISR operations
System::exit_critical_from_isr(saved);