From d93fdcd424c049078009119940d0042bb229ed38 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 27 Dec 2015 11:12:09 +0000 Subject: Fixed stability problems in OTGv1. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8651 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'os/hal/src/usb.c') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index 2075cd7a2..b6813c381 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -380,6 +380,19 @@ void usbDisableEndpointsI(USBDriver *usbp) { usbp->transmitting &= ~1U; usbp->receiving &= ~1U; for (i = 1; i <= (unsigned)USB_MAX_ENDPOINTS; i++) { +#if USB_USE_WAIT == TRUE + /* Signaling the event to threads waiting on endpoints.*/ + if (usbp->epc[i] != NULL) { + osalSysLockFromISR(); + if (usbp->epc[i]->in_state != NULL) { + osalThreadResumeI(&usbp->epc[i]->in_state->thread, MSG_RESET); + } + if (usbp->epc[i]->out_state != NULL) { + osalThreadResumeI(&usbp->epc[i]->out_state->thread, MSG_RESET); + } + osalSysUnlockFromISR(); + } +#endif usbp->epc[i] = NULL; } @@ -638,12 +651,14 @@ void _usb_reset(USBDriver *usbp) { #if USB_USE_WAIT == TRUE /* Signaling the event to threads waiting on endpoints.*/ if (usbp->epc[i] != NULL) { + osalSysLockFromISR(); if (usbp->epc[i]->in_state != NULL) { osalThreadResumeI(&usbp->epc[i]->in_state->thread, MSG_RESET); } if (usbp->epc[i]->out_state != NULL) { osalThreadResumeI(&usbp->epc[i]->out_state->thread, MSG_RESET); } + osalSysUnlockFromISR(); } #endif usbp->epc[i] = NULL; @@ -671,7 +686,7 @@ void _usb_reset(USBDriver *usbp) { void _usb_suspend(USBDriver *usbp) { /* State transition.*/ - usbp->state = USB_SUSPENDED; + usbp->state = USB_SUSPENDED; /* Notification of suspend event.*/ _usb_isr_invoke_event_cb(usbp, USB_EVENT_SUSPEND); @@ -683,12 +698,14 @@ void _usb_suspend(USBDriver *usbp) { for (i = 0; i <= (unsigned)USB_MAX_ENDPOINTS; i++) { if (usbp->epc[i] != NULL) { + osalSysLockFromISR(); if (usbp->epc[i]->in_state != NULL) { osalThreadResumeI(&usbp->epc[i]->in_state->thread, MSG_TIMEOUT); } if (usbp->epc[i]->out_state != NULL) { osalThreadResumeI(&usbp->epc[i]->out_state->thread, MSG_TIMEOUT); } + osalSysUnlockFromISR(); } } } -- cgit v1.2.3