mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
some touch-up/cleanup; add a timeout on a blocking read
This commit is contained in:
parent
1ec6bd7df4
commit
bebf323798
15 changed files with 124 additions and 232 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
|
@ -4326,13 +4326,14 @@ name = "usbd_bulk_only_transport"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"embedded-hal",
|
||||
"itm_logger",
|
||||
"log",
|
||||
"nb 0.1.3",
|
||||
"packing 0.2.0",
|
||||
"typenum",
|
||||
"usb-device",
|
||||
"usbd_mass_storage 0.1.0",
|
||||
"xous 0.9.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"xous-api-ticktimer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -4355,7 +4356,6 @@ name = "usbd_mass_storage"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"embedded-hal",
|
||||
"itm_logger",
|
||||
"log",
|
||||
"nb 0.1.3",
|
||||
"packing 0.2.0",
|
||||
|
|
@ -4399,7 +4399,6 @@ name = "usbd_scsi"
|
|||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"embedded-hal",
|
||||
"itm_logger",
|
||||
"log",
|
||||
"nb 0.1.3",
|
||||
"packing 0.2.0",
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ pub fn packed_derive(input: TokenStream) -> TokenStream {
|
|||
enum Attr {
|
||||
Flag { name: Ident, span: Span },
|
||||
Value { name: Ident, value: Lit, span: Span },
|
||||
Lit { value: Lit, span: Span },
|
||||
Lit { _value: Lit, span: Span },
|
||||
}
|
||||
|
||||
impl Attr {
|
||||
|
|
@ -148,7 +148,7 @@ fn flatten_attrs(attrs: &Vec<Attribute>) -> Result<Vec<Attr>, Error> {
|
|||
NestedMeta::Meta(Meta::NameValue(MetaNameValue { path, lit, .. })) =>
|
||||
Attr::Value { name: get_single_segment(path)?, value: lit.clone(), span: path.span() },
|
||||
NestedMeta::Lit(l) =>
|
||||
Attr::Lit { value: l.clone(), span: a.span() },
|
||||
Attr::Lit { _value: l.clone(), span: a.span() },
|
||||
y => panic!("y: {:?}", y),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,17 +17,10 @@ usb-device = "0.2.4"
|
|||
embedded-hal = "0.2.3"
|
||||
nb = "0.1.2"
|
||||
typenum = "1.11.2"
|
||||
itm_logger = { version = "0.1.0", default-features = false }
|
||||
usbd_mass_storage = { version = "0.1.0", path = "../usbd_mass_storage" }
|
||||
packing = { version = "0.2.0", path = "../packing/packing" }
|
||||
log = "0.4.17"
|
||||
xous = "0.9.29"
|
||||
ticktimer-server = { package = "xous-api-ticktimer", version = "0.9.23" }
|
||||
|
||||
[features]
|
||||
trace-bot-headers = []
|
||||
trace-bot-states = []
|
||||
trace-bot-bytes = []
|
||||
trace-bot-zlp = []
|
||||
trace-bot-buffer = []
|
||||
trace-usb-control = [ "usbd_mass_storage/trace-usb-control" ]
|
||||
trace-all = [ "trace-bot-headers", "trace-bot-states", "trace-bot-bytes", "trace-bot-zlp", "trace-bot-buffer",
|
||||
"trace-usb-control" ]
|
||||
|
|
|
|||
|
|
@ -146,6 +146,9 @@ pub struct BulkOnlyTransport<'a, B: UsbBus> {
|
|||
/// Indicates we are going to end the current data transaction after draining the current
|
||||
/// buffer regardless of data_residue
|
||||
data_done: bool,
|
||||
|
||||
/// access handle for the ticktimer, so we can measure time/delays
|
||||
tt: ticktimer_server::Ticktimer,
|
||||
}
|
||||
|
||||
impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
||||
|
|
@ -173,6 +176,7 @@ impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
|||
data_i: 0,
|
||||
last_packet_full: false,
|
||||
data_done: false,
|
||||
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
||||
}
|
||||
}
|
||||
pub fn debug(&self) {
|
||||
|
|
@ -233,7 +237,7 @@ impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
|||
.map_err(|_| Error::DataError);
|
||||
if cbw.is_err() {
|
||||
let err = cbw.err().unwrap();
|
||||
warn!("CBW unpack error: {:?}", err);
|
||||
log::warn!("CBW unpack error: {:?}", err);
|
||||
self.buffer_i = 0;
|
||||
return Err(err);
|
||||
}
|
||||
|
|
@ -357,37 +361,12 @@ impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
|||
|
||||
/// Returns a slice containing data from the buffer if there is `len` bytes available
|
||||
/// panics if len requested is > the max size of the buffer
|
||||
/// `take_available` modifies behaviour to return whatever is available, even if that is [u8; 0]
|
||||
/// Waits until a time-out for data to become available;
|
||||
/// returns WouldBlock if there isn't enough data available
|
||||
pub fn take_buffered_data(&mut self, len: usize, take_available: bool) -> Result<&[u8], Error> {
|
||||
/*
|
||||
if len > self.buffer.len() {
|
||||
panic!("BulkOnlyTransport::take_buffered_data called with len > buffer.len() ({} > {}) which can never be successful",
|
||||
len, self.buffer.len());
|
||||
}
|
||||
|
||||
log::info!("take_buffered_data() len: {}", len);
|
||||
let available = self.buffer_i - self.data_i;
|
||||
if !take_available && len > available {
|
||||
trace_bot_buffer!("BUFFER> contains insufficient data for take; requested: {}, available: {}", len, self.buffer_i - self.data_i);
|
||||
Err(WouldBlock)?
|
||||
}
|
||||
|
||||
let s = self.data_i;
|
||||
let len = len.min(available);
|
||||
let e = s + len;
|
||||
|
||||
self.data_i += len;
|
||||
if self.data_i == self.buffer_i {
|
||||
self.data_i = 0;
|
||||
self.buffer_i = 0;
|
||||
}
|
||||
trace_bot_buffer!("BUFFER> took {}, available after: {}", len, self.buffer_i - self.data_i);
|
||||
|
||||
log::info!("take_buffered_data() s: {} e: {}", s, e);
|
||||
Ok(&self.buffer[s..e])
|
||||
*/
|
||||
pub fn take_buffered_data(&mut self, len: usize) -> Result<&[u8], Error> {
|
||||
log::debug!("take_buffered_data() len: {}", len);
|
||||
const TIMEOUT_MS: u64 = 2000;
|
||||
let start = self.tt.elapsed_ms();
|
||||
loop {
|
||||
match self.inner.read_packet(&mut self.buffer[..len]) {
|
||||
Ok(l) => {
|
||||
|
|
@ -397,6 +376,10 @@ impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
|||
match e {
|
||||
UsbError::WouldBlock => {
|
||||
log::debug!("bulk read not ready yet");
|
||||
if self.tt.elapsed_ms() - start > TIMEOUT_MS {
|
||||
log::error!("bulk read timed out");
|
||||
return Err(Error::UsbError(WouldBlock))
|
||||
}
|
||||
continue;
|
||||
},
|
||||
_ => return Err(Error::UsbError(e)),
|
||||
|
|
@ -577,7 +560,7 @@ impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
|||
if self.command_status_wrapper.data_residue >= bytes {
|
||||
self.command_status_wrapper.data_residue -= bytes;
|
||||
} else {
|
||||
warn!("Read more bytes that CBW offered");
|
||||
log::warn!("Read more bytes that CBW offered");
|
||||
self.command_status_wrapper.data_residue = 0;
|
||||
}
|
||||
|
||||
|
|
@ -587,7 +570,6 @@ impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
|||
self.command_status_wrapper.data_residue,
|
||||
self.buffer_i - self.data_i,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
self.check_end_data_transfer()?;
|
||||
|
|
@ -660,7 +642,7 @@ impl<B: UsbBus> UsbClass<B> for BulkOnlyTransport<'_, B> {
|
|||
};
|
||||
|
||||
if let Some(Err(e)) = handled_res {
|
||||
error!("Error from ControlIn.accept: {:?}", e);
|
||||
log::error!("Error from ControlIn.accept: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const SIGNATURE: u32 = 0x53425355;
|
|||
|
||||
/// A wrapper that identifies a command sent from the host to the
|
||||
/// device on the OUT endpoint. Describes the data transfer IN or OUT
|
||||
/// that should happen immediatly after this wrapper is received.
|
||||
/// that should happen immediately after this wrapper is received.
|
||||
/// Little Endian
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Debug, Packed)]
|
||||
#[packed(little_endian, lsb0)]
|
||||
|
|
|
|||
|
|
@ -10,30 +10,10 @@ pub use bulk_only_transport::{
|
|||
};
|
||||
|
||||
mod logging {
|
||||
pub use itm_logger::*;
|
||||
|
||||
#[cfg(feature = "trace-bot-headers")]
|
||||
pub use itm_logger::trace as trace_bot_headers;
|
||||
|
||||
#[cfg(feature = "trace-bot-states")]
|
||||
pub use itm_logger::trace as trace_bot_states;
|
||||
|
||||
#[cfg(feature = "trace-bot-bytes")]
|
||||
pub use itm_logger::trace as trace_bot_bytes;
|
||||
|
||||
#[cfg(feature = "trace-bot-zlp")]
|
||||
pub use itm_logger::trace as trace_bot_zlp;
|
||||
|
||||
#[cfg(feature = "trace-bot-buffer")]
|
||||
pub use itm_logger::trace as trace_bot_buffer;
|
||||
|
||||
#[cfg(feature = "trace-usb-control")]
|
||||
pub use itm_logger::trace as trace_usb_control;
|
||||
|
||||
pub use log::debug as trace_bot_headers;
|
||||
pub use log::debug as trace_bot_states;
|
||||
pub use log::debug as trace_bot_bytes;
|
||||
pub use log::debug as trace_bot_zlp;
|
||||
pub use log::debug as trace_bot_buffer;
|
||||
pub use log::trace as trace_bot_bytes;
|
||||
pub use log::trace as trace_bot_zlp;
|
||||
pub use log::trace as trace_bot_buffer;
|
||||
pub use log::debug as trace_usb_control;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,7 @@ usb-device = "0.2.4"
|
|||
embedded-hal = "0.2.3"
|
||||
nb = "0.1.2"
|
||||
typenum = "1.11.2"
|
||||
itm_logger = { version = "0.1.0", default-features = false }
|
||||
packing = { version = "0.2.0", path = "../packing/packing" }
|
||||
log = "0.4.17"
|
||||
|
||||
[features]
|
||||
trace-usb-control = []
|
||||
trace-all = [ "trace-usb-control" ]
|
||||
|
|
|
|||
|
|
@ -24,11 +24,5 @@ pub use interface_subclass::*;
|
|||
pub use interface_protocol::*;
|
||||
|
||||
mod logging {
|
||||
pub use itm_logger::*;
|
||||
|
||||
#[cfg(feature = "trace-usb-control")]
|
||||
pub use itm_logger::trace as trace_usb_control;
|
||||
#[cfg(not(feature = "trace-usb-control"))]
|
||||
//pub use itm_logger::stub as trace_usb_control;
|
||||
pub use log::info as trace_usb_control;
|
||||
pub use log::debug as trace_usb_control;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use usb_device::{
|
|||
use crate::{
|
||||
InterfaceSubclass,
|
||||
InterfaceProtocol,
|
||||
logging::*,
|
||||
};
|
||||
|
||||
/// This should be used as `device_class` when building `UsbDevice`
|
||||
|
|
@ -63,26 +64,6 @@ impl<B: UsbBus> MscClass<'_, B> {
|
|||
|
||||
impl<B: UsbBus> UsbClass<B> for MscClass<'_, B> {
|
||||
fn get_configuration_descriptors(&self, writer: &mut DescriptorWriter) -> Result<()> {
|
||||
// writer.interface(
|
||||
// self.msc_if,
|
||||
// USB_CLASS_MSC,
|
||||
// self.subclass.to_primitive(),
|
||||
// self.protocol.to_primitive(),
|
||||
// )?;
|
||||
|
||||
// trace_usb_control!("AYYYYYYYY: read ep addr: {:?} write ep addr: {:?}", self.read_ep.address(), self.write_ep.address());
|
||||
|
||||
// writer.endpoint(&self.read_ep)?;
|
||||
// writer.endpoint(&self.write_ep)
|
||||
|
||||
// writer.iad(
|
||||
// self.msc_if,
|
||||
// 1,
|
||||
// USB_CLASS_MSC,
|
||||
// self.subclass.to_primitive(),
|
||||
// self.protocol.to_primitive(),
|
||||
// )?;
|
||||
|
||||
writer.interface(self.msc_if,
|
||||
USB_CLASS_MSC,
|
||||
self.subclass.to_primitive(),
|
||||
|
|
@ -92,15 +73,6 @@ impl<B: UsbBus> UsbClass<B> for MscClass<'_, B> {
|
|||
writer.endpoint(&self.write_ep)?;
|
||||
writer.endpoint(&self.read_ep)?;
|
||||
writer.endpoint(&self.write2_ep)
|
||||
|
||||
//writer.write(0, &[])
|
||||
|
||||
// writer.interface(
|
||||
// self.fake_if,
|
||||
// 0xff,
|
||||
// 0,
|
||||
// 0
|
||||
// )
|
||||
}
|
||||
|
||||
fn reset(&mut self) { }
|
||||
|
|
@ -108,14 +80,14 @@ impl<B: UsbBus> UsbClass<B> for MscClass<'_, B> {
|
|||
fn control_in(&mut self, xfer: ControlIn<B>) {
|
||||
let req = xfer.request();
|
||||
if self.correct_interface_number(req.index) {
|
||||
//trace_usb_control!("USB_CONTROL> Unhandled control-IN: {:?}", req);
|
||||
trace_usb_control!("USB_CONTROL> Unhandled control-IN: {:?}", req);
|
||||
}
|
||||
}
|
||||
|
||||
fn control_out(&mut self, xfer: ControlOut<B>) {
|
||||
let req = xfer.request();
|
||||
if self.correct_interface_number(req.index) {
|
||||
//trace_usb_control!("USB_CONTRO> Unhandled control-OUT: {:?}", req);
|
||||
trace_usb_control!("USB_CONTRO> Unhandled control-OUT: {:?}", req);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@ usb-device = "0.2.4"
|
|||
embedded-hal = "0.2.3"
|
||||
nb = "0.1.2"
|
||||
typenum = "1.11.2"
|
||||
itm_logger = { version = "0.1.0", default-features = false }
|
||||
usbd_mass_storage = { version = "0.1.0", path = "../usbd_mass_storage" }
|
||||
packing = { version = "0.2.0", path = "../packing/packing" }
|
||||
usbd_bulk_only_transport = { version = "0.1.0", path = "../usbd_bulk_only_transport" }
|
||||
|
|
@ -27,14 +26,3 @@ xous = "0.9.29"
|
|||
ticktimer-server = { package = "xous-api-ticktimer", version = "0.9.23" }
|
||||
|
||||
[features]
|
||||
trace-bot-headers = [ "usbd_bulk_only_transport/trace-bot-headers" ]
|
||||
trace-bot-states = [ "usbd_bulk_only_transport/trace-bot-states" ]
|
||||
trace-bot-bytes = [ "usbd_bulk_only_transport/trace-bot-bytes" ]
|
||||
trace-bot-zlp = [ "usbd_bulk_only_transport/trace-bot-zlp" ]
|
||||
trace-bot-buffer = [ "usbd_bulk_only_transport/trace-bot-buffer" ]
|
||||
trace-usb-control = [ "usbd_bulk_only_transport/trace-usb-control" ]
|
||||
trace-scsi-command = []
|
||||
trace-scsi-fs = []
|
||||
trace-all = [ "trace-bot-headers", "trace-bot-states", "trace-bot-bytes",
|
||||
"trace-bot-zlp", "trace-bot-buffer", "trace-scsi-command",
|
||||
"trace-scsi-fs", "trace-usb-control" ]
|
||||
|
|
@ -7,20 +7,6 @@ mod block_device;
|
|||
pub use block_device::*;
|
||||
|
||||
mod logging {
|
||||
pub use itm_logger::*;
|
||||
|
||||
/*
|
||||
#[cfg(feature = "trace-scsi-command")]
|
||||
pub use itm_logger::trace as trace_scsi_command;
|
||||
#[cfg(not(feature = "trace-scsi-command"))]
|
||||
pub use itm_logger::stub as trace_scsi_command;
|
||||
|
||||
#[cfg(feature = "trace-scsi-fs")]
|
||||
pub use itm_logger::trace as trace_scsi_fs;
|
||||
#[cfg(not(feature = "trace-scsi-fs"))]
|
||||
pub use itm_logger::stub as trace_scsi_fs;
|
||||
*/
|
||||
|
||||
pub use log::debug as trace_scsi_fs;
|
||||
pub use log::debug as trace_scsi_command;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ use packing::{
|
|||
|
||||
use crate::scsi::{
|
||||
enums::{
|
||||
VersionDescriptor,
|
||||
TargetPortGroupSupport,
|
||||
SpcVersion,
|
||||
PeripheralQualifier,
|
||||
|
|
@ -116,7 +115,7 @@ pub struct InquiryResponse {
|
|||
#[pkd(7, 0, 32, 35)]
|
||||
product_revision_level: [u8; 4],
|
||||
|
||||
/*
|
||||
/* // these records cause the inquiry to fail, and are thus omitted
|
||||
#[pkd(7, 0, 36, 55)]
|
||||
_vendor_specific3: [u8; 20],
|
||||
|
||||
|
|
|
|||
|
|
@ -237,8 +237,7 @@ impl<B: UsbBus, BD: BlockDevice> Scsi<'_, B, BD> {
|
|||
};
|
||||
|
||||
while self.lba <= self.lba_end {
|
||||
// I think this "len" computation isn't right for our purposes..
|
||||
let buf = self.inner.take_buffered_data(len, true).expect("Buffer should have enough data");
|
||||
let buf = self.inner.take_buffered_data(len).expect("Buffer should have enough data");
|
||||
self.block_device.write_block(self.lba, buf)?;
|
||||
self.lba += 1;
|
||||
}
|
||||
|
|
@ -402,7 +401,7 @@ impl<B: UsbBus, BD: BlockDevice> Scsi<'_, B, BD> {
|
|||
),
|
||||
};
|
||||
|
||||
info!("SENSE: {:?}, ASC: {} {}", sense_key, additional_sense_code.asc(), additional_sense_code.ascq());
|
||||
log::info!("SENSE: {:?}, ASC: {} {}", sense_key, additional_sense_code.asc(), additional_sense_code.ascq());
|
||||
self.request_sense_response.sense_key = sense_key;
|
||||
self.request_sense_response.additional_sense_code = additional_sense_code;
|
||||
}
|
||||
|
|
@ -482,7 +481,7 @@ impl<B: UsbBus, BD: BlockDevice> UsbClass<B> for Scsi<'_, B, BD> {
|
|||
|
||||
fn poll(&mut self) {
|
||||
if let Err(e) = self.update() {
|
||||
error!("Error from Scsi::update: {:?}", e);
|
||||
log::error!("Error from Scsi::update: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -649,7 +649,10 @@ pub(crate) fn main_hw() -> ! {
|
|||
Some(Opcode::SendString) => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut usb_send = buffer.to_original::<api::UsbString, _>().unwrap();
|
||||
#[cfg(not(feature="minimal"))]
|
||||
let mut sent = 0;
|
||||
#[cfg(feature="minimal")]
|
||||
let sent = 0;
|
||||
match view {
|
||||
#[cfg(not(feature="minimal"))]
|
||||
Views::FidoWithKbd => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue