mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
block reads work.
This commit is contained in:
parent
3d826ffbbe
commit
5c1518cee6
4 changed files with 45 additions and 44 deletions
|
|
@ -37,6 +37,6 @@ impl usbd_scsi::BlockDevice for BlockDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn max_lba(&self) -> u32 {
|
fn max_lba(&self) -> u32 {
|
||||||
512
|
511
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -200,6 +200,8 @@ pub struct SpinalUsbDevice {
|
||||||
address: AtomicUsize,
|
address: AtomicUsize,
|
||||||
// bit vector to track if a read is allowed. This prevents a race condition between polled reads and interrupted reads.
|
// bit vector to track if a read is allowed. This prevents a race condition between polled reads and interrupted reads.
|
||||||
read_allowed: AtomicU16,
|
read_allowed: AtomicU16,
|
||||||
|
// last descriptor in chain. Used to check if a transaction is in progress.
|
||||||
|
last_descriptor: Arc::<Mutex<[Option<SpinalUdcDescriptor>; 16]>>,
|
||||||
}
|
}
|
||||||
impl SpinalUsbDevice {
|
impl SpinalUsbDevice {
|
||||||
pub fn new(sid: xous::SID) -> SpinalUsbDevice {
|
pub fn new(sid: xous::SID) -> SpinalUsbDevice {
|
||||||
|
|
@ -235,6 +237,7 @@ impl SpinalUsbDevice {
|
||||||
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
||||||
address: AtomicUsize::new(0),
|
address: AtomicUsize::new(0),
|
||||||
read_allowed: AtomicU16::new(0),
|
read_allowed: AtomicU16::new(0),
|
||||||
|
last_descriptor: Arc::new(Mutex::new([None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,])),
|
||||||
};
|
};
|
||||||
|
|
||||||
xous::claim_interrupt(
|
xous::claim_interrupt(
|
||||||
|
|
@ -269,6 +272,7 @@ impl SpinalUsbDevice {
|
||||||
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
||||||
address: AtomicUsize::new(0),
|
address: AtomicUsize::new(0),
|
||||||
read_allowed: AtomicU16::new(0),
|
read_allowed: AtomicU16::new(0),
|
||||||
|
last_descriptor: Arc::new(Mutex::new([None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None,])),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_iface(&self) -> SpinalUsbMgmt {
|
pub fn get_iface(&self) -> SpinalUsbMgmt {
|
||||||
|
|
@ -678,41 +682,30 @@ impl UsbBus for SpinalUsbDevice {
|
||||||
let mut ep_status = self.status_read_volatile(ep_addr.index());
|
let mut ep_status = self.status_read_volatile(ep_addr.index());
|
||||||
|
|
||||||
if ep_addr.index() != 0 {
|
if ep_addr.index() != 0 {
|
||||||
let now = self.tt.elapsed_ms();
|
if let Some(final_descriptor) = &self.last_descriptor.lock().unwrap()[ep_addr.index()] {
|
||||||
let mut last_print = 10;
|
let now = self.tt.elapsed_ms();
|
||||||
while (self.tt.elapsed_ms() - now < WRITE_TIMEOUT_MS)
|
log::info!("checking final descriptor {:x?}", final_descriptor);
|
||||||
&& ep_status.head_offset() != 0 {
|
let mut last_print = 10;
|
||||||
xous::yield_slice();
|
while (self.tt.elapsed_ms() - now < WRITE_TIMEOUT_MS)
|
||||||
let secs = (self.tt.elapsed_ms() - now) / 1_000;
|
&& final_descriptor.in_progress() {
|
||||||
if secs != last_print {
|
xous::yield_slice();
|
||||||
log::info!("write wait!");
|
let secs = (self.tt.elapsed_ms() - now) / 1_000;
|
||||||
last_print = secs;
|
if secs != last_print {
|
||||||
|
log::info!("write wait!");
|
||||||
|
last_print = secs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ep_status = self.status_read_volatile(ep_addr.index());
|
// TODO: report WouldBlock timeout
|
||||||
}
|
|
||||||
if ep_status.head_offset() != 0 {
|
|
||||||
log::warn!("head offset is not 0 even after waiting");
|
|
||||||
return Err(UsbError::WouldBlock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is reset to 0 after every transaction by the hardware, so we must reset it
|
// this is reset to 0 after every transaction by the hardware, so we must reset it
|
||||||
ep_status.set_head_offset(head_offset as u32);
|
ep_status.set_head_offset(head_offset as u32);
|
||||||
|
|
||||||
let descriptor = self.descriptor_from_status(&ep_status);
|
let descriptor = self.descriptor_from_status(&ep_status);
|
||||||
/*if descriptor.in_progress() && ep_addr.index() != 0 {
|
/*if descriptor.in_progress() && ep_addr.index() != 0 {
|
||||||
log::warn!("WouldBlock {:?}", ep_addr);
|
log::warn!("WouldBlock {:?}", ep_addr);
|
||||||
return Err(UsbError::WouldBlock);
|
return Err(UsbError::WouldBlock);
|
||||||
}*/
|
}*/
|
||||||
if descriptor.in_progress() && ep_addr.index() != 0 {
|
|
||||||
// refresh the ep_status after waiting
|
|
||||||
ep_status = self.status_read_volatile(ep_addr.index());
|
|
||||||
ep_status.set_head_offset(head_offset as u32);
|
|
||||||
// note that the *descriptor* doesn't need to be updated because it refers directly to a memory location
|
|
||||||
if descriptor.in_progress() {
|
|
||||||
log::warn!("in progress despite waiting on write");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ep_addr.index() != 0 {
|
if ep_addr.index() != 0 {
|
||||||
descriptor.set_desc_flags(UsbDirection::In,
|
descriptor.set_desc_flags(UsbDirection::In,
|
||||||
false, false, false);
|
false, false, false);
|
||||||
|
|
@ -739,6 +732,7 @@ impl UsbBus for SpinalUsbDevice {
|
||||||
false, true, false);
|
false, true, false);
|
||||||
}
|
}
|
||||||
descriptor.set_offset(0); // reset the write pointer to 0, also sets in_progress
|
descriptor.set_offset(0); // reset the write pointer to 0, also sets in_progress
|
||||||
|
self.last_descriptor.lock().unwrap()[ep_addr.index()] = Some(descriptor);
|
||||||
//if ep_addr.index() != 0 {
|
//if ep_addr.index() != 0 {
|
||||||
// log::info!("WR PREdesc{}: {:?}", ep_addr.index(), descriptor);
|
// log::info!("WR PREdesc{}: {:?}", ep_addr.index(), descriptor);
|
||||||
//}
|
//}
|
||||||
|
|
@ -766,19 +760,21 @@ impl UsbBus for SpinalUsbDevice {
|
||||||
//}
|
//}
|
||||||
Ok(buf.len())
|
Ok(buf.len())
|
||||||
} else {
|
} else {
|
||||||
|
if let Some(final_descriptor) = &self.last_descriptor.lock().unwrap()[ep_addr.index()] {
|
||||||
|
log::info!("ll checking final descriptor {:x?}", final_descriptor);
|
||||||
|
let now = self.tt.elapsed_ms();
|
||||||
|
let mut last_secs = 5;
|
||||||
|
while final_descriptor.in_progress() && (self.tt.elapsed_ms() - now < WRITE_TIMEOUT_MS) {
|
||||||
|
xous::yield_slice();
|
||||||
|
let secs = (self.tt.elapsed_ms() - now) / 1_0000;
|
||||||
|
if last_secs != secs {
|
||||||
|
log::info!("waiting for linked list to complete...");
|
||||||
|
last_secs = secs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
let mut ep_status = self.status_read_volatile(ep_addr.index());
|
let mut ep_status = self.status_read_volatile(ep_addr.index());
|
||||||
|
|
||||||
let now = self.tt.elapsed_ms();
|
|
||||||
while (self.tt.elapsed_ms() - now < WRITE_TIMEOUT_MS)
|
|
||||||
&& ep_status.head_offset() != 0 {
|
|
||||||
xous::yield_slice();
|
|
||||||
ep_status = self.status_read_volatile(ep_addr.index());
|
|
||||||
}
|
|
||||||
if ep_status.head_offset() != 0 {
|
|
||||||
log::warn!("head offset is not 0 even after waiting");
|
|
||||||
return Err(UsbError::WouldBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (chain_offset, sub_buf) in buf.chunks(packet_len).enumerate() {
|
for (chain_offset, sub_buf) in buf.chunks(packet_len).enumerate() {
|
||||||
let descriptor = self.descriptor_from_head_and_chain(head_offset, chain_offset, packet_len);
|
let descriptor = self.descriptor_from_head_and_chain(head_offset, chain_offset, packet_len);
|
||||||
descriptor.set_desc_flags(UsbDirection::In,
|
descriptor.set_desc_flags(UsbDirection::In,
|
||||||
|
|
@ -807,6 +803,7 @@ impl UsbBus for SpinalUsbDevice {
|
||||||
}
|
}
|
||||||
descriptor.set_offset(0); // reset the write pointer to 0, also sets in_progress
|
descriptor.set_offset(0); // reset the write pointer to 0, also sets in_progress
|
||||||
log::info!("bulk descriptor {} setup: {:x?}", chain_offset, descriptor);
|
log::info!("bulk descriptor {} setup: {:x?}", chain_offset, descriptor);
|
||||||
|
self.last_descriptor.lock().unwrap()[ep_addr.index()] = Some(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
ep_status.set_max_packet_size(packet_len as _);
|
ep_status.set_max_packet_size(packet_len as _);
|
||||||
|
|
|
||||||
|
|
@ -382,7 +382,7 @@ impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
||||||
Ok(&self.buffer[s..e])
|
Ok(&self.buffer[s..e])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&mut self) -> Result<(), Error> {
|
pub fn flush(&mut self) -> Result<(), Error> {
|
||||||
// let packet_size = self.max_packet_size() as usize;
|
// let packet_size = self.max_packet_size() as usize;
|
||||||
let packet_size = 512; // TODO: link this to the buffer length constant if it the lower-level rework works
|
let packet_size = 512; // TODO: link this to the buffer length constant if it the lower-level rework works
|
||||||
let residue = self.command_status_wrapper.data_residue as usize;
|
let residue = self.command_status_wrapper.data_residue as usize;
|
||||||
|
|
@ -461,9 +461,12 @@ impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
||||||
|
|
||||||
fn end_data_transfer(&mut self) -> Result<(), Error> {
|
fn end_data_transfer(&mut self) -> Result<(), Error> {
|
||||||
// Get the csw ready to send
|
// Get the csw ready to send
|
||||||
log::debug!("data_i: {}, buffer_i: {}, buf: {:x?}", self.data_i, self.buffer_i, self.buffer);
|
//log::debug!("data_i: {}, buffer_i: {}, buf: {:x?}", self.data_i, self.buffer_i, self.buffer);
|
||||||
self.pack_csw();
|
self.pack_csw();
|
||||||
log::debug!("data_i: {}, buffer_i: {}, buf: {:x?}", self.data_i, self.buffer_i, self.buffer);
|
log::info!("data_residue: {}", self.command_status_wrapper.data_residue);
|
||||||
|
self.flush()?;
|
||||||
|
//log::debug!("data_i: {}, buffer_i: {}, buf: {:x?}", self.data_i, self.buffer_i, self.buffer);
|
||||||
|
log::info!("data_residue: {}", self.command_status_wrapper.data_residue);
|
||||||
|
|
||||||
// We only send a zero length packet if the last write was a full packet AND we are sending
|
// We only send a zero length packet if the last write was a full packet AND we are sending
|
||||||
// less total bytes than the command header asked for
|
// less total bytes than the command header asked for
|
||||||
|
|
@ -477,9 +480,7 @@ impl<B: UsbBus> BulkOnlyTransport<'_, B> {
|
||||||
if needs_zlp {
|
if needs_zlp {
|
||||||
trace_bot_zlp!("ZLP> required");
|
trace_bot_zlp!("ZLP> required");
|
||||||
self.change_state(State::NeedZlp);
|
self.change_state(State::NeedZlp);
|
||||||
self.flush()?;
|
|
||||||
self.send_zlp()?;
|
self.send_zlp()?;
|
||||||
self.flush()?;
|
|
||||||
} else {
|
} else {
|
||||||
trace_bot_zlp!("ZLP> not required");
|
trace_bot_zlp!("ZLP> not required");
|
||||||
self.change_state(State::NeedToSendStatus);
|
self.change_state(State::NeedToSendStatus);
|
||||||
|
|
|
||||||
|
|
@ -199,9 +199,12 @@ impl<B: UsbBus, BD: BlockDevice> Scsi<'_, B, BD> {
|
||||||
new_command, self.lba, self.lba_end, self.lba == self.lba_end);
|
new_command, self.lba, self.lba_end, self.lba == self.lba_end);
|
||||||
|
|
||||||
// We only get here if the buffer is empty
|
// We only get here if the buffer is empty
|
||||||
let buf = self.inner.take_buffer_space(BD::BLOCK_BYTES)?;
|
while self.lba <= self.lba_end {
|
||||||
self.block_device.read_block(self.lba, buf)?;
|
let buf = self.inner.take_buffer_space(BD::BLOCK_BYTES)?;
|
||||||
self.lba += 1;
|
self.block_device.read_block(self.lba, buf)?;
|
||||||
|
self.inner.flush()?;
|
||||||
|
self.lba += 1;
|
||||||
|
}
|
||||||
|
|
||||||
if self.lba <= self.lba_end {
|
if self.lba <= self.lba_end {
|
||||||
Ongoing
|
Ongoing
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue