diff --git a/drivers/src/device.rs b/drivers/src/device.rs index 4ad60fb..864efd5 100644 --- a/drivers/src/device.rs +++ b/drivers/src/device.rs @@ -43,6 +43,8 @@ pub trait Usb: Sized { fn next_with_timeout(&self, timeout: &std::time::Duration) -> Option; + fn backlog(&self) -> usize; + fn serial(&self) -> String; fn chip_firmware_configuration(&self) -> Self::Configuration; diff --git a/drivers/src/devices.rs b/drivers/src/devices.rs index 6988d4d..9939aff 100644 --- a/drivers/src/devices.rs +++ b/drivers/src/devices.rs @@ -190,6 +190,14 @@ macro_rules! register { } } + pub fn backlog(&self) -> usize { + match self { + $( + Self::[<$module:camel>](device) => device.backlog(), + )+ + } + } + pub fn properties(&self) -> Properties { match self { $( diff --git a/drivers/src/devices/prophesee_evk3_hd.rs b/drivers/src/devices/prophesee_evk3_hd.rs index 731ce86..8f59d89 100644 --- a/drivers/src/devices/prophesee_evk3_hd.rs +++ b/drivers/src/devices/prophesee_evk3_hd.rs @@ -374,6 +374,10 @@ impl device::Usb for Device { self.ring.next_with_timeout(timeout) } + fn backlog(&self) -> usize { + self.ring.backlog() + } + fn serial(&self) -> String { self.serial.clone() } diff --git a/drivers/src/devices/prophesee_evk4.rs b/drivers/src/devices/prophesee_evk4.rs index d544a7c..a2b6f55 100644 --- a/drivers/src/devices/prophesee_evk4.rs +++ b/drivers/src/devices/prophesee_evk4.rs @@ -837,6 +837,10 @@ impl device::Usb for Device { self.ring.next_with_timeout(timeout) } + fn backlog(&self) -> usize { + self.ring.backlog() + } + fn serial(&self) -> String { self.serial.clone() } diff --git a/drivers/src/usb.rs b/drivers/src/usb.rs index aaf0a27..57471dd 100644 --- a/drivers/src/usb.rs +++ b/drivers/src/usb.rs @@ -271,7 +271,7 @@ extern "system" fn usb_transfer_callback(transfer_pointer: *mut libusb1_sys::lib .ring .shared .lock() - .expect("ring context's lock is poisonned"); + .expect("ring context's lock is not poisoned"); match shared.transfer_statuses[context.transfer_index] { TransferStatus::Active => match transfer.status { libusb1_sys::constants::LIBUSB_TRANSFER_COMPLETED @@ -495,7 +495,7 @@ impl Ring { let shared = context .shared .lock() - .expect("ring context's lock is poisonned"); + .expect("ring context's lock is not poisoned"); for index in 0..configuration.transfer_queue_size { // unsafe: libusb1_sys wrapper let mut transfer = match std::ptr::NonNull::new(unsafe { @@ -623,7 +623,7 @@ impl Ring { .context .shared .lock() - .expect("ring context's lock is poisonned"); + .expect("ring context's lock is not poisoned"); for rest_index in index..result.transfers.len() { // dropping 'result' cancels transfers // mark unscheduled transfers as complete to prevent un-needed cancelling @@ -686,6 +686,15 @@ impl Drop for BufferView<'_> { } impl Ring { + pub fn backlog(&self) -> usize { + let shared = self + .context + .shared + .lock() + .expect("ring context's lock is not poisoned"); + (shared.write_range.0 + shared.buffers.len() - 1 - shared.read) % shared.buffers.len() + } + pub fn next_with_timeout(&self, duration: &std::time::Duration) -> Option { if self .active_buffer_view @@ -699,7 +708,7 @@ impl Ring { .context .shared .lock() - .expect("ring context's lock is poisonned"); + .expect("ring context's lock is not poisoned"); loop { shared.read = (shared.read + 1) % shared.buffers.len(); while (shared.write_range.1 + shared.buffers.len() - 1 - shared.read) @@ -759,7 +768,7 @@ impl Drop for Ring { .context .shared .lock() - .expect("ring context's lock is poisonned"); + .expect("ring context's lock is not poisoned"); // unsafe: transfer is allocated let _ = unsafe { libusb1_sys::libusb_cancel_transfer(self.transfers[0].as_ptr()) }; for index in 0..self.transfers.len() { @@ -773,7 +782,7 @@ impl Drop for Ring { .context .shared .lock() - .expect("ring context's lock is poisonned"); + .expect("ring context's lock is not poisoned"); for index in 0..self.transfers.len() { match shared.transfer_statuses[index] { TransferStatus::Active => { @@ -825,7 +834,7 @@ impl Drop for Ring { .context .shared .lock() - .expect("ring context's lock is poisonned"); + .expect("ring context's lock is not poisoned"); for buffer in shared.buffers.iter() { if buffer.dma { // unsafe: buffer was allocated by libusb with 'capacity' bytes