From f620f29e0a803ed942134ac8a801d5204cebe034 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 13 Jun 2012 16:13:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4273 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/serial_usb.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'os/hal/src') diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 52be6e975..2b02ae02f 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -120,6 +120,11 @@ static void inotify(GenericQueue *qp) { size_t n, maxsize; SerialUSBDriver *sdup = chQGetLink(qp); + /* If the USB driver is not in the appropriate state then transactions + must not be started.*/ + if (usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) + return; + /* If there is in the queue enough space to hold at least one packet and a transaction is not yet started then a new transaction is started for the available space.*/ @@ -145,6 +150,11 @@ static void onotify(GenericQueue *qp) { size_t n; SerialUSBDriver *sdup = chQGetLink(qp); + /* If the USB driver is not in the appropriate state then transactions + must not be started.*/ + if (usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) + return; + /* If there is not an ongoing transaction and the output queue contains data then a new transaction is started.*/ if (!usbGetTransmitStatusI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP) && @@ -238,6 +248,22 @@ void sduStop(SerialUSBDriver *sdup) { usbStop(sdup->config->usbp); } +/** + * @brief USB device configured handler. + * + * @param[in] usbp pointer to the @p USBDriver object + * + * @iclass + */ +void sduConfigureHookI(USBDriver *usbp) { + SerialUSBDriver *sdup = usbp->param; + + sdup->flags = CHN_NO_ERROR; + chIQResetI(&sdup->iqueue); + chOQResetI(&sdup->oqueue); + chnAddFlagsI(sdup, CHN_CONNECTED); +} + /** * @brief Default requests hook. * @details Applications wanting to use the Serial over USB driver can use -- cgit v1.2.3