Skip to content

Commit aca54b0

Browse files
Merge pull request #35 from Neotron-Compute/extra-functions
Add a power_off, power_reboot, and compare-and-swap function.
2 parents cca2622 + 49db401 commit aca54b0

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "GPL-3.0-or-later"
77
name = "neotron-common-bios"
88
readme = "README.md"
99
repository = "https://github.com/neotron-compute/neotron-common-bios.git"
10-
version = "0.10.0"
10+
version = "0.11.0-alpha"
1111

1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

src/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub struct Api {
311311
/// (if any), or from the top of Region 0 (although this reduces the maximum
312312
/// application space available). The OS will prefer lower numbered regions
313313
/// (other than Region 0), so faster memory should be listed first.
314-
pub memory_get_region: extern "C" fn(region_index: u8) -> crate::FfiOption<types::MemoryRegion>,
314+
pub memory_get_region: extern "C" fn(region_index: u8) -> crate::FfiOption<MemoryRegion>,
315315

316316
// ========================================================================
317317
// Human Interface Device Support
@@ -598,6 +598,25 @@ pub struct Api {
598598
/// On a microcontroller, this will wait for interrupts. Running in an
599599
/// emulator, this will sleep the thread for a while.
600600
pub power_idle: extern "C" fn(),
601+
/// The OS will call this function to control power on this system.
602+
///
603+
/// This function will not return, because the system will be switched off
604+
/// before it can return. In the event on an error, this function will hang
605+
/// instead.
606+
pub power_control: extern "C" fn(mode: PowerMode) -> !,
607+
608+
// ========================================================================
609+
// Mutex functions
610+
// ========================================================================
611+
/// Performs a compare-and-swap on `value`.
612+
///
613+
/// * If `value == old_value`, sets `value = new_value` and returns `true`
614+
/// * If `value != old_value`, returns `false`
615+
pub compare_and_swap_bool: extern "C" fn(
616+
value: &core::sync::atomic::AtomicBool,
617+
old_value: bool,
618+
new_value: bool,
619+
) -> bool,
601620
}
602621

603622
// ============================================================================

src/types.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ pub struct MemoryRegion {
105105
pub kind: MemoryKind,
106106
}
107107

108+
/// The kinds of power control we can do.
109+
#[repr(C)]
110+
#[derive(Debug, Copy, Clone)]
111+
pub enum PowerMode {
112+
/// Turn the system power off
113+
Off,
114+
/// Reboot the main processor
115+
Reset,
116+
/// Reboot the main processor, but tell it to enter a bootloader mode for
117+
/// programming. Precisely what this will do will depend upon the BIOS. Some
118+
/// BIOSes will not have a bootloader mode and this will do a regular
119+
/// reboot.
120+
Bootloader,
121+
}
122+
108123
// ============================================================================
109124
// Impls
110125
// ============================================================================

0 commit comments

Comments
 (0)