Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nrf52: usb: better check state on IN resume #1947

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions chips/nrf52/src/usbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,15 +1919,29 @@ impl<'a> hil::usb::UsbController<'a> for Usbd<'a> {
fn endpoint_resume_in(&self, endpoint: usize) {
debug_events!("endpoint_resume_in({})", endpoint);

// Get the state of the endpoint that the upper layer requested to start
// an IN transfer with for our state machine.
let (_, in_state, _) = self.descriptors[endpoint].state.get().bulk_state();
// If the state is `None`, this endpoint is not configured and should
// not have been used to call `endpoint_resume_in()`.
assert!(in_state.is_some());

if self.dma_pending.get() {
// If there is an active DMA request, or we are waiting on finishing up
// a previous IN transfer, we queue this request and it will be serviced
// after those complete.
if self.dma_pending.get() || in_state != Some(BulkInState::Init) {
debug_events!("requesting resume_in[{}]", endpoint);
// A DMA is already pending. Schedule the resume for later.
self.descriptors[endpoint].request_transmit_in.set(true);
} else {
// Trigger the transaction now.
// If we aren't waiting on anything, trigger the transaction now.
//
// NOTE! TODO! We can't actually do this. This leads to an upcall
// (`client.packet_in()`) happening as a direct result of a downcall
// (this `endpoint_resume_in()` call). Unfortunately, the nRF52
// doesn't give us a great interrupt to use to check the
// `request_transmit_in` flag if we were to queue unconditionally in
// `endpoint_resume_in()`.
self.transmit_in(endpoint);
}
}
Expand Down