chip/stm32/usb: Split usb wake handler as a different function
Indentation is growing out of control, let's move to a separate
function so that we can return early.
BRANCH=none
TEST=Flash hammer, usb_wake works.
@@ -422,33 +422,28 @@ int usb_is_suspended(void)
}
#endif /* CONFIG_USB_SUSPEND */
-void usb_interrupt(void)
-{
- uint16_t status = STM32_USB_ISTR;
-
- if (status & STM32_USB_ISTR_RESET)
- usb_reset();
-
-#ifdef CONFIG_USB_SUSPEND
-#ifdef CONFIG_USB_REMOTE_WAKEUP
+#if defined(CONFIG_USB_SUSPEND) && defined(CONFIG_USB_REMOTE_WAKEUP)
/*
- * usb_wake is asking us to count esof_count ESOF interrupts (one
- * per millisecond), then disable RESUME, then wait for resume to
- * complete.
+ * Called by usb_interrupt when usb_wake is asking us to count esof_count ESOF
+ * interrupts (one per millisecond), then disable RESUME, then wait for resume
+ * to complete.
*/
- if (status & (STM32_USB_ISTR_ESOF | STM32_USB_ISTR_SOF) &&
- !usb_wake_done) {
+static void usb_interrupt_handle_wake(uint16_t status)
+{
+ int state;
+ int good;
+
esof_count--;
+ /* Keep counting. */
+ if (esof_count > 0)
+ return;
+
/* Clear RESUME bit. */
if (esof_count == 0)
STM32_USB_CNTR &= ~STM32_USB_CNTR_RESUME;
/* Then count down until state is resumed. */
- if (esof_count <= 0) {
- int state;
- int good;
-
state = (STM32_USB_FNR & STM32_USB_FNR_RXDP_RXDM_MASK)
>> STM32_USB_FNR_RXDP_RXDM_SHIFT;
@@ -459,22 +454,33 @@ void usb_interrupt(void)
good = (status & STM32_USB_ISTR_SOF) || (state == 2);
/* Either: state is ready, or we timed out. */
- if (good || state == 3 ||
- esof_count <= -USB_RESUME_TIMEOUT_MS) {
- STM32_USB_CNTR &= ~(STM32_USB_CNTR_ESOFM |
- STM32_USB_CNTR_SOFM);
+ if (good || state == 3 || esof_count <= -USB_RESUME_TIMEOUT_MS) {
+ STM32_USB_CNTR &= ~(STM32_USB_CNTR_ESOFM | STM32_USB_CNTR_SOFM);
usb_wake_done = 1;
if (!good) {
CPRINTF("wake error: cnt=%d state=%d\n",
esof_count, state);
usb_suspend();
- } else {
- CPRINTF("RSMOK%d %d\n",
- -esof_count, state);
- }
+ return;
}
+
+ CPRINTF("RSMOK%d %d\n", -esof_count, state);
}
}
+#endif /* CONFIG_USB_SUSPEND && CONFIG_USB_REMOTE_WAKEUP */
+
+void usb_interrupt(void)
+{
+ uint16_t status = STM32_USB_ISTR;
+
+ if (status & STM32_USB_ISTR_RESET)
+ usb_reset();
+
+#ifdef CONFIG_USB_SUSPEND
+#ifdef CONFIG_USB_REMOTE_WAKEUP
+ if (status & (STM32_USB_ISTR_ESOF | STM32_USB_ISTR_SOF) &&
+ !usb_wake_done)
+ usb_interrupt_handle_wake(status);
#endif
if (status & STM32_USB_ISTR_SUSP)
