@@ -872,57 +872,59 @@ impl Inner {
872
872
// unconnected & unsuspended, we do not handle them to avoid spurious
873
873
// transitions.
874
874
875
- let intbits = self . usb ( ) . epintsmry . read ( ) . bits ( ) ;
876
- if intbits == 0 {
877
- return PollResult :: None ;
878
- }
879
-
880
875
let mut ep_out = 0 ;
881
876
let mut ep_in_complete = 0 ;
882
877
let mut ep_setup = 0 ;
883
878
884
879
for ep in 0 ..8u16 {
885
880
let mask = 1 << ep;
886
- if ( intbits & mask) == 0 {
887
- continue ;
888
- }
889
881
890
882
let idx = ep as usize ;
891
883
892
- let bank1 = self
893
- . bank1 ( EndpointAddress :: from_parts ( idx, UsbDirection :: In ) )
894
- . unwrap ( ) ;
895
- if bank1. is_transfer_complete ( ) {
896
- bank1. clear_transfer_complete ( ) ;
897
- dbgprint ! ( "ep {} WRITE DONE\n " , ep) ;
898
- ep_in_complete |= mask;
899
- // Continuing (and hence not setting masks to indicate complete
900
- // OUT transfers) is necessary for operation to proceed beyond
901
- // the device-address + descriptor stage. The authors suspect a
902
- // deadlock caused by waiting on a write when handling a read
903
- // somewhere in an underlying class or control crate, but we
904
- // can't be sure. Either way, if a write has finished, we only
905
- // set the flag for a completed write on that endpoint index.
906
- // Future polls will handle the reads.
907
- continue ;
908
- }
909
- drop ( bank1) ;
910
-
911
- let bank0 = self
912
- . bank0 ( EndpointAddress :: from_parts ( idx, UsbDirection :: Out ) )
913
- . unwrap ( ) ;
914
- if bank0. received_setup_interrupt ( ) {
915
- dbgprint ! ( "ep {} GOT SETUP\n " , ep) ;
916
- ep_setup |= mask;
917
- // usb-device crate:
918
- // "This event should continue to be reported until the packet
919
- // is read." So we don't clear the flag here,
920
- // instead it is cleared in the read handler.
884
+ if let Ok ( bank1) = self . bank1 ( EndpointAddress :: from_parts ( idx, UsbDirection :: In ) ) {
885
+ if bank1. is_transfer_complete ( ) {
886
+ bank1. clear_transfer_complete ( ) ;
887
+ dbgprint ! ( "ep {} WRITE DONE\n " , ep) ;
888
+ ep_in_complete |= mask;
889
+ // Continuing (and hence not setting masks to indicate complete
890
+ // OUT transfers) is necessary for operation to proceed beyond
891
+ // the device-address + descriptor stage. The authors suspect a
892
+ // deadlock caused by waiting on a write when handling a read
893
+ // somewhere in an underlying class or control crate, but we
894
+ // can't be sure. Either way, if a write has finished, we only
895
+ // set the flag for a completed write on that endpoint index.
896
+ // Future polls will handle the reads.
897
+ continue ;
898
+ }
921
899
}
922
900
923
- if bank0. is_transfer_complete ( ) {
924
- dbgprint ! ( "ep {} READABLE\n " , ep) ;
925
- ep_out |= mask;
901
+ if let Ok ( bank0) = self . bank0 ( EndpointAddress :: from_parts ( idx, UsbDirection :: Out ) ) {
902
+ if bank0. received_setup_interrupt ( ) {
903
+ dbgprint ! ( "ep {} GOT SETUP\n " , ep) ;
904
+ ep_setup |= mask;
905
+ // usb-device crate:
906
+ // "This event should continue to be reported until the packet
907
+ // is read." So we don't clear the flag here,
908
+ // instead it is cleared in the read handler.
909
+ }
910
+
911
+ // Clear the transfer complete and transfer failed interrupt flags
912
+ // so that execution leaves the USB interrupt until the host makes
913
+ // another transaction. The transfer failed flag may have been set
914
+ // if an OUT transaction wasn't read() from the endpoint by the
915
+ // Class; the hardware will have NAKed (unless the endpoint is
916
+ // isochronous) and the host may retry.
917
+ bank0. clear_transfer_complete ( ) ;
918
+
919
+ // Use the bk0rdy flag via is_ready() to indicate that data has been
920
+ // received successfully, rather than the interrupting trcpt0 via
921
+ // is_transfer_ready(), because data may have been received on an
922
+ // earlier poll() which cleared trcpt0. bk0rdy is cleared in the
923
+ // endpoint read().
924
+ if bank0. is_ready ( ) {
925
+ dbgprint ! ( "ep {} READABLE\n " , ep) ;
926
+ ep_out |= mask;
927
+ }
926
928
}
927
929
}
928
930
@@ -976,8 +978,6 @@ impl Inner {
976
978
}
977
979
978
980
// self.print_epstatus(idx, "read");
979
-
980
- bank. clear_transfer_complete ( ) ;
981
981
bank. set_ready ( false ) ;
982
982
983
983
drop ( bank) ;
0 commit comments