Get soft reboot working
Change-Id: I7b2707fef62ae7b3878ca3d6ed6991bea41d7d6e
diff --git a/motors/usb/usb.cc b/motors/usb/usb.cc
index 3067695..0a05fad 100644
--- a/motors/usb/usb.cc
+++ b/motors/usb/usb.cc
@@ -250,6 +250,7 @@
// If we just finished processing a token.
if (status & USB_ISTAT_TOKDNE) {
const uint8_t stat = USB0_STAT;
+ USB0_ISTAT = USB_ISTAT_TOKDNE;
const int endpoint = G_USB_STAT_ENDP(stat);
if (endpoint == 0) {
@@ -281,8 +282,6 @@
}
}
}
-
- USB0_ISTAT = USB_ISTAT_TOKDNE;
}
if (status & USB_ISTAT_USBRST) {
@@ -355,14 +354,16 @@
dma_memory_barrier();
// Next IN and OUT packet for this endpoint (data stage/status stage)
// should both be DATA1.
- // TODO(Brian): Does this actually deal with received toggles correctly?
- bdt_entry->buffer_descriptor =
- M_USB_BD_OWN | M_USB_BD_DTS | V_USB_BD_BC(kEndpoint0MaxSize);
MutableBdtEntryFromStat(stat ^ M_USB_STAT_ODD)->buffer_descriptor =
M_USB_BD_OWN | M_USB_BD_DTS | V_USB_BD_BC(kEndpoint0MaxSize) |
M_USB_BD_DATA1;
endpoint0_tx_toggle_ = Data01::kData1;
+ // Give this buffer back. It should be DATA0 because it'll be the second
+ // received packet.
+ bdt_entry->buffer_descriptor =
+ M_USB_BD_OWN | M_USB_BD_DTS | V_USB_BD_BC(kEndpoint0MaxSize);
+
// TODO(Brian): Tell the functions a new setup packet is starting.
// CdcTty: next_endpoint0_out_ = NextEndpoint0Out::kNone;