diff --git a/services/usb-device-xous/src/api.rs b/services/usb-device-xous/src/api.rs index f1730683c..ff2505b92 100644 --- a/services/usb-device-xous/src/api.rs +++ b/services/usb-device-xous/src/api.rs @@ -33,6 +33,7 @@ pub(crate) enum Opcode { SetBlockDevice, SetBlockDeviceSID, + ResetBlockDevice, /// Handle the USB interrupt UsbIrqHandler, diff --git a/services/usb-device-xous/src/apps_block_device.rs b/services/usb-device-xous/src/apps_block_device.rs index ed9ce94e3..4cd27296f 100644 --- a/services/usb-device-xous/src/apps_block_device.rs +++ b/services/usb-device-xous/src/apps_block_device.rs @@ -5,25 +5,11 @@ use std::sync::Mutex; use usbd_scsi::BlockDevice; use xous::msg_blocking_scalar_unpack; -#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive)] -pub enum BlockDeviceOp { - // Read signals the application on the other side to read some data into - // the shared MemoryRange and return. - Read, - - // Write signals the application on the other side to write some data in to the - // shared MemoryRange and return. - Write, - - // MaxLBA signals the application on the other side to return the max amount of - // LBA and return. - MaxLBA, -} - #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive)] pub enum BlockDeviceMgmtOp { SetOps, SetSID, + Reset, } #[repr(C, align(4096))] @@ -88,6 +74,19 @@ impl AppsBlockDevice { xous::return_scalar(msg.sender, 0).unwrap(); }) } + Some(BlockDeviceMgmtOp::Reset) => msg_blocking_scalar_unpack!(msg, 0, 0, 0, 0, { + let mut ac = app_cid_clone.lock().unwrap(); + let mut ids = rw_ids_clone.lock().unwrap(); + + *ac = None; + *ids = RwOp { + read_id: 0, + write_id: 0, + max_lba_id: 0, + }; + + xous::return_scalar(msg.sender, 0).unwrap(); + }), None => unimplemented!("missing opcode for appsblockdevice mgmt interface"), } }); diff --git a/services/usb-device-xous/src/lib.rs b/services/usb-device-xous/src/lib.rs index 0b169740b..b41c51f14 100644 --- a/services/usb-device-xous/src/lib.rs +++ b/services/usb-device-xous/src/lib.rs @@ -50,6 +50,18 @@ impl UsbHid { ).unwrap(); } + pub fn reset_block_device(&self) { + send_message(self.conn, + Message::new_blocking_scalar( + Opcode::ResetBlockDevice.to_usize().unwrap(), + 0, + 0, + 0, + 0, + ) + ).unwrap(); + } + /// used to query if the HID core was able to start. Mainly to handle edge cases between updates. pub fn is_soc_compatible(&self) -> bool { match send_message( diff --git a/services/usb-device-xous/src/main_hw.rs b/services/usb-device-xous/src/main_hw.rs index 1be8ee818..ad4c935ea 100644 --- a/services/usb-device-xous/src/main_hw.rs +++ b/services/usb-device-xous/src/main_hw.rs @@ -289,6 +289,14 @@ pub(crate) fn main_hw() -> ! { ).unwrap(); xous::return_scalar(msg.sender, 0).unwrap(); }), + Some(Opcode::ResetBlockDevice) => msg_blocking_scalar_unpack!(msg, 0, 0, 0, 0, { + xous::send_message(abdcid, + xous::Message::new_blocking_scalar( + apps_block_device::BlockDeviceMgmtOp::Reset.to_usize().unwrap(), 0, 0, 0, 0, + ) + ).unwrap(); + xous::return_scalar(msg.sender, 0).unwrap(); + }), Some(Opcode::SuspendResume) => msg_scalar_unpack!(msg, token, _, _, _, { usbmgmt.xous_suspend(); susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");