usb_suspend.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /***********************************************************************************
  2. Filename: usb_suspend.h
  3. Description: Handle the USB suspend state.
  4. ***********************************************************************************/
  5. #ifndef USBSUSPEND_H
  6. #define USBSUSPEND_H
  7. /** \addtogroup module_usb_suspend USB Suspend (usbsusp)
  8. * \brief This module contains the functionality for USB suspend, USB resume and USB remote wakeup.
  9. *
  10. * All USB devices must support the suspended state to fully comply with the USB specification. Special
  11. * care must be taken to implement this functionality correctly, so follow the instructions below
  12. * carefully. Refer to the USB specification for detailed information on current consumption in suspend
  13. * mode (how power consumption shall be measured, averaging, peak value etc.).
  14. *
  15. * \section usb_suspend_resume USB Suspend and Resume
  16. * If there is no activity on the USB bus for a period longer than 3 ms, the MCU will generate a
  17. * \ref USBIRQ_EVENT_SUSPEND event. The USB device must then enter suspend mode within 10 ms, where it
  18. * draws no more than:
  19. * \li 500 uA for low-power devices or high-power devices operating at lower-power
  20. * \li 2.5 mA for high-power devices with remote wake-up enabled
  21. *
  22. * The library supports the USB suspend and resume functionality through a simple interface:
  23. * \li Make sure that the 48 MHz XOSC is never turned off anywhere in the application.
  24. * \li In the call to \ref usbirqInit(), add \ref USBIRQ_EVENT_SUSPEND and \ref USBIRQ_EVENT_RESUME
  25. * (optional) to the interrupt mask.
  26. * \li Do NOT process \ref USBIRQ_EVENT_SUSPEND in \ref usbirqHookProcessEvents() or in any other
  27. * interrupt service routine. This may (or in most cases will) prevent the USB device from getting
  28. * out of suspend mode.
  29. *
  30. * \li In the main loop, add the code shown below. Make sure that this code is visited at least every
  31. * 10 ms. If the worst-case path through the main loop uses more than 10 ms, the code block can be
  32. * inserted in multiple places in the loop until the requirement is met.
  33. * \code
  34. * // Process USB suspend events
  35. * if (USBIRQ_GET_EVENT_MASK() & USBIRQ_EVENT_SUSPEND) {
  36. *
  37. * // Clear the suspend event
  38. * USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_SUSPEND);
  39. *
  40. * ... Do what needs to be done before entering power mode 1 here (e.g. turn off the radio, configure
  41. * I/O to minimize power consumption, start the sleep timer etc.) ...
  42. *
  43. * // This function call will take the USB device into power mode 1. It will not return until resume
  44. * // signaling has been detected on the bus, or the remote wake-up function has been used. Other
  45. * // interrupts (for instance from I/O ports or the sleep timer) can be used during this period. When
  46. * // returning from these interrupts, the \ref usbsuspEnter() function (running here) will put the
  47. * // MCU back into power mode 1.
  48. * usbsuspEnter();
  49. *
  50. * // At this point the event handler is up and running again. Clear the resume event.
  51. * USBIRQ_CLEAR_EVENTS(USBIRQ_EVENT_RESUME);
  52. *
  53. * ... If a USBIRQ_EVENT_RESET event will affect the code that follows (before the event is processed
  54. * elsewhere), then make sure to handle it here also ...
  55. *
  56. * ... Do what needs to be done to wake up from suspend mode (e.g. turn on the radio, reactivate I/O
  57. * and peripherals, turn off the sleep timer ...
  58. * }
  59. * \endcode
  60. *
  61. * \li All interrupts that run during suspension mode must start with the following code:
  62. * \code
  63. * while (!XOSC_STABLE);
  64. * \endcode
  65. *
  66. * \section usb_remote_wakeup USB Remote Wakeup:
  67. * Remote wakeup should be used when the USB device desires to initiate the resume process and wake up
  68. * the host. In a radio application this may happen when a particular radio packet is received, for
  69. * instance from a wireless keyboard or mouse.
  70. *
  71. * USB remote wakeup can only be performed if the host has given the device the privilege to do so. The
  72. * privilege to perform remote wakeup is requested by setting bit 5 in the \c bmAttributes field in
  73. * the \ref USB_CONFIGURATION_DESCRIPTOR. The host will then grant or recall the privilege through a
  74. * SET_FEATURE request, which is communicated through a \ref USBSR_EVENT_REMOTE_WAKEUP_ENABLED or
  75. * \ref USBSR_EVENT_REMOTE_WAKEUP_DISABLED event, respectively.
  76. *
  77. * The USB library handles the remote wakeup sequence automatically. Do the following to incorporate it
  78. * into the application:
  79. * \li Implement suspend and resume as described above.
  80. * \li In the USB descriptor, set bit 5 in bmAttributes in the configuration descriptor.
  81. * \li While the USB MCU is in USB suspend mode, remote wakeup can be performed from interrupt context
  82. * (e.g. the sleep timer interrupt) by calling \ref usbsuspDoRemoteWakeup(). This function will
  83. * return TRUE if successful or FALSE if remote wakeup is not permitted (by the host).
  84. * @{
  85. */
  86. #include "usb_firmware_library_headers.h"
  87. typedef void (*VFPTR)(void);
  88. //-------------------------------------------------------------------------------------------------------
  89. // Suspend enter/exit hooks
  90. extern __xdata VFPTR pFnSuspendEnterHook;
  91. extern __xdata VFPTR pFnSuspendExitHook;
  92. //-------------------------------------------------------------------------------------------------------
  93. // Function prototypes
  94. void usbsuspEnter(void);
  95. uint8 usbsuspDoRemoteWakeup(void);
  96. void usbsuspStopPm1(void);
  97. //-------------------------------------------------------------------------------------------------------
  98. //@}
  99. /*
  100. +------------------------------------------------------------------------------
  101. | Copyright 2004-2007 Texas Instruments Incorporated. All rights reserved.
  102. |
  103. | IMPORTANT: Your use of this Software is limited to those specific rights
  104. | granted under the terms of a software license agreement between the user who
  105. | downloaded the software, his/her employer (which must be your employer) and
  106. | Texas Instruments Incorporated (the "License"). You may not use this Software
  107. | unless you agree to abide by the terms of the License. The License limits
  108. | your use, and you acknowledge, that the Software may not be modified, copied
  109. | or distributed unless embedded on a Texas Instruments microcontroller or used
  110. | solely and exclusively in conjunction with a Texas Instruments radio
  111. | frequency transceiver, which is integrated into your product. Other than for
  112. | the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  113. | works of, modify, distribute, perform, display or sell this Software and/or
  114. | its documentation for any purpose.
  115. |
  116. | YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  117. | PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  118. | INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  119. | NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  120. | TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  121. | NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  122. | LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING
  123. | BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
  124. | CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
  125. | SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  126. | (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  127. |
  128. | Should you have any questions regarding your right to use this Software,
  129. | contact Texas Instruments Incorporated at www.TI.com.
  130. |
  131. +------------------------------------------------------------------------------
  132. */
  133. #endif