GD32F1x0: USB_Operation_Macros

GD32F1x0

Macros

#define _SetEPType(EpID, Type)    (_SetEPxCSR(EpID, ((_GetEPxCSR(EpID) & EP_CTL_MASK) | Type)))
 Endpoint type setting and getting(bits EP_CTL[1:0] in endpoint control and status register) More...
 
#define _GetEPType(EpID)    (_GetEPxCSR(EpID) & EP_CTL)
 
#define _SetEPTxStatus(EpID, State)
 Tx transfer status setting and getting (bits EPTX_STA[1:0]) More...
 
#define _GetEPTxStatus(EpID)    ((uint16_t)_GetEPxCSR(EpID) & EPTX_STA)
 
#define _SetEPRxStatus(EpID, State)
 Rx transfer status setting and getting (bits EPRX_STA[1:0]) More...
 
#define _GetEPRxStatus(EpID)    ((uint16_t)_GetEPxCSR(EpID) & EPRX_STA)
 
#define _SetEPRxTxStatus(EpID, StateRx, StateTx)
 Rx and Tx transfer status setting (bits EPRX_STA[1:0] & EPTX_STA[1:0]) More...
 
#define _SetEP_KIND(EpID)    (_SetEPxCSR(EpID, ((_GetEPxCSR(EpID) | EP_KCTL) & EPCSR_MASK)))
 Set and Clear endpoint kind (bit EP_KCTL). More...
 
#define _ClearEP_KIND(EpID)    (_SetEPxCSR(EpID, (_GetEPxCSR(EpID) & EPKCTL_MASK)))
 
#define _Set_Status_Out(EpID)    _SetEP_KIND(EpID)
 Set and Clear directly STATUS_OUT state of endpoint. More...
 
#define _Clear_Status_Out(EpID)    _ClearEP_KIND(EpID)
 
#define _SetEPDoubleBuff(EpID)    _SetEP_KIND(EpID)
 Set and Clear directly double buffered feature of endpoint. More...
 
#define _ClearEPDoubleBuff(EpID)    _ClearEP_KIND(EpID)
 
#define _ClearEPRX_ST(EpID)    (_SetEPxCSR(EpID, _GetEPxCSR(EpID) & 0x7FFF & EPCSR_MASK))
 Clear bit EPRX_ST / EPTX_ST in the endpoint control and status register. More...
 
#define _ClearEPTX_ST(EpID)    (_SetEPxCSR(EpID, _GetEPxCSR(EpID) & 0xFF7F & EPCSR_MASK))
 
#define _ToggleDTG_RX(EpID)    (_SetEPxCSR(EpID, EPRX_DTG | (_GetEPxCSR(EpID) & EPCSR_MASK)))
 Toggle and Clear EPRX_DTG bit in the endpoint control and status register. More...
 
#define _ClearDTG_RX(EpID)    if((_GetEPxCSR(EpID) & EPRX_DTG) != 0) _ToggleDTG_RX(EpID)
 
#define _ToggleDTG_TX(EpID)    (_SetEPxCSR(EpID, EPTX_DTG | (_GetEPxCSR(EpID) & EPCSR_MASK)))
 Toggle and Clear EPTX_DTG bit in the endpoint control and status register. More...
 
#define _ClearDTG_TX(EpID)    if((_GetEPxCSR(EpID) & EPTX_DTG) != 0) _ToggleDTG_TX(EpID)
 
#define _ToggleSWBUF_TX(EpID)    _ToggleDTG_RX(EpID)
 Toggle SW_BUF bit in the double buffered endpoint. More...
 
#define _ToggleSWBUF_RX(EpID)    _ToggleDTG_TX(EpID)
 
#define _SetEPAddress(EpID, Addr)    _SetEPxCSR(EpID, (_GetEPxCSR(EpID) & EPCSR_MASK) | Addr)
 Set and Get endpoint address. More...
 
#define _GetEPAddress(EpID)    ((uint8_t)(_GetEPxCSR(EpID) & EP_AR))
 
#define _GetEPTXARn(EpID)    ((uint32_t *)((_GetBAR() + EpID * 8) * 2 + PBA_Addr))
 Get endpoint transmission buffer address. More...
 
#define _GetEPTXCNTx(EpID)    ((uint32_t *)((_GetBAR() + EpID * 8 + 2) * 2 + PBA_Addr))
 Get endpoint transmission byte count. More...
 
