From dab619d6273597fcd9770dcd618987b247f3fc75 Mon Sep 17 00:00:00 2001 From: Andrea Nall Date: Sun, 20 Jun 2021 01:12:16 -0500 Subject: [PATCH] split rom_data into safe and unsafe functions This was originally applied in 71a7057b76d9da5bb3bae4520dd9d145430b8429 and got inadvertently reverted as part of e3be4f8025f3fa9344910aa627891ad7bde86980 --- rp2040-hal/src/rom_data.rs | 45 ++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/rp2040-hal/src/rom_data.rs b/rp2040-hal/src/rom_data.rs index 8b80148..77afe98 100644 --- a/rp2040-hal/src/rom_data.rs +++ b/rp2040-hal/src/rom_data.rs @@ -52,6 +52,25 @@ macro_rules! rom_funcs { } } +macro_rules! rom_funcs_unsafe { + ( + $( + $(#[$outer:meta])* + $c:literal $name:ident ( + $( $aname:ident : $aty:ty ),* + ) -> $ret:ty ; + )* + ) => { + $( + $(#[$outer])* + pub unsafe fn $name($( $aname:$aty ),*) -> $ret{ + let func: extern "C" fn( $( $aty ),* ) -> $ret = rom_table_lookup(FUNC_TABLE, *$c); + func($( $aname ),*) + } + )* + } +} + rom_funcs! { /// Return a count of the number of 1 bits in value. b"P3" popcount32(value: u32) -> u32; @@ -65,6 +84,20 @@ rom_funcs! { /// Return the number of consecutive low order 0 bits of value. If value is zero, returns 32. b"T3" ctz32(value: u32) -> u32; + /// Resets the RP2040 and uses the watchdog facility to re-start in BOOTSEL mode: + /// * gpio_activity_pin_mask is provided to enable an 'activity light' via GPIO attached LED + /// for the USB Mass Storage Device: + /// * 0 No pins are used as per cold boot. + /// * Otherwise a single bit set indicating which GPIO pin should be set to output and + /// raised whenever there is mass storage activity from the host. + /// * disable_interface_mask may be used to control the exposed USB interfaces: + /// * 0 To enable both interfaces (as per cold boot). + /// * 1 To disable the USB Mass Storage Interface. + /// * 2 to Disable the USB PICOBOOT Interface. + b"UB" reset_to_usb_boot(gpio_activity_pin_mask: u32, disable_interface_mask: u32) -> (); +} + +rom_funcs_unsafe! { /// Sets n bytes start at ptr to the value c and returns ptr b"MS" memset(ptr: *mut u8, c: u8, n: u8) -> *mut u8; @@ -113,18 +146,6 @@ rom_funcs! { /// know exactly what kind of flash device is connected. b"CX" flash_enter_cmd_xip() -> (); - /// Resets the RP2040 and uses the watchdog facility to re-start in BOOTSEL mode: - /// * gpio_activity_pin_mask is provided to enable an 'activity light' via GPIO attached LED - /// for the USB Mass Storage Device: - /// * 0 No pins are used as per cold boot. - /// * Otherwise a single bit set indicating which GPIO pin should be set to output and - /// raised whenever there is mass storage activity from the host. - /// * disable_interface_mask may be used to control the exposed USB interfaces: - /// * 0 To enable both interfaces (as per cold boot). - /// * 1 To disable the USB Mass Storage Interface. - /// * 2 to Disable the USB PICOBOOT Interface. - b"UB" reset_to_usb_boot(gpio_activity_pin_mask: u32, disable_interface_mask: u32) -> (); - /// This is the method that is entered by core 1 on reset to wait to be launched by core 0. /// There are few cases where you should call this method (resetting core 1 is much better). /// This method does not return and should only ever be called on core 1.