Skip to content

Commit ac52081

Browse files
committed
Provide compare-and-swap function.
1 parent 13f4089 commit ac52081

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rp-pico = { version = "0.7", default-features = false, features = [
1919
# Cortex-M run-time (or start-up) code
2020
cortex-m-rt = "0.7"
2121
# The BIOS to OS API
22-
neotron-common-bios = "0.10"
22+
neotron-common-bios = { version = "0.11.0-alpha", git = "https://github.com/neotron-compute/neotron-common-bios", branch = "extra-functions" }
2323
# For the RP2040 bootloader
2424
rp2040-boot2 = "0.3.0"
2525
# For hardware abstraction traits
@@ -60,7 +60,7 @@ embedded-sdmmc = { version = "0.5", default-features = false, features = [
6060
] }
6161

6262
[build-dependencies]
63-
neotron-common-bios = "0.10"
63+
neotron-common-bios = { version = "0.11.0-alpha", git = "https://github.com/neotron-compute/neotron-common-bios", branch = "extra-functions" }
6464
vte = "0.11"
6565

6666
[[bin]]

src/main.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ static INTERRUPT_PENDING: AtomicBool = AtomicBool::new(false);
255255
/// Stack for Core 1
256256
static 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
259262
static 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]
21982233
unsafe fn HardFault(frame: &cortex_m_rt::ExceptionFrame) -> ! {

0 commit comments

Comments
 (0)