#define _GetEPRXARn(EpID)    ((uint32_t *)((_GetBAR() + EpID * 8 + 4) * 2 + PBA_Addr))
 Get endpoint reception buffer address. More...
 
#define _GetEPRXCNTx(EpID)    ((uint32_t *)((_GetBAR() + EpID * 8 + 6) * 2 + PBA_Addr))
 Get endpoint reception byte count. More...
 
#define _SetEPTxAddr(EpID, Addr)    (*_GetEPTXARn(EpID) = (Addr & ~((uint16_t)1)))
 Set Tx/Rx buffer address. More...
 
#define _SetEPRxAddr(EpID, Addr)    (*_GetEPRXARn(EpID) = (Addr & ~((uint16_t)1)))
 
#define _GetEPTxAddr(EpID)    ((uint16_t)*_GetEPTXARn(EpID))
 Get Tx/Rx buffer address. More...
 
#define _GetEPRxAddr(EpID)    ((uint16_t)*_GetEPRXARn(EpID))
 
#define _BlocksOf32(pdwReg, Count)
 Set the reception buffer byte count register when 1 block is 32 bytes. More...
 
#define _BlocksOf2(pdwReg, Count)
 Set the reception buffer byte count register when 1 block is 2 bytes. More...
 
#define _SetEPRxDblBuf0Count(EpID, Count)
 Set buffer0 reception byte count when use double buffer. More...
 
#define _SetEPTxCount(EpID, Count)    (*_GetEPTXCNTx(EpID) = Count)
 Set Tx/Rx buffer byte count. More...
 
#define _SetEPRxCount(EpID, Count)
 
#define _GetEPTxCount(EpID)   ((uint16_t) (*_GetEPTXCNTx(EpID)) & EPTXCNTR_CNT)
 Get Tx/Rx buffer byte count. More...
 
#define _GetEPRxCount(EpID)   ((uint16_t) (*_GetEPRXCNTx(EpID)) & EPRXCNTR_CNT)
 
#define _SetEPDblBuf0Addr(EpID, Buf0Addr)   {_SetEPTxAddr(EpID, Buf0Addr);}
 Sets buffer 0/1 address when use double buffer. More...
 
#define _SetEPDblBuf1Addr(EpID, Buf1Addr)   {_SetEPRxAddr(EpID, Buf1Addr);}
 
#define _SetEPDblBufAddr(EpID, Buf0Addr, Buf1Addr)
 Sets a double buffer endpoint addresses. More...
 
#define _GetEPDblBuf0Addr(EpID)    (_GetEPTxAddr(EpID))
 Get a double buffer endpoint buffer 0/1 address. More...
 
#define _GetEPDblBuf1Addr(EpID)    (_GetEPRxAddr(EpID))
 
#define _SetEPDblBuf0Count(EpID, Dir, Count)
 Set buffer 0/1 byte count register in a double buffer endpoint. More...
 
#define _SetEPDblBuf1Count(EpID, Dir, Count)
 
#define _SetEPDblBuffCount(EpID, Dir, Count)
 
#define _GetEPDblBuf0Count(EpID)    (_GetEPTxCount(EpID))
 Get buffer 0/1 byte count. More...
 
#define _GetEPDblBuf1Count(EpID)    (_GetEPRxCount(EpID))
 
#define _SetDouBleBuffEPStall(EpID, Dir)
 Set double buffer endpoint status to STALL. More...
 

Detailed Description

Macro Definition Documentation

#define _BlocksOf2 (   pdwReg,
  Count 
)
Value:
{\
register uint16_t BlockNum = Count >> BLKSIZE2_OFFSETMASK;\
if((Count & BLKSIZE2_MASK) != 0)\
BlockNum++;\
*pdwReg = (uint32_t)(BlockNum << RXCNT_OFFSET);\
}

Set the reception buffer byte count register when 1 block is 2 bytes.

Parameters
pdwRegreception buffer byte count register
Countbyte count value
Return values
None

Definition at line 594 of file usb_regs.h.

#define _BlocksOf32 (   pdwReg,
  Count 
)
Value:
{\
register uint16_t BlockNum = Count >> BLKSIZE32_OFFSETMASK;\
if((Count & BLKSIZE32_MASK) == 0)\
BlockNum--;\
*pdwReg = (uint32_t)((BlockNum << RXCNT_OFFSET) | EPRXCNTR_BLKSIZ);\
}
#define EPRXCNTR_BLKSIZ
Endpoint receive/transmission counter register bit definitions.
Definition: usb_regs.h:288

