usb_hal.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //###########################################################################
  2. //
  3. // FILE: usb_hal.c
  4. //
  5. // TITLE: Wrapper for interrupt functions and USB support pins.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2837xD Support Library v3.05.00.00 $
  9. // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  10. // $Copyright:
  11. // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  12. //
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions
  15. // are met:
  16. //
  17. // Redistributions of source code must retain the above copyright
  18. // notice, this list of conditions and the following disclaimer.
  19. //
  20. // Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the
  23. // distribution.
  24. //
  25. // Neither the name of Texas Instruments Incorporated nor the names of
  26. // its contributors may be used to endorse or promote products derived
  27. // from this software without specific prior written permission.
  28. //
  29. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. // $
  41. //###########################################################################
  42. #include "F2837xD_device.h"
  43. #include "F2837xD_Examples.h"
  44. #include "inc/hw_types.h"
  45. #include "inc/hw_memmap.h"
  46. #include "inc/hw_usb.h"
  47. #include "usb_hal.h"
  48. #include "usb.h"
  49. #include "include/usblib.h"
  50. #include "include/usblibpriv.h"
  51. #include "include/device/usbdevice.h"
  52. #include "include/host/usbhost.h"
  53. #include "include/host/usbhostpriv.h"
  54. #include "include/usblibpriv.h"
  55. //*****************************************************************************
  56. //
  57. //! \addtogroup c2000_specific
  58. //! @{
  59. //
  60. //*****************************************************************************
  61. //*****************************************************************************
  62. //
  63. //! Enables USB related GPIOs to perform their USB function.
  64. //
  65. //*****************************************************************************
  66. void USBGPIOEnable(void)
  67. {
  68. EALLOW;
  69. GpioCtrlRegs.GPBLOCK.all = 0x00000000;
  70. GpioCtrlRegs.GPBAMSEL.bit.GPIO42 = 1;
  71. GpioCtrlRegs.GPBAMSEL.bit.GPIO43 = 1;
  72. //VBUS
  73. GpioCtrlRegs.GPBDIR.bit.GPIO46 = 0;
  74. //ID
  75. GpioCtrlRegs.GPBDIR.bit.GPIO47 = 0;
  76. GpioCtrlRegs.GPDGMUX2.bit.GPIO120 = 3;
  77. GpioCtrlRegs.GPDMUX2.bit.GPIO120 = 3;
  78. GpioCtrlRegs.GPDGMUX2.bit.GPIO121 = 3;
  79. GpioCtrlRegs.GPDMUX2.bit.GPIO121 = 3;
  80. EDIS;
  81. }
  82. //*****************************************************************************
  83. //
  84. //! Disables USB related GPIOs from performing their USB function.
  85. //
  86. //*****************************************************************************
  87. void USBGPIODisable(void)
  88. {
  89. EALLOW;
  90. GpioCtrlRegs.GPBLOCK.all = 0x00000000;
  91. GpioCtrlRegs.GPBAMSEL.bit.GPIO42 = 0;
  92. GpioCtrlRegs.GPBAMSEL.bit.GPIO43 = 0;
  93. GpioCtrlRegs.GPDGMUX2.bit.GPIO120 = 0;
  94. GpioCtrlRegs.GPDMUX2.bit.GPIO120 = 0;
  95. GpioCtrlRegs.GPDGMUX2.bit.GPIO121 = 0;
  96. GpioCtrlRegs.GPDMUX2.bit.GPIO121 = 0;
  97. EDIS;
  98. }
  99. //*****************************************************************************
  100. //
  101. //! Wrapper function to implement mS based delay for USB functions
  102. //
  103. //*****************************************************************************
  104. void USBDelay(uint32_t ui32Delay)
  105. {
  106. DELAY_US(ui32Delay*1000);
  107. }
  108. //*****************************************************************************
  109. //
  110. //! Device interrupt service routine wrapper to make ISR compatible with
  111. //! C2000 PIE controller.
  112. //
  113. //*****************************************************************************
  114. __interrupt void
  115. f28x_USB0DeviceIntHandler(void)
  116. {
  117. USB0DeviceIntHandler();
  118. PieCtrlRegs.PIEACK.all |= 0x0100;
  119. }
  120. //*****************************************************************************
  121. //
  122. //! Host interrupt service routine wrapper to make ISR compatible with
  123. //! C2000 PIE controller.
  124. //
  125. //*****************************************************************************
  126. __interrupt void
  127. f28x_USB0HostIntHandler(void)
  128. {
  129. USB0HostIntHandler();
  130. PieCtrlRegs.PIEACK.all |= 0x0100;
  131. }
  132. //*****************************************************************************
  133. //
  134. //! Dual mode interrupt service routine wrapper to make ISR compatible with
  135. //! C2000 PIE controller.
  136. //
  137. //*****************************************************************************
  138. __interrupt void
  139. f28x_USB0DualModeIntHandler(void)
  140. {
  141. USB0DualModeIntHandler();
  142. PieCtrlRegs.PIEACK.all |= 0x0100;
  143. }
  144. //*****************************************************************************
  145. //
  146. // Close the c2000_specific Doxygen group.
  147. //! @}
  148. //
  149. //*****************************************************************************