From aa7557a5f206124dc232343be2010f7d9b82e267 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 8 Sep 2015 10:43:31 +0000 Subject: USB suspend mode. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8286 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/usb.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'os/hal/src') diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c index c563d5fea..c4f612d0f 100644 --- a/os/hal/src/usb.c +++ b/os/hal/src/usb.c @@ -314,7 +314,8 @@ void usbStop(USBDriver *usbp) { osalSysLock(); osalDbgAssert((usbp->state == USB_STOP) || (usbp->state == USB_READY) || - (usbp->state == USB_SELECTED) || (usbp->state == USB_ACTIVE), + (usbp->state == USB_SELECTED) || (usbp->state == USB_ACTIVE) || + (usbp->state == USB_SUSPENDED), "invalid state"); usb_lld_stop(usbp); usbp->state = USB_STOP; @@ -607,7 +608,10 @@ bool usbStallTransmitI(USBDriver *usbp, usbep_t ep) { void _usb_reset(USBDriver *usbp) { unsigned i; + /* State transition.*/ usbp->state = USB_READY; + + /* Resetting internal state.*/ usbp->status = 0; usbp->address = 0; usbp->configuration = 0; @@ -624,6 +628,45 @@ void _usb_reset(USBDriver *usbp) { /* Low level reset.*/ usb_lld_reset(usbp); + + /* Notification of reset event.*/ + _usb_isr_invoke_event_cb(usbp, USB_EVENT_RESET); +} + +/** + * @brief USB suspend routine. + * @details This function must be invoked when an USB bus suspend condition is + * detected. + * + * @param[in] usbp pointer to the @p USBDriver object + * + * @notapi + */ +void _usb_suspend(USBDriver *usbp) { + + /* State transition.*/ + usbp->state = USB_SUSPENDED; + + /* Notification of suspend event.*/ + _usb_isr_invoke_event_cb(usbp, USB_EVENT_SUSPEND); +} + +/** + * @brief USB wake-up routine. + * @details This function must be invoked when an USB bus wake-up condition is + * detected. + * + * @param[in] usbp pointer to the @p USBDriver object + * + * @notapi + */ +void _usb_wakeup(USBDriver *usbp) { + + /* State transition.*/ + usbp->state = USB_ACTIVE; + + /* Notification of suspend event.*/ + _usb_isr_invoke_event_cb(usbp, USB_EVENT_WAKEUP); } /** -- cgit v1.2.3