usb-device-xous: implement way to reset current block device app

This commit is contained in:
Gianguido Sorà 2023-01-26 19:29:20 +01:00
parent 9e5cc25a50
commit 12a7271732
No known key found for this signature in database
4 changed files with 35 additions and 15 deletions

View file

@ -33,6 +33,7 @@ pub(crate) enum Opcode {
SetBlockDevice,
SetBlockDeviceSID,
ResetBlockDevice,
/// Handle the USB interrupt
UsbIrqHandler,

View file

@ -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"),
}
});

View file

@ -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(

View file

@ -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");