Set the reception buffer byte count register when 1 block is 32 bytes.

Parameters
pdwRegreception buffer byte count register
Countbyte count value
Return values
None

Definition at line 581 of file usb_regs.h.

#define _ClearEPRX_ST (   EpID)    (_SetEPxCSR(EpID, _GetEPxCSR(EpID) & 0x7FFF & EPCSR_MASK))

Clear bit EPRX_ST / EPTX_ST in the endpoint control and status register.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 489 of file usb_regs.h.

#define _GetEPDblBuf0Addr (   EpID)    (_GetEPTxAddr(EpID))

Get a double buffer endpoint buffer 0/1 address.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 661 of file usb_regs.h.

#define _GetEPDblBuf0Count (   EpID)    (_GetEPTxCount(EpID))

Get buffer 0/1 byte count.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
bufferbyte count

Definition at line 698 of file usb_regs.h.

#define _GetEPRXARn (   EpID)    ((uint32_t *)((_GetBAR() + EpID * 8 + 4) * 2 + PBA_Addr))

Get endpoint reception buffer address.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 549 of file usb_regs.h.

#define _GetEPRXCNTx (   EpID)    ((uint32_t *)((_GetBAR() + EpID * 8 + 6) * 2 + PBA_Addr))

Get endpoint reception byte count.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 556 of file usb_regs.h.

#define _GetEPTxAddr (   EpID)    ((uint16_t)*_GetEPTXARn(EpID))

Get Tx/Rx buffer address.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
Addressof the buffer

Definition at line 572 of file usb_regs.h.

#define _GetEPTXARn (   EpID)    ((uint32_t *)((_GetBAR() + EpID * 8) * 2 + PBA_Addr))

Get endpoint transmission buffer address.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 535 of file usb_regs.h.

#define _GetEPTXCNTx (   EpID)    ((uint32_t *)((_GetBAR() + EpID * 8 + 2) * 2 + PBA_Addr))

Get endpoint transmission byte count.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 542 of file usb_regs.h.

#define _GetEPTxCount (   EpID)    ((uint16_t) (*_GetEPTXCNTx(EpID)) & EPTXCNTR_CNT)

Get Tx/Rx buffer byte count.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
Bytecount value

Definition at line 631 of file usb_regs.h.

#define _Set_Status_Out (   EpID)    _SetEP_KIND(EpID)

Set and Clear directly STATUS_OUT state of endpoint.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 471 of file usb_regs.h.

#define _SetDouBleBuffEPStall (   EpID,
  Dir 
)
Value:
{\
if (Dir == DBUF_EP_OUT) \
{ \
_SetEPxCSR(EpID, _GetEPxCSR(EpID) & ~EPRX_STALL); \
} \
else if (Dir == DBUF_EP_IN) \
{ \
_SetEPxCSR(EpID, _GetEPxCSR(EpID) & ~EPTX_STALL); \
} \
}
#define EPTX_STALL
Definition: usb_regs.h:271
#define EPRX_STALL
Definition: usb_regs.h:280

Set double buffer endpoint status to STALL.

Parameters
EpIDendpoint identifier which is in (0..7)
Direndpoint direction This parameter can be any one of the following values:
  • DBUF_EP_OUT: OUT direction
  • DBUF_EP_IN: IN direction
Return values
None

Definition at line 710 of file usb_regs.h.

#define _SetEP_KIND (   EpID)    (_SetEPxCSR(EpID, ((_GetEPxCSR(EpID) | EP_KCTL) & EPCSR_MASK)))

Set and Clear endpoint kind (bit EP_KCTL).

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 462 of file usb_regs.h.

#define _SetEPAddress (   EpID,
  Addr 
)    _SetEPxCSR(EpID, (_GetEPxCSR(EpID) & EPCSR_MASK) | Addr)

Set and Get endpoint address.

Parameters
EpIDendpoint identifier which is in (0..7)
Addrendpoint address
Return values
None

Definition at line 526 of file usb_regs.h.

#define _SetEPDblBuf0Addr (   EpID,
  Buf0Addr 
)    {_SetEPTxAddr(EpID, Buf0Addr);}

Sets buffer 0/1 address when use double buffer.

