usb_regs.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
  2. * File Name : usb_regs.h
  3. * Author : MCD Application Team
  4. * Version : V3.1.0
  5. * Date : 10/30/2009
  6. * Description : Interface prototype functions to USB cell registers
  7. ********************************************************************************
  8. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  9. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  10. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  11. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  12. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  13. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  14. *******************************************************************************/
  15. /* Define to prevent recursive inclusion -------------------------------------*/
  16. #ifndef __USB_REGS_H
  17. #define __USB_REGS_H
  18. #ifndef STM32F10X_CL
  19. /* Includes ------------------------------------------------------------------*/
  20. /* Exported types ------------------------------------------------------------*/
  21. typedef enum _EP_DBUF_DIR
  22. {
  23. /* double buffered endpoint direction */
  24. EP_DBUF_ERR,
  25. EP_DBUF_OUT,
  26. EP_DBUF_IN
  27. }EP_DBUF_DIR;
  28. /* endpoint buffer number */
  29. enum EP_BUF_NUM
  30. {
  31. EP_NOBUF,
  32. EP_BUF0,
  33. EP_BUF1
  34. };
  35. /* Exported constants --------------------------------------------------------*/
  36. #define RegBase (0x40005C00L) /* USB_IP Peripheral Registers base address */
  37. #define PMAAddr (0x40006000L) /* USB_IP Packet Memory Area base address */
  38. /******************************************************************************/
  39. /* General registers */
  40. /******************************************************************************/
  41. /* Control register */
  42. #define CNTR ((__IO unsigned *)(RegBase + 0x40))
  43. /* Interrupt status register */
  44. #define ISTR ((__IO unsigned *)(RegBase + 0x44))
  45. /* Frame number register */
  46. #define FNR ((__IO unsigned *)(RegBase + 0x48))
  47. /* Device address register */
  48. #define DADDR ((__IO unsigned *)(RegBase + 0x4C))
  49. /* Buffer Table address register */
  50. #define BTABLE ((__IO unsigned *)(RegBase + 0x50))
  51. /******************************************************************************/
  52. /* Endpoint registers */
  53. /******************************************************************************/
  54. #define EP0REG ((__IO unsigned *)(RegBase)) /* endpoint 0 register address */
  55. /* Endpoint Addresses (w/direction) */
  56. #define EP0_OUT ((uint8_t)0x00)
  57. #define EP0_IN ((uint8_t)0x80)
  58. #define EP1_OUT ((uint8_t)0x01)
  59. #define EP1_IN ((uint8_t)0x81)
  60. #define EP2_OUT ((uint8_t)0x02)
  61. #define EP2_IN ((uint8_t)0x82)
  62. #define EP3_OUT ((uint8_t)0x03)
  63. #define EP3_IN ((uint8_t)0x83)
  64. #define EP4_OUT ((uint8_t)0x04)
  65. #define EP4_IN ((uint8_t)0x84)
  66. #define EP5_OUT ((uint8_t)0x05)
  67. #define EP5_IN ((uint8_t)0x85)
  68. #define EP6_OUT ((uint8_t)0x06)
  69. #define EP6_IN ((uint8_t)0x86)
  70. #define EP7_OUT ((uint8_t)0x07)
  71. #define EP7_IN ((uint8_t)0x87)
  72. /* endpoints enumeration */
  73. #define ENDP0 ((uint8_t)0)
  74. #define ENDP1 ((uint8_t)1)
  75. #define ENDP2 ((uint8_t)2)
  76. #define ENDP3 ((uint8_t)3)
  77. #define ENDP4 ((uint8_t)4)
  78. #define ENDP5 ((uint8_t)5)
  79. #define ENDP6 ((uint8_t)6)
  80. #define ENDP7 ((uint8_t)7)
  81. /******************************************************************************/
  82. /* ISTR interrupt events */
  83. /******************************************************************************/
  84. #define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */
  85. #define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */
  86. #define ISTR_ERR (0x2000) /* ERRor (clear-only bit) */
  87. #define ISTR_WKUP (0x1000) /* WaKe UP (clear-only bit) */
  88. #define ISTR_SUSP (0x0800) /* SUSPend (clear-only bit) */
  89. #define ISTR_RESET (0x0400) /* RESET (clear-only bit) */
  90. #define ISTR_SOF (0x0200) /* Start Of Frame (clear-only bit) */
  91. #define ISTR_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */
  92. #define ISTR_DIR (0x0010) /* DIRection of transaction (read-only bit) */
  93. #define ISTR_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */
  94. #define CLR_CTR (~ISTR_CTR) /* clear Correct TRansfer bit */
  95. #define CLR_DOVR (~ISTR_DOVR) /* clear DMA OVeR/underrun bit*/
  96. #define CLR_ERR (~ISTR_ERR) /* clear ERRor bit */
  97. #define CLR_WKUP (~ISTR_WKUP) /* clear WaKe UP bit */
  98. #define CLR_SUSP (~ISTR_SUSP) /* clear SUSPend bit */
  99. #define CLR_RESET (~ISTR_RESET) /* clear RESET bit */
  100. #define CLR_SOF (~ISTR_SOF) /* clear Start Of Frame bit */
  101. #define CLR_ESOF (~ISTR_ESOF) /* clear Expected Start Of Frame bit */
  102. /******************************************************************************/
  103. /* CNTR control register bits definitions */
  104. /******************************************************************************/
  105. #define CNTR_CTRM (0x8000) /* Correct TRansfer Mask */
  106. #define CNTR_DOVRM (0x4000) /* DMA OVeR/underrun Mask */
  107. #define CNTR_ERRM (0x2000) /* ERRor Mask */
  108. #define CNTR_WKUPM (0x1000) /* WaKe UP Mask */
  109. #define CNTR_SUSPM (0x0800) /* SUSPend Mask */
  110. #define CNTR_RESETM (0x0400) /* RESET Mask */
  111. #define CNTR_SOFM (0x0200) /* Start Of Frame Mask */
  112. #define CNTR_ESOFM (0x0100) /* Expected Start Of Frame Mask */
  113. #define CNTR_RESUME (0x0010) /* RESUME request */
  114. #define CNTR_FSUSP (0x0008) /* Force SUSPend */
  115. #define CNTR_LPMODE (0x0004) /* Low-power MODE */
  116. #define CNTR_PDWN (0x0002) /* Power DoWN */
  117. #define CNTR_FRES (0x0001) /* Force USB RESet */
  118. /******************************************************************************/
  119. /* FNR Frame Number Register bit definitions */
  120. /******************************************************************************/
  121. #define FNR_RXDP (0x8000) /* status of D+ data line */
  122. #define FNR_RXDM (0x4000) /* status of D- data line */
  123. #define FNR_LCK (0x2000) /* LoCKed */
  124. #define FNR_LSOF (0x1800) /* Lost SOF */
  125. #define FNR_FN (0x07FF) /* Frame Number */
  126. /******************************************************************************/
  127. /* DADDR Device ADDRess bit definitions */
  128. /******************************************************************************/
  129. #define DADDR_EF (0x80)
  130. #define DADDR_ADD (0x7F)
  131. /******************************************************************************/
  132. /* Endpoint register */
  133. /******************************************************************************/
  134. /* bit positions */
  135. #define EP_CTR_RX (0x8000) /* EndPoint Correct TRansfer RX */
  136. #define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */
  137. #define EPRX_STAT (0x3000) /* EndPoint RX STATus bit field */
  138. #define EP_SETUP (0x0800) /* EndPoint SETUP */
  139. #define EP_T_FIELD (0x0600) /* EndPoint TYPE */
  140. #define EP_KIND (0x0100) /* EndPoint KIND */
  141. #define EP_CTR_TX (0x0080) /* EndPoint Correct TRansfer TX */
  142. #define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */
  143. #define EPTX_STAT (0x0030) /* EndPoint TX STATus bit field */
  144. #define EPADDR_FIELD (0x000F) /* EndPoint ADDRess FIELD */
  145. /* EndPoint REGister MASK (no toggle fields) */
  146. #define EPREG_MASK (EP_CTR_RX|EP_SETUP|EP_T_FIELD|EP_KIND|EP_CTR_TX|EPADDR_FIELD)
  147. /* EP_TYPE[1:0] EndPoint TYPE */
  148. #define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */
  149. #define EP_BULK (0x0000) /* EndPoint BULK */
  150. #define EP_CONTROL (0x0200) /* EndPoint CONTROL */
  151. #define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */
  152. #define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */
  153. #define EP_T_MASK (~EP_T_FIELD & EPREG_MASK)
  154. /* EP_KIND EndPoint KIND */
  155. #define EPKIND_MASK (~EP_KIND & EPREG_MASK)
  156. /* STAT_TX[1:0] STATus for TX transfer */
  157. #define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */
  158. #define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */
  159. #define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */
  160. #define EP_TX_VALID (0x0030) /* EndPoint TX VALID */
  161. #define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */
  162. #define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */
  163. #define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK)
  164. /* STAT_RX[1:0] STATus for RX transfer */
  165. #define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */
  166. #define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */
  167. #define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */
  168. #define EP_RX_VALID (0x3000) /* EndPoint RX VALID */
  169. #define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */
  170. #define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */
  171. #define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK)
  172. /* Exported macro ------------------------------------------------------------*/
  173. /* SetCNTR */
  174. #define _SetCNTR(wRegValue) (*CNTR = (uint16_t)wRegValue)
  175. /* SetISTR */
  176. #define _SetISTR(wRegValue) (*ISTR = (uint16_t)wRegValue)
  177. /* SetDADDR */
  178. #define _SetDADDR(wRegValue) (*DADDR = (uint16_t)wRegValue)
  179. /* SetBTABLE */
  180. #define _SetBTABLE(wRegValue)(*BTABLE = (uint16_t)(wRegValue & 0xFFF8))
  181. /* GetCNTR */
  182. #define _GetCNTR() ((uint16_t) *CNTR)
  183. /* GetISTR */
  184. #define _GetISTR() ((uint16_t) *ISTR)
  185. /* GetFNR */
  186. #define _GetFNR() ((uint16_t) *FNR)
  187. /* GetDADDR */
  188. #define _GetDADDR() ((uint16_t) *DADDR)
  189. /* GetBTABLE */
  190. #define _GetBTABLE() ((uint16_t) *BTABLE)
  191. /* SetENDPOINT */
  192. #define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \
  193. (uint16_t)wRegValue)
  194. /* GetENDPOINT */
  195. #define _GetENDPOINT(bEpNum) ((uint16_t)(*(EP0REG + bEpNum)))
  196. /*******************************************************************************
  197. * Macro Name : SetEPType
  198. * Description : sets the type in the endpoint register(bits EP_TYPE[1:0])
  199. * Input : bEpNum: Endpoint Number.
  200. * wType
  201. * Output : None.
  202. * Return : None.
  203. *******************************************************************************/
  204. #define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\
  205. ((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType )))
  206. /*******************************************************************************
  207. * Macro Name : GetEPType
  208. * Description : gets the type in the endpoint register(bits EP_TYPE[1:0])
  209. * Input : bEpNum: Endpoint Number.
  210. * Output : None.
  211. * Return : Endpoint Type
  212. *******************************************************************************/
  213. #define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD)
  214. /*******************************************************************************
  215. * Macro Name : SetEPTxStatus
  216. * Description : sets the status for tx transfer (bits STAT_TX[1:0]).
  217. * Input : bEpNum: Endpoint Number.
  218. * wState: new state
  219. * Output : None.
  220. * Return : None.
  221. *******************************************************************************/
  222. #define _SetEPTxStatus(bEpNum,wState) {\
  223. register uint16_t _wRegVal; \
  224. _wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\
  225. /* toggle first bit ? */ \
  226. if((EPTX_DTOG1 & wState)!= 0) \
  227. _wRegVal ^= EPTX_DTOG1; \
  228. /* toggle second bit ? */ \
  229. if((EPTX_DTOG2 & wState)!= 0) \
  230. _wRegVal ^= EPTX_DTOG2; \
  231. _SetENDPOINT(bEpNum, (_wRegVal | EP_CTR_RX|EP_CTR_TX)); \
  232. } /* _SetEPTxStatus */
  233. /*******************************************************************************
  234. * Macro Name : SetEPRxStatus
  235. * Description : sets the status for rx transfer (bits STAT_TX[1:0])
  236. * Input : bEpNum: Endpoint Number.
  237. * wState: new state.
  238. * Output : None.
  239. * Return : None.
  240. *******************************************************************************/
  241. #define _SetEPRxStatus(bEpNum,wState) {\
  242. register uint16_t _wRegVal; \
  243. \
  244. _wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\
  245. /* toggle first bit ? */ \
  246. if((EPRX_DTOG1 & wState)!= 0) \
  247. _wRegVal ^= EPRX_DTOG1; \
  248. /* toggle second bit ? */ \
  249. if((EPRX_DTOG2 & wState)!= 0) \
  250. _wRegVal ^= EPRX_DTOG2; \
  251. _SetENDPOINT(bEpNum, (_wRegVal | EP_CTR_RX|EP_CTR_TX)); \
  252. } /* _SetEPRxStatus */
  253. /*******************************************************************************
  254. * Macro Name : SetEPRxTxStatus
  255. * Description : sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0])
  256. * Input : bEpNum: Endpoint Number.
  257. * wStaterx: new state.
  258. * wStatetx: new state.
  259. * Output : None.
  260. * Return : None.
  261. *******************************************************************************/
  262. #define _SetEPRxTxStatus(bEpNum,wStaterx,wStatetx) {\
  263. register uint32_t _wRegVal; \
  264. \
  265. _wRegVal = _GetENDPOINT(bEpNum) & (EPRX_DTOGMASK |EPTX_STAT) ;\
  266. /* toggle first bit ? */ \
  267. if((EPRX_DTOG1 & wStaterx)!= 0) \
  268. _wRegVal ^= EPRX_DTOG1; \
  269. /* toggle second bit ? */ \
  270. if((EPRX_DTOG2 & wStaterx)!= 0) \
  271. _wRegVal ^= EPRX_DTOG2; \
  272. /* toggle first bit ? */ \
  273. if((EPTX_DTOG1 & wStatetx)!= 0) \
  274. _wRegVal ^= EPTX_DTOG1; \
  275. /* toggle second bit ? */ \
  276. if((EPTX_DTOG2 & wStatetx)!= 0) \
  277. _wRegVal ^= EPTX_DTOG2; \
  278. _SetENDPOINT(bEpNum, _wRegVal | EP_CTR_RX|EP_CTR_TX); \
  279. } /* _SetEPRxTxStatus */
  280. /*******************************************************************************
  281. * Macro Name : GetEPTxStatus / GetEPRxStatus
  282. * Description : gets the status for tx/rx transfer (bits STAT_TX[1:0]
  283. * /STAT_RX[1:0])
  284. * Input : bEpNum: Endpoint Number.
  285. * Output : None.
  286. * Return : status .
  287. *******************************************************************************/
  288. #define _GetEPTxStatus(bEpNum) ((uint16_t)_GetENDPOINT(bEpNum) & EPTX_STAT)
  289. #define _GetEPRxStatus(bEpNum) ((uint16_t)_GetENDPOINT(bEpNum) & EPRX_STAT)
  290. /*******************************************************************************
  291. * Macro Name : SetEPTxValid / SetEPRxValid
  292. * Description : sets directly the VALID tx/rx-status into the enpoint register
  293. * Input : bEpNum: Endpoint Number.
  294. * Output : None.
  295. * Return : None.
  296. *******************************************************************************/
  297. #define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID))
  298. #define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID))
  299. /*******************************************************************************
  300. * Macro Name : GetTxStallStatus / GetRxStallStatus.
  301. * Description : checks stall condition in an endpoint.
  302. * Input : bEpNum: Endpoint Number.
  303. * Output : None.
  304. * Return : TRUE = endpoint in stall condition.
  305. *******************************************************************************/
  306. #define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \
  307. == EP_TX_STALL)
  308. #define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \
  309. == EP_RX_STALL)
  310. /*******************************************************************************
  311. * Macro Name : SetEP_KIND / ClearEP_KIND.
  312. * Description : set & clear EP_KIND bit.
  313. * Input : bEpNum: Endpoint Number.
  314. * Output : None.
  315. * Return : None.
  316. *******************************************************************************/
  317. #define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
  318. (EP_CTR_RX|EP_CTR_TX|((_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK))))
  319. #define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
  320. (EP_CTR_RX|EP_CTR_TX|(_GetENDPOINT(bEpNum) & EPKIND_MASK))))
  321. /*******************************************************************************
  322. * Macro Name : Set_Status_Out / Clear_Status_Out.
  323. * Description : Sets/clears directly STATUS_OUT bit in the endpoint register.
  324. * Input : bEpNum: Endpoint Number.
  325. * Output : None.
  326. * Return : None.
  327. *******************************************************************************/
  328. #define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum)
  329. #define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum)
  330. /*******************************************************************************
  331. * Macro Name : SetEPDoubleBuff / ClearEPDoubleBuff.
  332. * Description : Sets/clears directly EP_KIND bit in the endpoint register.
  333. * Input : bEpNum: Endpoint Number.
  334. * Output : None.
  335. * Return : None.
  336. *******************************************************************************/
  337. #define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum)
  338. #define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum)
  339. /*******************************************************************************
  340. * Macro Name : ClearEP_CTR_RX / ClearEP_CTR_TX.
  341. * Description : Clears bit CTR_RX / CTR_TX in the endpoint register.
  342. * Input : bEpNum: Endpoint Number.
  343. * Output : None.
  344. * Return : None.
  345. *******************************************************************************/
  346. #define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\
  347. _GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK))
  348. #define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\
  349. _GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK))
  350. /*******************************************************************************
  351. * Macro Name : ToggleDTOG_RX / ToggleDTOG_TX .
  352. * Description : Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
  353. * Input : bEpNum: Endpoint Number.
  354. * Output : None.
  355. * Return : None.
  356. *******************************************************************************/
  357. #define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \
  358. EP_CTR_RX|EP_CTR_TX|EP_DTOG_RX | (_GetENDPOINT(bEpNum) & EPREG_MASK)))
  359. #define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \
  360. EP_CTR_RX|EP_CTR_TX|EP_DTOG_TX | (_GetENDPOINT(bEpNum) & EPREG_MASK)))
  361. /*******************************************************************************
  362. * Macro Name : ClearDTOG_RX / ClearDTOG_TX.
  363. * Description : Clears DTOG_RX / DTOG_TX bit in the endpoint register.
  364. * Input : bEpNum: Endpoint Number.
  365. * Output : None.
  366. * Return : None.
  367. *******************************************************************************/
  368. #define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\
  369. _ToggleDTOG_RX(bEpNum)
  370. #define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\
  371. _ToggleDTOG_TX(bEpNum)
  372. /*******************************************************************************
  373. * Macro Name : SetEPAddress.
  374. * Description : Sets address in an endpoint register.
  375. * Input : bEpNum: Endpoint Number.
  376. * bAddr: Address.
  377. * Output : None.
  378. * Return : None.
  379. *******************************************************************************/
  380. #define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\
  381. EP_CTR_RX|EP_CTR_TX|(_GetENDPOINT(bEpNum) & EPREG_MASK) | bAddr)
  382. /*******************************************************************************
  383. * Macro Name : GetEPAddress.
  384. * Description : Gets address in an endpoint register.
  385. * Input : bEpNum: Endpoint Number.
  386. * Output : None.
  387. * Return : None.
  388. *******************************************************************************/
  389. #define _GetEPAddress(bEpNum) ((uint8_t)(_GetENDPOINT(bEpNum) & EPADDR_FIELD))
  390. #define _pEPTxAddr(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr))
  391. #define _pEPTxCount(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr))
  392. #define _pEPRxAddr(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr))
  393. #define _pEPRxCount(bEpNum) ((uint32_t *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr))
  394. /*******************************************************************************
  395. * Macro Name : SetEPTxAddr / SetEPRxAddr.
  396. * Description : sets address of the tx/rx buffer.
  397. * Input : bEpNum: Endpoint Number.
  398. * wAddr: address to be set (must be word aligned).
  399. * Output : None.
  400. * Return : None.
  401. *******************************************************************************/
  402. #define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1))
  403. #define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1))
  404. /*******************************************************************************
  405. * Macro Name : GetEPTxAddr / GetEPRxAddr.
  406. * Description : Gets address of the tx/rx buffer.
  407. * Input : bEpNum: Endpoint Number.
  408. * Output : None.
  409. * Return : address of the buffer.
  410. *******************************************************************************/
  411. #define _GetEPTxAddr(bEpNum) ((uint16_t)*_pEPTxAddr(bEpNum))
  412. #define _GetEPRxAddr(bEpNum) ((uint16_t)*_pEPRxAddr(bEpNum))
  413. /*******************************************************************************
  414. * Macro Name : SetEPCountRxReg.
  415. * Description : Sets counter of rx buffer with no. of blocks.
  416. * Input : pdwReg: pointer to counter.
  417. * wCount: Counter.
  418. * Output : None.
  419. * Return : None.
  420. *******************************************************************************/
  421. #define _BlocksOf32(dwReg,wCount,wNBlocks) {\
  422. wNBlocks = wCount >> 5;\
  423. if((wCount & 0x1f) == 0)\
  424. wNBlocks--;\
  425. *pdwReg = (uint32_t)((wNBlocks << 10) | 0x8000);\
  426. }/* _BlocksOf32 */
  427. #define _BlocksOf2(dwReg,wCount,wNBlocks) {\
  428. wNBlocks = wCount >> 1;\
  429. if((wCount & 0x1) != 0)\
  430. wNBlocks++;\
  431. *pdwReg = (uint32_t)(wNBlocks << 10);\
  432. }/* _BlocksOf2 */
  433. #define _SetEPCountRxReg(dwReg,wCount) {\
  434. uint16_t wNBlocks;\
  435. if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
  436. else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
  437. }/* _SetEPCountRxReg */
  438. #define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
  439. uint32_t *pdwReg = _pEPTxCount(bEpNum); \
  440. _SetEPCountRxReg(pdwReg, wCount);\
  441. }
  442. /*******************************************************************************
  443. * Macro Name : SetEPTxCount / SetEPRxCount.
  444. * Description : sets counter for the tx/rx buffer.
  445. * Input : bEpNum: endpoint number.
  446. * wCount: Counter value.
  447. * Output : None.
  448. * Return : None.
  449. *******************************************************************************/
  450. #define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount)
  451. #define _SetEPRxCount(bEpNum,wCount) {\
  452. uint32_t *pdwReg = _pEPRxCount(bEpNum); \
  453. _SetEPCountRxReg(pdwReg, wCount);\
  454. }
  455. /*******************************************************************************
  456. * Macro Name : GetEPTxCount / GetEPRxCount.
  457. * Description : gets counter of the tx buffer.
  458. * Input : bEpNum: endpoint number.
  459. * Output : None.
  460. * Return : Counter value.
  461. *******************************************************************************/
  462. #define _GetEPTxCount(bEpNum)((uint16_t)(*_pEPTxCount(bEpNum)) & 0x3ff)
  463. #define _GetEPRxCount(bEpNum)((uint16_t)(*_pEPRxCount(bEpNum)) & 0x3ff)
  464. /*******************************************************************************
  465. * Macro Name : SetEPDblBuf0Addr / SetEPDblBuf1Addr.
  466. * Description : Sets buffer 0/1 address in a double buffer endpoint.
  467. * Input : bEpNum: endpoint number.
  468. * : wBuf0Addr: buffer 0 address.
  469. * Output : None.
  470. * Return : None.
  471. *******************************************************************************/
  472. #define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);}
  473. #define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);}
  474. /*******************************************************************************
  475. * Macro Name : SetEPDblBuffAddr.
  476. * Description : Sets addresses in a double buffer endpoint.
  477. * Input : bEpNum: endpoint number.
  478. * : wBuf0Addr: buffer 0 address.
  479. * : wBuf1Addr = buffer 1 address.
  480. * Output : None.
  481. * Return : None.
  482. *******************************************************************************/
  483. #define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \
  484. _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\
  485. _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\
  486. } /* _SetEPDblBuffAddr */
  487. /*******************************************************************************
  488. * Macro Name : GetEPDblBuf0Addr / GetEPDblBuf1Addr.
  489. * Description : Gets buffer 0/1 address of a double buffer endpoint.
  490. * Input : bEpNum: endpoint number.
  491. * Output : None.
  492. * Return : None.
  493. *******************************************************************************/
  494. #define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum))
  495. #define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum))
  496. /*******************************************************************************
  497. * Macro Name : SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count.
  498. * Description : Gets buffer 0/1 address of a double buffer endpoint.
  499. * Input : bEpNum: endpoint number.
  500. * : bDir: endpoint dir EP_DBUF_OUT = OUT
  501. * EP_DBUF_IN = IN
  502. * : wCount: Counter value
  503. * Output : None.
  504. * Return : None.
  505. *******************************************************************************/
  506. #define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \
  507. if(bDir == EP_DBUF_OUT)\
  508. /* OUT endpoint */ \
  509. {_SetEPRxDblBuf0Count(bEpNum,wCount);} \
  510. else if(bDir == EP_DBUF_IN)\
  511. /* IN endpoint */ \
  512. *_pEPTxCount(bEpNum) = (uint32_t)wCount; \
  513. } /* SetEPDblBuf0Count*/
  514. #define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \
  515. if(bDir == EP_DBUF_OUT)\
  516. /* OUT endpoint */ \
  517. {_SetEPRxCount(bEpNum,wCount);}\
  518. else if(bDir == EP_DBUF_IN)\
  519. /* IN endpoint */\
  520. *_pEPRxCount(bEpNum) = (uint32_t)wCount; \
  521. } /* SetEPDblBuf1Count */
  522. #define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\
  523. _SetEPDblBuf0Count(bEpNum, bDir, wCount); \
  524. _SetEPDblBuf1Count(bEpNum, bDir, wCount); \
  525. } /* _SetEPDblBuffCount */
  526. /*******************************************************************************
  527. * Macro Name : GetEPDblBuf0Count / GetEPDblBuf1Count.
  528. * Description : Gets buffer 0/1 rx/tx counter for double buffering.
  529. * Input : bEpNum: endpoint number.
  530. * Output : None.
  531. * Return : None.
  532. *******************************************************************************/
  533. #define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum))
  534. #define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum))
  535. /* External variables --------------------------------------------------------*/
  536. extern __IO uint16_t wIstr; /* ISTR register last read value */
  537. /* Exported functions ------------------------------------------------------- */
  538. void SetCNTR(uint16_t /*wRegValue*/);
  539. void SetISTR(uint16_t /*wRegValue*/);
  540. void SetDADDR(uint16_t /*wRegValue*/);
  541. void SetBTABLE(uint16_t /*wRegValue*/);
  542. void SetBTABLE(uint16_t /*wRegValue*/);
  543. uint16_t GetCNTR(void);
  544. uint16_t GetISTR(void);
  545. uint16_t GetFNR(void);
  546. uint16_t GetDADDR(void);
  547. uint16_t GetBTABLE(void);
  548. void SetENDPOINT(uint8_t /*bEpNum*/, uint16_t /*wRegValue*/);
  549. uint16_t GetENDPOINT(uint8_t /*bEpNum*/);
  550. void SetEPType(uint8_t /*bEpNum*/, uint16_t /*wType*/);
  551. uint16_t GetEPType(uint8_t /*bEpNum*/);
  552. void SetEPTxStatus(uint8_t /*bEpNum*/, uint16_t /*wState*/);
  553. void SetEPRxStatus(uint8_t /*bEpNum*/, uint16_t /*wState*/);
  554. void SetDouBleBuffEPStall(uint8_t /*bEpNum*/, uint8_t bDir);
  555. uint16_t GetEPTxStatus(uint8_t /*bEpNum*/);
  556. uint16_t GetEPRxStatus(uint8_t /*bEpNum*/);
  557. void SetEPTxValid(uint8_t /*bEpNum*/);
  558. void SetEPRxValid(uint8_t /*bEpNum*/);
  559. uint16_t GetTxStallStatus(uint8_t /*bEpNum*/);
  560. uint16_t GetRxStallStatus(uint8_t /*bEpNum*/);
  561. void SetEP_KIND(uint8_t /*bEpNum*/);
  562. void ClearEP_KIND(uint8_t /*bEpNum*/);
  563. void Set_Status_Out(uint8_t /*bEpNum*/);
  564. void Clear_Status_Out(uint8_t /*bEpNum*/);
  565. void SetEPDoubleBuff(uint8_t /*bEpNum*/);
  566. void ClearEPDoubleBuff(uint8_t /*bEpNum*/);
  567. void ClearEP_CTR_RX(uint8_t /*bEpNum*/);
  568. void ClearEP_CTR_TX(uint8_t /*bEpNum*/);
  569. void ToggleDTOG_RX(uint8_t /*bEpNum*/);
  570. void ToggleDTOG_TX(uint8_t /*bEpNum*/);
  571. void ClearDTOG_RX(uint8_t /*bEpNum*/);
  572. void ClearDTOG_TX(uint8_t /*bEpNum*/);
  573. void SetEPAddress(uint8_t /*bEpNum*/, uint8_t /*bAddr*/);
  574. uint8_t GetEPAddress(uint8_t /*bEpNum*/);
  575. void SetEPTxAddr(uint8_t /*bEpNum*/, uint16_t /*wAddr*/);
  576. void SetEPRxAddr(uint8_t /*bEpNum*/, uint16_t /*wAddr*/);
  577. uint16_t GetEPTxAddr(uint8_t /*bEpNum*/);
  578. uint16_t GetEPRxAddr(uint8_t /*bEpNum*/);
  579. void SetEPCountRxReg(uint32_t * /*pdwReg*/, uint16_t /*wCount*/);
  580. void SetEPTxCount(uint8_t /*bEpNum*/, uint16_t /*wCount*/);
  581. void SetEPRxCount(uint8_t /*bEpNum*/, uint16_t /*wCount*/);
  582. uint16_t GetEPTxCount(uint8_t /*bEpNum*/);
  583. uint16_t GetEPRxCount(uint8_t /*bEpNum*/);
  584. void SetEPDblBuf0Addr(uint8_t /*bEpNum*/, uint16_t /*wBuf0Addr*/);
  585. void SetEPDblBuf1Addr(uint8_t /*bEpNum*/, uint16_t /*wBuf1Addr*/);
  586. void SetEPDblBuffAddr(uint8_t /*bEpNum*/, uint16_t /*wBuf0Addr*/, uint16_t /*wBuf1Addr*/);
  587. uint16_t GetEPDblBuf0Addr(uint8_t /*bEpNum*/);
  588. uint16_t GetEPDblBuf1Addr(uint8_t /*bEpNum*/);
  589. void SetEPDblBuffCount(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/);
  590. void SetEPDblBuf0Count(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/);
  591. void SetEPDblBuf1Count(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/);
  592. uint16_t GetEPDblBuf0Count(uint8_t /*bEpNum*/);
  593. uint16_t GetEPDblBuf1Count(uint8_t /*bEpNum*/);
  594. EP_DBUF_DIR GetEPDblBufDir(uint8_t /*bEpNum*/);
  595. void FreeUserBuffer(uint8_t bEpNum/*bEpNum*/, uint8_t bDir);
  596. uint16_t ToWord(uint8_t, uint8_t);
  597. uint16_t ByteSwap(uint16_t);
  598. #endif /* STM32F10X_CL */
  599. #endif /* __USB_REGS_H */
  600. /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/