usbdhandler.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //*****************************************************************************
  2. //
  3. // usbhandler.c - General USB handling routines.
  4. //
  5. // Copyright (c) 2007-2010 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of AM1808 StarterWare USB Library and reused from revision 6288
  22. // of the Stellaris USB Library.
  23. //
  24. //*****************************************************************************
  25. #include "hw_usb.h"
  26. #include "interrupt.h"
  27. #include "hw_types.h"
  28. #include "usb.h"
  29. #include "usblib.h"
  30. #include "usbdevice.h"
  31. #include "usbdevicepriv.h"
  32. #include "usblibpriv.h"
  33. //*****************************************************************************
  34. //
  35. //! \addtogroup device_api
  36. //! @{
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. // USB instance Object
  42. //
  43. //*****************************************************************************
  44. extern tUSBInstanceObject g_USBInstance[];
  45. //*****************************************************************************
  46. //
  47. //! The USB device interrupt handler.
  48. //!
  49. //! This the main USB interrupt handler entry point for use in USB device
  50. //! applications. This top-level handler will branch the interrupt off to the
  51. //! appropriate application or stack handlers depending on the current status
  52. //! of the USB controller.
  53. //!
  54. //! Applications which operate purely as USB devices (rather than dual mode
  55. //! applications which can operate in either device or host mode at different
  56. //! times) must ensure that a pointer to this function is installed in the
  57. //! interrupt vector table entry for the USB0 interrupt. For dual mode
  58. //! operation, the vector should be set to point to \e USB0DualModeIntHandler()
  59. //! instead.
  60. //!
  61. //! \return None.
  62. //
  63. //*****************************************************************************
  64. void
  65. USB0DeviceIntHandler(void)
  66. {
  67. unsigned int ulStatus = 0;
  68. #if defined(am335x) || defined (am335x_15x15) || defined(c6a811x) || defined(am386x) || \
  69. defined(c6741x)
  70. unsigned int epStatus = 0;
  71. //
  72. // Get the controller interrupt status.
  73. //
  74. ulStatus = HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_STATUS_1);
  75. //
  76. // Get the EP interrupt status.
  77. //
  78. epStatus = HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_STATUS_0);
  79. //
  80. // Clear the controller interrupt status.
  81. //
  82. HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_STATUS_1) = ulStatus;
  83. //
  84. // Clear the EP interrupt status.
  85. //
  86. HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_STATUS_0) = epStatus;
  87. #ifdef DMA_MODE
  88. HWREG(USBSS_BASE + USBSS_IRQ_STATUS) =
  89. HWREG(USBSS_BASE + USBSS_IRQ_STATUS);
  90. #endif
  91. //
  92. //Call the Interrupt Handler.
  93. //
  94. USBDeviceIntHandlerInternal(0, ulStatus, &epStatus);
  95. //
  96. //End of Interrupts.
  97. //
  98. HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_EOI) = 0;
  99. #ifdef DMA_MODE
  100. HWREG(USBSS_BASE + USBSS_IRQ_EOI) = 0;
  101. #endif
  102. #else
  103. //
  104. // Get the controller interrupt status.
  105. //
  106. ulStatus = HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_INTR_SRC);
  107. // Clear the Interrupts
  108. HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_INTR_SRC_CLEAR) = ulStatus;
  109. #ifdef _TMS320C6X
  110. IntEventClear(g_USBInstance[0].uiInterruptNum);
  111. #else
  112. IntSystemStatusClear(g_USBInstance[0].uiInterruptNum);
  113. #endif
  114. //
  115. // Call the internal handler.
  116. //
  117. USBDeviceIntHandlerInternal(0, ulStatus, NULL);
  118. // End of Interrupts
  119. HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_END_OF_INTR) = 0;
  120. #endif
  121. }
  122. void
  123. USB1DeviceIntHandler(void)
  124. {
  125. unsigned int ulStatus = 0;
  126. #if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
  127. unsigned int epStatus = 0;
  128. //
  129. // Get the controller interrupt status.
  130. //
  131. ulStatus = HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_STATUS_1);
  132. //
  133. // Get the EP interrupt status.
  134. //
  135. epStatus = HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_STATUS_0);
  136. //
  137. // Clear the controller interrupt status.
  138. //
  139. HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_STATUS_1) = ulStatus;
  140. //
  141. // Clear the EP interrupt status.
  142. //
  143. HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_STATUS_0) = epStatus;
  144. #ifdef DMA_MODE
  145. HWREG(USBSS_BASE + USBSS_IRQ_STATUS) =
  146. HWREG(USBSS_BASE + USBSS_IRQ_STATUS);
  147. #endif
  148. //
  149. //Call the Interrupt Handler.
  150. //
  151. USBDeviceIntHandlerInternal(1, ulStatus, &epStatus);
  152. //
  153. //End of Interrupts.
  154. //
  155. HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_EOI) = 0;
  156. #ifdef DMA_MODE
  157. HWREG(USBSS_BASE + USBSS_IRQ_EOI) = 0;
  158. #endif
  159. #else
  160. //
  161. // Get the controller interrupt status.
  162. //
  163. ulStatus = HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_INTR_SRC);
  164. // Clear the Interrupts
  165. HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_INTR_SRC_CLEAR) = ulStatus;
  166. #ifdef _TMS320C6X
  167. IntEventClear(g_USBInstance[1].uiInterruptNum);
  168. #else
  169. IntSystemStatusClear(g_USBInstance[1].uiInterruptNum);
  170. #endif
  171. //
  172. // Call the internal handler.
  173. //
  174. USBDeviceIntHandlerInternal(1, ulStatus, NULL);
  175. // End of Interrupts
  176. HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_END_OF_INTR) = 0;
  177. #endif
  178. }
  179. //*****************************************************************************
  180. //
  181. // Close the Doxygen group.
  182. //! @}
  183. //
  184. //*****************************************************************************