Parameters
EpIDendpoint identifier which is in (0..7)
Buf0Addrbuffer0 address
Buf1Addrbuffer1 address
Return values
None

Definition at line 641 of file usb_regs.h.

#define _SetEPDblBuf0Count (   EpID,
  Dir,
  Count 
)
Value:
{ \
if(Dir == DBUF_EP_OUT)\
{_SetEPRxDblBuf0Count(EpID, Count);} \
else if(Dir == DBUF_EP_IN)\
{*_GetEPTXCNTx(EpID) = (uint32_t)Count;} \
}
#define _GetEPTXCNTx(EpID)
Get endpoint transmission byte count.
Definition: usb_regs.h:542
#define _SetEPRxDblBuf0Count(EpID, Count)
Set buffer0 reception byte count when use double buffer.
Definition: usb_regs.h:607

Set buffer 0/1 byte count register in a double buffer endpoint.

Parameters
EpIDendpoint identifier which is in (0..7)
Direndpoint direction This parameter can be any one of the following values:
  • DBUF_EP_OUT = OUT
  • DBUF_EP_IN = IN
Countbyte count value
Return values
None

Definition at line 674 of file usb_regs.h.

#define _SetEPDblBuf1Count (   EpID,
  Dir,
  Count 
)
Value:
{ \
if(Dir == DBUF_EP_OUT)\
{_SetEPRxCount(EpID, Count);}\
else if(Dir == DBUF_EP_IN)\
{*_GetEPRXCNTx(EpID) = (uint32_t)Count;} \
}
#define _GetEPRXCNTx(EpID)
Get endpoint reception byte count.
Definition: usb_regs.h:556

Definition at line 681 of file usb_regs.h.

#define _SetEPDblBufAddr (   EpID,
  Buf0Addr,
  Buf1Addr 
)
Value:
{ \
_SetEPDblBuf0Addr(EpID, Buf0Addr);\
_SetEPDblBuf1Addr(EpID, Buf1Addr);\
}

Sets a double buffer endpoint addresses.

Parameters
EpIDendpoint identifier which is in (0..7)
Buf0Addrbuffer0 address
Buf1Addrbuffer1 address
Return values
None

Definition at line 651 of file usb_regs.h.

#define _SetEPDblBuffCount (   EpID,
  Dir,
  Count 
)
Value:
{\
_SetEPDblBuf0Count(EpID, Dir, Count); \
_SetEPDblBuf1Count(EpID, Dir, Count); \
}

Definition at line 688 of file usb_regs.h.

#define _SetEPDoubleBuff (   EpID)    _SetEP_KIND(EpID)

Set and Clear directly double buffered feature of endpoint.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 480 of file usb_regs.h.

#define _SetEPRxCount (   EpID,
  Count 
)
Value:
{\
uint32_t *pdwReg = _GetEPRXCNTx(EpID); \
if(Count > 62) { _BlocksOf32(pdwReg, Count); } \
else { _BlocksOf2(pdwReg, Count); } \
}
#define _BlocksOf32(pdwReg, Count)
Set the reception buffer byte count register when 1 block is 32 bytes.
Definition: usb_regs.h:581
#define _GetEPRXCNTx(EpID)
Get endpoint reception byte count.
Definition: usb_regs.h:556
#define _BlocksOf2(pdwReg, Count)
Set the reception buffer byte count register when 1 block is 2 bytes.
Definition: usb_regs.h:594

Definition at line 620 of file usb_regs.h.

#define _SetEPRxDblBuf0Count (   EpID,
  Count 
)
Value:
{\
uint32_t *pdwReg = _GetEPTXCNTx(EpID); \
if(Count > 62) { _BlocksOf32(pdwReg, Count); } \
else { _BlocksOf32(pdwReg, Count); } \
}
#define _BlocksOf32(pdwReg, Count)
Set the reception buffer byte count register when 1 block is 32 bytes.
Definition: usb_regs.h:581
#define _GetEPTXCNTx(EpID)
Get endpoint transmission byte count.
Definition: usb_regs.h:542

Set buffer0 reception byte count when use double buffer.

Parameters
EpIDendpoint identifier which is in (0..7)
Countbyte count value
Return values
None

Definition at line 607 of file usb_regs.h.

#define _SetEPRxStatus (   EpID,
  State 
)
Value:
{\
register uint16_t _RegVal; \
_RegVal = _GetEPxCSR(EpID) & EPRX_DTGMASK;\
_SetEPxCSR(EpID, (_RegVal ^ State)); \
}

