[−][src]Module drone_cortex_m::sv
The Supervisor module.
Supervisor is an abstraction for the SVC
assembly instruction, which means
SuperVisor Call, and the SV_CALL
exception.
Usage
use drone_cortex_m::{sv, thr}; sv! { /// The supervisor. pub struct Sv; /// Array of services. static SERVICES; // The list of attached services goes here. // SwitchContextService; // SwitchBackService; } thr::vtable! { use Thr; pub struct Vtable; pub struct Handlers; pub struct Thrs; static THREADS; // Define an external function handler for the SV_CALL exception. fn SV_CALL; } thr! { use THREADS; pub struct Thr {} pub struct ThrLocal {} } #[no_mangle] pub static VTABLE: Vtable = Vtable::new(Handlers { reset, // Attach the SV_CALL handler for the supervisor `Sv`. sv_call: drone_cortex_m::sv::sv_handler::<Sv>, }); unsafe extern "C" fn reset() -> ! { loop {} }
Predefined Services
If SwitchContextService
and
SwitchBackService
are defined for the supervisor,
switch_context
and
switch_back
functions become available to
switch the program stack.
use drone_cortex_m::sv::{Switch, SwitchBackService, SwitchContextService}; use drone_cortex_m::sv; sv! { /// The supervisor. pub struct Sv; /// Array of services. static SERVICES; SwitchContextService; SwitchBackService; } unsafe { // Allocate the stack. let stack = Box::<[u8]>::new_uninit_slice(0x800).assume_init(); // `stack_ptr` will store the current stack pointer. let mut stack_ptr = stack.as_ptr(); let mut data = Box::<u32>::new(0); let mut data_ptr = &mut *data as *mut u32; Sv::switch_context(data_ptr, &mut stack_ptr); // ------------------- // Using the new stack. // ------------------- Sv::switch_back(&mut data_ptr); }
Structs
SwitchBackService | A service to switch back from a process stack. |
SwitchContextService | A service to switch to a process stack. |
Traits
Supervisor | Generic supervisor. |
SvCall | A supervisor call. |
SvService | Generic supervisor service. |
Switch | Extends |
Functions
service_handler⚠ | This function is called by |
sv_call⚠ | Calls |
sv_handler⚠ |
|