GD32F10x USB-Device: E:/USB Libraries/GD32_USB_Device_Driver/inc/usb_regs.h Source File

GD32F103 Firmware

usb_regs.h
Go to the documentation of this file.
1 
11 /* Define to prevent recursive inclusion -------------------------------------*/
12 #ifndef __GD32F10X_USB_REGS_H
13 #define __GD32F10X_USB_REGS_H
14 
15 /* Includes ------------------------------------------------------------------*/
16 #include "usb_conf.h"
17 
38 {
39  USB_SPEED_LOW,
40  USB_SPEED_FULL
41 };
42 
46 typedef enum _DBUF_EP_DIR
47 {
48  DBUF_EP_IN,
49  DBUF_EP_OUT,
50  DBUF_EP_ERR,
51 }
53 
61 #define REG_BASE (0x40005C00L)
62 #define PBA_ADDR (0x40006000L)
71 #define CTLR ((__IO unsigned *)(REG_BASE + 0x40))
72 #define IFR ((__IO unsigned *)(REG_BASE + 0x44))
73 #define SR ((__IO unsigned *)(REG_BASE + 0x48))
74 #define AR ((__IO unsigned *)(REG_BASE + 0x4C))
75 #define BAR ((__IO unsigned *)(REG_BASE + 0x50))
84 #define EP0CSR ((__IO unsigned *)(REG_BASE))
97 #define EP0_OUT ((uint8_t)0x00)
98 #define EP0_IN ((uint8_t)0x80)
99 #define EP1_OUT ((uint8_t)0x01)
100 #define EP1_IN ((uint8_t)0x81)
101 #define EP2_OUT ((uint8_t)0x02)
102 #define EP2_IN ((uint8_t)0x82)
103 #define EP3_OUT ((uint8_t)0x03)
104 #define EP3_IN ((uint8_t)0x83)
105 #define EP4_OUT ((uint8_t)0x04)
106 #define EP4_IN ((uint8_t)0x84)
107 #define EP5_OUT ((uint8_t)0x05)
108 #define EP5_IN ((uint8_t)0x85)
109 #define EP6_OUT ((uint8_t)0x06)
110 #define EP6_IN ((uint8_t)0x86)
111 #define EP7_OUT ((uint8_t)0x07)
112 #define EP7_IN ((uint8_t)0x87)
113 
121 #define EP0 ((uint8_t)0)
122 #define EP1 ((uint8_t)1)
123 #define EP2 ((uint8_t)2)
124 #define EP3 ((uint8_t)3)
125 #define EP4 ((uint8_t)4)
126 #define EP5 ((uint8_t)5)
127 #define EP6 ((uint8_t)6)
128 #define EP7 ((uint8_t)7)
129 
141 #define CTLR_STIE (0x8000)
142 #define CTLR_PMOUIE (0x4000)
143 #define CTLR_ERRIE (0x2000)
144 #define CTLR_WKUPIE (0x1000)
145 #define CTLR_SPSIE (0x0800)
146 #define CTLR_RSTIE (0x0400)
147 #define CTLR_SOFIE (0x0200)
148 #define CTLR_ESOFIE (0x0100)
149 #define CTLR_RSREQ (0x0010)
150 #define CTLR_SETSPS (0x0008)
151 #define CTLR_LOWM (0x0004)
152 #define CTLR_CLOSE (0x0002)
153 #define CTLR_SETRST (0x0001)
158 #define IFR_STIF (0x8000)
159 #define IFR_PMOUIF (0x4000)
160 #define IFR_ERRIF (0x2000)
161 #define IFR_WKUPIF (0x1000)
162 #define IFR_SPSIF (0x0800)
163 #define IFR_RSTIF (0x0400)
164 #define IFR_SOFIF (0x0200)
165 #define IFR_ESOFIF (0x0100)
166 #define IFR_DIR (0x0010)
167 #define IFR_EPNUM (0x000F)
169 #define CLR_STIF (~IFR_STIF)
170 #define CLR_PMOUIF (~IFR_PMOUIF)
171 #define CLR_ERRIF (~IFR_ERRIF)
172 #define CLR_WKUPIF (~IFR_WKUPIF)
173 #define CLR_SPSIF (~IFR_SPSIF)
174 #define CLR_RSTIF (~IFR_RSTIF)
175 #define CLR_SOFIF (~IFR_SOFIF)
176 #define CLR_ESOFIF (~IFR_ESOFIF)
181 #define SR_RXDP (0x8000)
182 #define SR_RXDM (0x4000)
183 #define SR_LOCK (0x2000)
184 #define SR_SOFLN (0x1800)
185 #define SR_FCNT (0x07FF)
190 #define AR_USBEN (0x80)
191 #define AR_USBADDR (0x7F)
196 #define EPRX_ST (0x8000)
197 #define EPRX_DTG (0x4000)
198 #define EPRX_STA (0x3000)
199 #define EP_SETUP (0x0800)
200 #define EP_CTL (0x0600)
201 #define EP_KCTL (0x0100)
202 #define EPTX_ST (0x0080)
203 #define EPTX_DTG (0x0040)
204 #define EPTX_STA (0x0030)
205 #define EP_AR (0x000F)
210 #define EPCSR_MASK (EPRX_ST|EP_SETUP|EP_CTL|EP_KCTL|EPTX_ST|EP_AR)
211 
215 #define EP_BULK (0x0000)
216 #define EP_CONTROL (0x0200)
217 #define EP_ISO (0x0400)
218 #define EP_INTERRUPT (0x0600)
219 #define EP_CTL_MASK (~EP_CTL & EPCSR_MASK)
220 
224 #define EPKCTL_MASK (~EP_KCTL & EPCSR_MASK)
225 
229 #define EPTX_DISABLED (0x0000)
230 #define EPTX_STALL (0x0010)
231 #define EPTX_NAK (0x0020)
232 #define EPTX_VALID (0x0030)
233 #define EPTX_DTGMASK (EPTX_STA | EPCSR_MASK)
234 
238 #define EPRX_DISABLED (0x0000)
239 #define EPRX_STALL (0x1000)
240 #define EPRX_NAK (0x2000)
241 #define EPRX_VALID (0x3000)
242 #define EPRX_DTGMASK (EPRX_STA | EPCSR_MASK)
243 
247 #define EPRXCNTR_BLKSIZ (0x8000)
248 #define EPRXCNTR_BLKNUM (0x7C00)
249 #define EPRXCNTR_CNT (0x03FF)
250 
251 #define EPTXCNTR_CNT (0x03FF)
252 
256 #define BLKSIZE_OFFSET (0x01)
257 #define BLKNUM_OFFSET (0x05)
258 #define RXCNT_OFFSET (0x0A)
259 
260 #define TXCNT_OFFSET (0x0A)
261 
262 #define BLKSIZE32_MASK (0x1f)
263 #define BLKSIZE2_MASK (0x01)
264 
265 #define BLKSIZE32_OFFSETMASK (0x05)
266 #define BLKSIZE2_OFFSETMASK (0x01)
267 
280 /* Set CTLR */
281 #define _SetCTLR(RegValue) (*CTLR = (uint16_t)RegValue)
282 
283 /* Get CTLR */
284 #define _GetCTLR() ((uint16_t) *CTLR)
285 
286 /* Set IFR */
287 #define _SetIFR(RegValue) (*IFR = (uint16_t)RegValue)
288 
289 /* Get IFR */
290 #define _GetIFR() ((uint16_t) *IFR)
291 
292 /* Set AR */
293 #define _SetAR(RegValue) (*AR = (uint16_t)RegValue)
294 
295 /* Get AR */
296 #define _GetAR() ((uint16_t) *AR)
297 
298 /* Set BAR */
299 #define _SetBAR(RegValue) (*BAR = (uint16_t)(RegValue & 0xFFF8))
300 
301 /* Get BAR */
302 #define _GetBAR() ((uint16_t) *BAR)
303 
304 /* Get SR */
305 #define _GetSR() ((uint16_t) *SR)
306 
307 /* Set EPxCSR */
308 #define _SetEPxCSR(EpID,RegValue) (*(EP0CSR + EpID) = (uint16_t)RegValue)
309 
310 /* Get EPxCSR*/
311 #define _GetEPxCSR(EpID) ((uint16_t)(*(EP0CSR + EpID)))
312 
327 #define _SetEPType(EpID, Type) (_SetEPxCSR(EpID, ((_GetEPxCSR(EpID) & EP_CTL_MASK) | Type)))
328 
329 #define _GetEPType(EpID) (_GetEPxCSR(EpID) & EP_CTL)
330 
331 
338 #define _SetEPTxStatus(EpID, State) {\
339  register uint16_t _RegVal; \
340  _RegVal = _GetEPxCSR(EpID) & EPTX_DTGMASK;\
341  _SetEPxCSR(EpID, (_RegVal ^ State)); \
342 }
343 
344 #define _GetEPTxStatus(EpID) ((uint16_t)_GetEPxCSR(EpID) & EPTX_STA)
345 
352 #define _SetEPRxStatus(EpID, State) {\
353  register uint16_t _RegVal; \
354  _RegVal = _GetEPxCSR(EpID) & EPRX_DTGMASK;\
355  _SetEPxCSR(EpID, (_RegVal ^ State)); \
356 }
357 
358 #define _GetEPRxStatus(EpID) ((uint16_t)_GetEPxCSR(EpID) & EPRX_STA)
359 
367 #define _SetEPRxTxStatus(EpID, StateRx, StateTx) {\
368  register uint16_t _RegVal; \
369  _RegVal = _GetEPxCSR(EpID) & (EPRX_DTGMASK | EPTX_STA) ;\
370  _SetEPxCSR(EpID, ((_RegVal ^ StateRx) ^ StateTx)); \
371 }
372 
378 #define _SetEP_KIND(EpID) (_SetEPxCSR(EpID, ((_GetEPxCSR(EpID) | EP_KCTL) & EPCSR_MASK)))
379 
380 #define _ClearEP_KIND(EpID) (_SetEPxCSR(EpID, (_GetEPxCSR(EpID) & EPKCTL_MASK)))
381 
387 #define _Set_Status_Out(EpID) _SetEP_KIND(EpID)
388 
389 #define _Clear_Status_Out(EpID) _ClearEP_KIND(EpID)
390 
396 #define _SetEPDoubleBuff(EpID) _SetEP_KIND(EpID)
397 
398 #define _ClearEPDoubleBuff(EpID) _ClearEP_KIND(EpID)
399 
405 #define _ClearEPRX_ST(EpID) (_SetEPxCSR(EpID, _GetEPxCSR(EpID) & 0x7FFF & EPCSR_MASK))
406 
407 #define _ClearEPTX_ST(EpID) (_SetEPxCSR(EpID, _GetEPxCSR(EpID) & 0xFF7F & EPCSR_MASK))
408 
414 #define _ToggleDTG_RX(EpID) (_SetEPxCSR(EpID, EPRX_DTG | (_GetEPxCSR(EpID) & EPCSR_MASK)))
415 
416 #define _ClearDTG_RX(EpID) if((_GetEPxCSR(EpID) & EPRX_DTG) != 0) _ToggleDTG_RX(EpID)
417 
423 #define _ToggleDTG_TX(EpID) (_SetEPxCSR(EpID, EPTX_DTG | (_GetEPxCSR(EpID) & EPCSR_MASK)))
424 
425 #define _ClearDTG_TX(EpID) if((_GetEPxCSR(EpID) & EPTX_DTG) != 0) _ToggleDTG_TX(EpID)
426 
432 #define _ToggleSWBUF_TX(EpID) _ToggleDTG_RX(EpID)
433 
434 #define _ToggleSWBUF_RX(EpID) _ToggleDTG_TX(EpID)
435 
442 #define _SetEPAddress(EpID,Addr) _SetEPxCSR(EpID, (_GetEPxCSR(EpID) & EPCSR_MASK) | Addr)
443 
444 #define _GetEPAddress(EpID) ((uint8_t)(_GetEPxCSR(EpID) & EP_AR))
445 
451 #define _GetEPTXARn(EpID) ((uint32_t *)((_GetBAR() + EpID * 8) * 2 + PBA_ADDR))
452 
458 #define _GetEPTXCNTx(EpID) ((uint32_t *)((_GetBAR() + EpID * 8 + 2) * 2 + PBA_ADDR))
459 
465 #define _GetEPRXARn(EpID) ((uint32_t *)((_GetBAR() + EpID * 8 + 4) * 2 + PBA_ADDR))
466 
472 #define _GetEPRXCNTx(EpID) ((uint32_t *)((_GetBAR() + EpID * 8 + 6) * 2 + PBA_ADDR))
473 
480 #define _SetEPTxAddr(EpID, Addr) (*_GetEPTXARn(EpID) = (Addr & ~((uint16_t)1)))
481 #define _SetEPRxAddr(EpID, Addr) (*_GetEPRXARn(EpID) = (Addr & ~((uint16_t)1)))
482 
488 #define _GetEPTxAddr(EpID) ((uint16_t)*_GetEPTXARn(EpID))
489 #define _GetEPRxAddr(EpID) ((uint16_t)*_GetEPRXARn(EpID))
490 
497 #define _BlocksOf32(pdwReg, Count) {\
498  register uint16_t BlockNum = Count >> BLKSIZE32_OFFSETMASK;\
499  if((Count & BLKSIZE32_MASK) == 0)\
500  BlockNum--;\
501  *pdwReg = (uint32_t)((BlockNum << RXCNT_OFFSET) | EPRXCNTR_BLKSIZ);\
502 }
503 
510 #define _BlocksOf2(pdwReg, Count) {\
511  register uint16_t BlockNum = Count >> BLKSIZE2_OFFSETMASK;\
512  if((Count & BLKSIZE2_MASK) != 0)\
513  BlockNum++;\
514  *pdwReg = (uint32_t)(BlockNum << RXCNT_OFFSET);\
515 }
516 
523 #define _SetEPRxDblBuf0Count(EpID, Count) {\
524  uint32_t *pdwReg = _GetEPTXCNTx(EpID); \
525  if(Count > 62) { _BlocksOf32(pdwReg, Count); } \
526  else { _BlocksOf32(pdwReg, Count); } \
527 }
528 
535 #define _SetEPTxCount(EpID, Count) (*_GetEPTXCNTx(EpID) = Count)
536 #define _SetEPRxCount(EpID, Count) {\
537  uint32_t *pdwReg = _GetEPRXCNTx(EpID); \
538  if(Count > 62) { _BlocksOf32(pdwReg, Count); } \
539  else { _BlocksOf2(pdwReg, Count); } \
540 }
541 
547 #define _GetEPTxCount(EpID)((uint16_t) (*_GetEPTXCNTx(EpID)) & EPTXCNTR_CNT)
548 #define _GetEPRxCount(EpID)((uint16_t) (*_GetEPRXCNTx(EpID)) & EPRXCNTR_CNT)
549 
557 #define _SetEPDblBuf0Addr(EpID, Buf0Addr) {_SetEPTxAddr(EpID, Buf0Addr);}
558 #define _SetEPDblBuf1Addr(EpID, Buf1Addr) {_SetEPRxAddr(EpID, Buf1Addr);}
559 
567 #define _SetEPDblBufAddr(EpID, Buf0Addr, Buf1Addr) { \
568  _SetEPDblBuf0Addr(EpID, Buf0Addr);\
569  _SetEPDblBuf1Addr(EpID, Buf1Addr);\
570 }
571 
577 #define _GetEPDblBuf0Addr(EpID) (_GetEPTxAddr(EpID))
578 #define _GetEPDblBuf1Addr(EpID) (_GetEPRxAddr(EpID))
579 
589 #define _SetEPDblBuf0Count(EpID, Dir, Count) { \
590  if(Dir == DBUF_EP_OUT)\
591  {_SetEPRxDblBuf0Count(EpID, Count);} \
592  else if(Dir == DBUF_EP_IN)\
593  {*_GetEPTXCNTx(EpID) = (uint32_t)Count;} \
594 }
595 
596 #define _SetEPDblBuf1Count(EpID, Dir, Count) { \
597  if(Dir == DBUF_EP_OUT)\
598  {_SetEPRxCount(EpID, Count);}\
599  else if(Dir == DBUF_EP_IN)\
600  {*_GetEPRXCNTx(EpID) = (uint32_t)Count;} \
601 }
602 
603 #define _SetEPDblBuffCount(EpID, Dir, Count) {\
604  _SetEPDblBuf0Count(EpID, Dir, Count); \
605  _SetEPDblBuf1Count(EpID, Dir, Count); \
606 }
607 
613 #define _GetEPDblBuf0Count(EpID) (_GetEPTxCount(EpID))
614 #define _GetEPDblBuf1Count(EpID) (_GetEPRxCount(EpID))
615 
622 #define _SetDouBleBuffEPStall(EpID, Dir) {\
623  if (Dir == DBUF_EP_OUT) \
624  { \
625  _SetEPxCSR(EpID, _GetEPxCSR(EpID) & ~EPRX_STALL); \
626  } \
627  else if (Dir == DBUF_EP_IN) \
628  { \
629  _SetEPxCSR(EpID, _GetEPxCSR(EpID) & ~EPTX_STALL); \
630  } \
631 }
632 
641 #endif /* __GD32F10X_USB_REGS_H */
642 
655 /************************ (C) COPYRIGHT 2014 GIGADEVICE *****END OF FILE****/
_DBUF_EP_DIR
USB double buffer endpoint direction.
Definition: usb_regs.h:46
USB_SPEED
USB device speed.
Definition: usb_regs.h:37
enum _DBUF_EP_DIR DBUF_EP_DIR
USB double buffer endpoint direction.
Generated on Fri Feb 6 2015 14:56:35 for GD32F10x USB-Device by   doxygen 1.8.8