Rx transfer status setting and getting (bits EPRX_STA[1:0])

Parameters
EpIDendpoint identifier which is in (0..7)
Statenew state This parameter can be any one of the following values:
  • EPRX_DISABLED
  • EPRX_VALID
  • EPRX_NAK
  • EPRX_STALL
Return values
None

Definition at line 426 of file usb_regs.h.

#define _SetEPRxTxStatus (   EpID,
  StateRx,
  StateTx 
)
Value:
{\
register uint16_t _RegVal; \
_RegVal = _GetEPxCSR(EpID) & (EPRX_DTGMASK | EPTX_STA) ;\
_SetEPxCSR(EpID, ((_RegVal ^ StateRx) ^ StateTx)); \
}
#define EPTX_STA
Definition: usb_regs.h:245

Rx and Tx transfer status setting (bits EPRX_STA[1:0] & EPTX_STA[1:0])

Parameters
EpIDendpoint identifier which is in (0..7)
StateRxnew Rx state This parameter can be any one of the following values:
  • EPRX_DISABLED
  • EPRX_VALID
  • EPRX_NAK
  • EPRX_STALL
StateTxnew Tx state This parameter can be any one of the following values:
  • EPTX_DISABLED
  • EPTX_VALID
  • EPTX_NAK
  • EPTX_STALL
Return values
None

Definition at line 451 of file usb_regs.h.

#define _SetEPTxAddr (   EpID,
  Addr 
)    (*_GetEPTXARn(EpID) = (Addr & ~((uint16_t)1)))

Set Tx/Rx buffer address.

Parameters
EpIDendpoint identifier which is in (0..7)
Addraddress to be set (must be word aligned)
Return values
None

Definition at line 564 of file usb_regs.h.

#define _SetEPTxCount (   EpID,
  Count 
)    (*_GetEPTXCNTx(EpID) = Count)

Set Tx/Rx buffer byte count.

Parameters
EpIDendpoint identifier which is in (0..7)
Countbyte count value
Return values
None

Definition at line 619 of file usb_regs.h.

#define _SetEPTxStatus (   EpID,
  State 
)
Value:
{\
register uint16_t _RegVal; \
_RegVal = _GetEPxCSR(EpID) & EPTX_DTGMASK;\
_SetEPxCSR(EpID, (_RegVal ^ State)); \
}

Tx transfer status setting and getting (bits EPTX_STA[1:0])

Parameters
EpIDendpoint identifier which is in (0..7)
Statenew state This parameter can be any one of the following values:
  • EPTX_DISABLED
  • EPTX_VALID
  • EPTX_NAK
  • EPTX_STALL
Return values
None

Definition at line 407 of file usb_regs.h.

#define _SetEPType (   EpID,
  Type 
)    (_SetEPxCSR(EpID, ((_GetEPxCSR(EpID) & EP_CTL_MASK) | Type)))

Endpoint type setting and getting(bits EP_CTL[1:0] in endpoint control and status register)

Parameters
EpIDendpoint identifier which is in (0..7)
Typeendpoint type This parameter can be any one of the following values:
  • USB_EPTYPE_CONTROL: control transfer endpoint
  • USB_EPTYPE_BULK: bulk transfer endpoint
  • USB_EPTYPE_INT: interrupt transfer endpoint
  • USB_EPTYPE_ISOC: isochronous transfer endpoint
Return values
None

Definition at line 391 of file usb_regs.h.

#define _ToggleDTG_RX (   EpID)    (_SetEPxCSR(EpID, EPRX_DTG | (_GetEPxCSR(EpID) & EPCSR_MASK)))

Toggle and Clear EPRX_DTG bit in the endpoint control and status register.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 498 of file usb_regs.h.

#define _ToggleDTG_TX (   EpID)    (_SetEPxCSR(EpID, EPTX_DTG | (_GetEPxCSR(EpID) & EPCSR_MASK)))

Toggle and Clear EPTX_DTG bit in the endpoint control and status register.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 507 of file usb_regs.h.

#define _ToggleSWBUF_TX (   EpID)    _ToggleDTG_RX(EpID)

Toggle SW_BUF bit in the double buffered endpoint.

Parameters
EpIDendpoint identifier which is in (0..7)
Return values
None

Definition at line 516 of file usb_regs.h.

Generated by   doxygen 1.8.10