hw_usb.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //*****************************************************************************
  2. //
  3. // hw_usb.h - Macros for use in accessing the USB registers.
  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 Hercules Development Kit software.
  22. //
  23. //******************************************************************************
  24. #ifndef __HW_USB_H__
  25. #define __HW_USB_H__
  26. /** @brief Base address of memmory mapped Registers */
  27. #define USBD_0_BASE 0xFCF78A00u
  28. #define USB0_BASE USBD_0_BASE
  29. typedef volatile struct {
  30. uint16 rev; /* Revision */
  31. /** Endpoint registers ***************************************************/
  32. uint16 epnum; /* Endpoint selection */
  33. uint16 data; /* Data */
  34. uint16 ctrl; /* Control */
  35. uint16 stat_flag; /* Status */
  36. uint16 rxf_stat; /* RX FIFO Status */
  37. uint16 syscon1; /* System configuration 1 */
  38. uint16 syscon2; /* System configuration 2 */
  39. uint16 dev_stat; /* Device status */
  40. uint16 sof; /* Start of frame */
  41. uint16 irq_en; /* Interrupt enable */
  42. uint16 dma_irqen; /* DMA Interrupt enable */
  43. uint16 irqsrc; /* Interrupt source */
  44. uint16 epn_stat; /* Non-ISO EP interrupt enable */
  45. uint16 dman_stat; /* Non-ISO DMA interrupt enable */
  46. uint16 _rsvd1[1]; /* Reserved for reg holes */
  47. /** DMA Configuration ***************************************************/
  48. uint16 rxdma_cfg; /* DMA Rx channels configuration */
  49. uint16 txdma_cfg; /* DMA Tx channels configuration */
  50. uint16 data_dma; /* DMA FIFO data */
  51. uint16 txdma0; /* Transmit DMA control 0 */
  52. uint16 txdma1; /* Transmit DMA control 1 */
  53. uint16 txdma2; /* Transmit DMA control 2 */
  54. uint16 _rsvd2[2]; /* Reserved for reg holes */
  55. uint16 dman_rxdma0; /* Receive DMA control 0 */
  56. uint16 dman_rxdma1; /* Receive DMA control 1 */
  57. uint16 dman_rxdma2; /* Receive DMA control 2 */
  58. uint16 _rsvd3[5]; /* Reserved */
  59. /** Endpoint Configuration ***********************************************/
  60. uint16 ep0; /* Endpoint 0 Configuration */
  61. uint16 epn_rx[15]; /* RX EP configurations... */
  62. uint16 _rsvd4[1]; /* Reserved for reg holes */
  63. uint16 epn_tx[15]; /* TX EP configurations... */
  64. } usbdRegs;
  65. /******************************************************************************\
  66. * Register Bit Masks
  67. * (USBD_<Instance ID=0>_<Register Name>_<Bit Field Name> <Mask Value>
  68. \******************************************************************************/
  69. /* Endpoint selection *********************************************************/
  70. #define USBD_EP_NUM_SETUP_SEL (0x0040u)
  71. #define USBD_EP_NUM_EP_SEL (0x0020u)
  72. #define USBD_EP_NUM_EP_DIR (0x0010u)
  73. #define USBD_EP_NUM_EP_NUM_MASK (0x000Fu)
  74. /* Data ***********************************************************************/
  75. #define USBD_DATA_DATA (0xFFFFu)
  76. /* Control ********************************************************************/
  77. #define USBD_CTRL_CLR_HALT (0x0080u)
  78. #define USBD_CTRL_SET_HALT (0x0040u)
  79. #define USBD_CTRL_SET_FIFO_EN (0x0004u)
  80. #define USBD_CTRL_CLR_EP (0x0002u)
  81. #define USBD_CTRL_RESET_EP (0x0001u)
  82. /* Status *********************************************************************/
  83. #define USBD_STAT_FLG_NO_RXPACKET (0x8000u)
  84. #define USBD_STAT_FLG_MISS_IN (0x4000u)
  85. #define USBD_STAT_FLG_DATA_FLUSH (0x2000u)
  86. #define USBD_STAT_FLG_ISO_ERR (0x1000u)
  87. #define USBD_STAT_FLG_ISO_FIFO_EMPTY (0x0200u)
  88. #define USBD_STAT_FLG_ISO_FIFO_FULL (0x0100u)
  89. #define USBD_STAT_FLG_EP_HALTED (0x0040u)
  90. #define USBD_STAT_FLG_STALL (0x0020u)
  91. #define USBD_STAT_FLG_NAK (0x0010u)
  92. #define USBD_STAT_FLG_ACK (0x0008u)
  93. #define USBD_STAT_FLG_FIFO_EN (0x0004u)
  94. #define USBD_STAT_FLG_NON_ISO_FIFO_EMPTY (0x0002u)
  95. #define USBD_STAT_FLG_NON_ISO_FIFO_FULL (0x0001u)
  96. /* RX FIFO Status */
  97. #define USBD_RXFSTAT_RXF_COUNT (0x03FFu)
  98. /* System configuration 1 *****************************************************/
  99. #define USBD_SYSCON1_CFG_LOCK (0x0100u)
  100. #define USBD_SYSCON1_DATA_ENDIAN (0x0080u)
  101. #define USBD_SYSCON1_DMA_ENDIAN (0x0040u)
  102. #define USBD_SYSCON1_NAK_EN (0x0010u)
  103. #define USBD_SYSCON1_AUTODEC_DIS (0x0008u)
  104. #define USBD_SYSCON1_SELF_PWR (0x0004u)
  105. #define USBD_SYSCON1_SOFF_DIS (0x0002u)
  106. #define USBD_SYSCON1_PULLUP_EN (0x0001u)
  107. /* System configuration 2 *****************************************************/
  108. #define USBD_SYSCON2_RMT_WKP (0x0040u)
  109. #define USBD_SYSCON2_STALL_CMD (0x0020u)
  110. #define USBD_SYSCON2_DEV_CFG (0x0008u)
  111. #define USBD_SYSCON2_CLR_CFG (0x0004u)
  112. /* Device status **************************************************************/
  113. #define USBD_DEVSTAT_B_HNP_ENABLE (0x0200u)
  114. #define USBD_DEVSTAT_A_HNP_SUPPORT (0x0100u)
  115. #define USBD_DEVSTAT_A_ALT_HNP_SUPPORT (0x0080u)
  116. #define USBD_DEVSTAT_R_WK_OK (0x0040u)
  117. #define USBD_DEVSTAT_USB_RESET (0x0020u)
  118. #define USBD_DEVSTAT_SUS (0x0010u)
  119. #define USBD_DEVSTAT_CFG (0x0008u)
  120. #define USBD_DEVSTAT_ADD (0x0004u)
  121. #define USBD_DEVSTAT_DEF (0x0002u)
  122. #define USBD_DEVSTAT_ATT (0x0001u)
  123. /* Start of frame *************************************************************/
  124. #define USBD_SOF_FT_LOCK (0x1000u)
  125. #define USBD_SOF_TS_OK (0x0800u)
  126. #define USBD_SOF_TS (0x07FFu)
  127. /* Interrupt enable ***********************************************************/
  128. #define USBD_IRQ_EN_SOF_IE (0x0080u)
  129. #define USBD_IRQ_EN_EPN_RX_IE (0x0020u)
  130. #define USBD_IRQ_EN_EPN_TX_IE (0x0010u)
  131. #define USBD_IRQ_EN_DS_CHG_IE (0x0008u)
  132. #define USBD_IRQ_EN_EP0_IE (0x0001u)
  133. /* DMA Interrupt enable *******************************************************/
  134. #define USBD_DMA_IRQ_EN_TX2_DONE_IE (0x0400u)
  135. #define USBD_DMA_IRQ_EN_RX2_CNT_IE (0x0200u)
  136. #define USBD_DMA_IRQ_EN_RX2_EOT_IE (0x0100u)
  137. #define USBD_DMA_IRQ_EN_TX1_DONE_IE (0x0040u)
  138. #define USBD_DMA_IRQ_EN_RX1_CNT_IE (0x0020u)
  139. #define USBD_DMA_IRQ_EN_RX1_EOT_IE (0x0010u)
  140. #define USBD_DMA_IRQ_EN_TX0_DONE_IE (0x0004u)
  141. #define USBD_DMA_IRQ_EN_RX0_CNT_IE (0x0002u)
  142. #define USBD_DMA_IRQ_EN_RX0_EOT_IE (0x0001u)
  143. /* Interrupt source ***********************************************************/
  144. #define USBD_IRQ_SRC_TXN_DONE (0x0400u)
  145. #define USBD_IRQ_SRC_RXN_CNT (0x0200u)
  146. #define USBD_IRQ_SRC_RXN_EOT (0x0100u)
  147. #define USBD_IRQ_SRC_SOF (0x0080u)
  148. #define USBD_IRQ_SRC_EPN_RX (0x0020u)
  149. #define USBD_IRQ_SRC_EPN_TX (0x0010u)
  150. #define USBD_IRQ_SRC_DS_CHG (0x0008u)
  151. #define USBD_IRQ_SRC_SETUP (0x0004u)
  152. #define USBD_IRQ_SRC_EP0_RX (0x0002u)
  153. #define USBD_IRQ_SRC_EP0_TX (0x0001u)
  154. /* Non-ISO endpoint interrupt enable ******************************************/
  155. #define USBD_EPN_STAT_RX_IT_SRC (0x0F00u)
  156. #define USBD_EPN_STAT_TX_IT_SRC (0x000Fu)
  157. /* Non-ISO DMA interrupt enable ***********************************************/
  158. #define USBD_DMAN_STAT_RX_SB (0x1000u)
  159. #define USBD_DMAN_STAT_RX_IT_SRC (0x0F00u)
  160. #define USBD_DMAN_STAT_TX_IT_SRC (0x000Fu)
  161. /* DMA Receive channels configuration *****************************************/
  162. #define USBD_RXDMA_CFG_RX_REQ (0x1000u)
  163. #define USBD_RXDMA_CFG_RXDMA2_EP (0x0F00u)
  164. #define USBD_RXDMA_CFG_RXDMA1_EP (0x00F0u)
  165. #define USBD_RXDMA_CFG_RXDMA0_EP (0x000Fu)
  166. /* DMA Transmit channels configuration ****************************************/
  167. #define USBD_TXDMA_CFG_TX_REQ (0x1000u)
  168. #define USBD_TXDMA_CFG_TXDMA2_EP (0x0F00u)
  169. #define USBD_TXDMA_CFG_TXDMA1_EP (0x00F0u)
  170. #define USBD_TXDMA_CFG_TXDMA0_EP (0x000Fu)
  171. /* DMA FIFO data **************************************************************/
  172. #define USBD_DATA_DMA_DATA_DMA (0xFFFFu)
  173. /* Transmit DMA control 0 *****************************************************/
  174. #define USBD_TXDMA0_TX0_EOT (0x8000u)
  175. #define USBD_TXDMA0_TX0_START (0x4000u)
  176. #define USBD_TXDMA0_TX0_TSC (0x03FFu)
  177. /* Transmit DMA control 1 *****************************************************/
  178. #define USBD_TXDMA1_TX1_EOT (0x8000u)
  179. #define USBD_TXDMA1_TX1_START (0x4000u)
  180. #define USBD_TXDMA1_TX1_TSC (0x03FFu)
  181. #define USBD_TXDMA1_TX1_TSC_SHIFT (0x0000u)
  182. /* Transmit DMA control 2 *****************************************************/
  183. #define USBD_TXDMA2_TX2_EOT (0x8000u)
  184. #define USBD_TXDMA2_TX2_START (0x4000u)
  185. #define USBD_TXDMA2_TX2_TSC (0x03FFu)
  186. /* Receive DMA control 0 ******************************************************/
  187. #define USBD_RXDMA0_RX0_STOP (0x8000u)
  188. #define USBD_RXDMA0_RX0_TC (0x00FFu)
  189. /* Receive DMA control 1 ******************************************************/
  190. #define USBD_RXDMA1_RX10_STOP (0x8000u)
  191. #define USBD_RXDMA1_RX1_TC (0x00FFu)
  192. /* Receive DMA control 2 ******************************************************/
  193. #define USBD_RXDMA2_RX2_STOP (0x8000u)
  194. #define USBD_RXDMA2_RX2_TC (0x00FFu)
  195. /* Endpoint 0 Configuration ***************************************************/
  196. #define USBD_EP0_SIZE (0x3000u)
  197. #define USBD_EP0_PTR (0x07FFu)
  198. /* Receive endpoint configurations... *****************************************/
  199. #define USBD_RX_EP_VALID (0x8000u)
  200. #define USBD_RX_EP_SIZEDB (0x4000u)
  201. #define USBD_RX_EP_SIZE (0x3000u)
  202. #define USBD_RX_EP_ISO (0x0800u)
  203. #define USBD_RX_EP_PTR (0x07FFu)
  204. /* Transmit endpoint configurations... ****************************************/
  205. #define USBD_TX_EP_VALID (0x8000u)
  206. #define USBD_TX_EP_SIZEDB (0x4000u)
  207. #define USBD_TX_EP_SIZE (0x3000u)
  208. #define USBD_TX_EP_ISO (0x0800u)
  209. #define USBD_TX_EP_PTR (0x07FFu)
  210. #define USBD_MAX_EP0_PTR (0xFFu)
  211. #define USBD_EP_RX_MAX (15u)
  212. #define USBD_EP_TX_MAX (15u)
  213. /** @brief Macro for setting a bit/s in a register (read, modify & write) */
  214. #define USBD_REG_BIT_SET(reg,bit) ((reg) |= ((uint16)(bit)))
  215. /** @brief Macro for clearing a bit/s in a register (read, modify & write) */
  216. #define USBD_REG_BIT_CLR(reg,bit) ((reg) &= ((uint16)~((uint16)bit)))
  217. /** @brief Macro for setting a bit/s in a register (write) */
  218. #define USBD_REG_SET_ONE(reg,value) ((reg) = ((uint16)value))
  219. #endif // __HW_USB_H__