@@ -255,6 +255,9 @@ static INTERRUPT_PENDING: AtomicBool = AtomicBool::new(false);
255255/// Stack for Core 1
256256static mut CORE1_STACK : [ usize ; 256 ] = [ 0 ; 256 ] ;
257257
258+ /// The pin we use for external interrupt input
259+ static IRQ_PIN : NeoMutex < Option < IrqPin > > = NeoMutex :: new ( None ) ;
260+
258261/// The table of API calls we provide the OS
259262static API_CALLS : common:: Api = common:: Api {
260263 api_version_get,
@@ -305,6 +308,9 @@ static API_CALLS: common::Api = common::Api {
305308 bus_interrupt_status,
306309 block_dev_eject,
307310 power_idle,
311+ power_off,
312+ power_reboot,
313+ compare_and_swap_bool,
308314} ;
309315
310316/// Seconds between the Neotron Epoch (2000-01-01T00:00:00) and the UNIX Epoch (1970-01-01T00:00:00).
@@ -2114,7 +2120,36 @@ extern "C" fn time_ticks_per_second() -> common::Ticks {
21142120 common:: Ticks ( 1_000_000 )
21152121}
21162122
2117- static IRQ_PIN : NeoMutex < Option < IrqPin > > = NeoMutex :: new ( None ) ;
2123+ /// Power the system off.
2124+ extern "C" fn power_off ( ) -> ! {
2125+ todo ! ( ) ;
2126+ }
2127+
2128+ /// Reboot the system.
2129+ extern "C" fn power_reboot ( ) -> ! {
2130+ todo ! ( ) ;
2131+ }
2132+
2133+ /// Performs a compare-and-swap on `value`.
2134+ ///
2135+ /// * If `value == old_value`, sets `value = new_value` and returns `true`
2136+ /// * If `value != old_value`, returns `false`
2137+ extern "C" fn compare_and_swap_bool ( value : & AtomicBool , old_value : bool , new_value : bool ) -> bool {
2138+ let state = unsafe { critical_section:: acquire ( ) } ;
2139+
2140+ let result = if value. load ( Ordering :: Relaxed ) == old_value {
2141+ value. store ( new_value, Ordering :: Relaxed ) ;
2142+ true
2143+ } else {
2144+ false
2145+ } ;
2146+
2147+ unsafe {
2148+ critical_section:: release ( state) ;
2149+ }
2150+
2151+ result
2152+ }
21182153
21192154/// Called when we get a SIO interrupt on the main bank of GPIO pins.
21202155///
@@ -2192,7 +2227,7 @@ fn check_stack(start: *const usize, stack_len_bytes: usize, check_word: usize) {
21922227/// This probably means something panicked, and the Rust code was compiled to
21932228/// abort-on-panic. Or someone jumped to a bad address.
21942229///
2195- /// Hopefully the debug output we print will of be some use. Think of it as our
2230+ /// Hopefully the debug output we print will be of some use. Think of it as our
21962231/// Blue Screen of Death, or Guru Meditation Error.
21972232#[ cortex_m_rt:: exception]
21982233unsafe fn HardFault ( frame : & cortex_m_rt:: ExceptionFrame ) -> ! {
0 commit comments