📄 usb_regs.h
字号:
#define _GetISTR() ((u16) *ISTR)
/*----------------------------------------------------------------*/
/* GetFNR */
/*----------------------------------------------------------------*/
#define _GetFNR() ((u16) *FNR)
/*----------------------------------------------------------------*/
/* GetDADDR */
/*----------------------------------------------------------------*/
#define _GetDADDR() ((u16) *DADDR)
/*----------------------------------------------------------------*/
/* GetBTABLE */
/*----------------------------------------------------------------*/
#define _GetBTABLE() ((u16) *BTABLE)
/*----------------------------------------------------------------*/
/* SetENDPOINT */
/*----------------------------------------------------------------*/
#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \
(u16)wRegValue)
/*----------------------------------------------------------------*/
/* GetENDPOINT */
/*----------------------------------------------------------------*/
#define _GetENDPOINT(bEpNum) ((u16)(*(EP0REG + bEpNum)))
/*----------------------------------------------------------------*/
/* SetEPType */
/* sets the type in the endpoint register(bits EP_TYPE[1:0]) */
/* IN : bEpNum = endpoint number */
/* wType = type definition */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\
((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType)))
/*----------------------------------------------------------------*/
/* GetEPType */
/* gets the type in the endpoint register(bits EP_TYPE[1:0]) */
/* IN : bEpNum = endpoint number */
/* OUT: type definition */
/*----------------------------------------------------------------*/
#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD)
/*----------------------------------------------------------------*/
/* SetEPTxStatus */
/* sets the status for tx transfer (bits STAT_TX[1:0]) */
/* IN : bEpNum = endpoint number */
/* wState = new state */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _SetEPTxStatus(bEpNum,wState) {\
register u16 _wRegVal; \
_wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\
/* toggle first bit ? */ \
if((EPTX_DTOG1 & wState)!= 0) \
_wRegVal ^= EPTX_DTOG1; \
/* toggle second bit ? */ \
if((EPTX_DTOG2 & wState)!= 0) \
_wRegVal ^= EPTX_DTOG2; \
_SetENDPOINT(bEpNum, _wRegVal); \
} /* _SetEPTxStatus */
/*----------------------------------------------------------------*/
/* SetEPRxStatus */
/* sets the status for rx transfer (bits STAT_TX[1:0]) */
/* IN : bEpNum = endpoint number */
/* wState = new state */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _SetEPRxStatus(bEpNum,wState) {\
register u16 _wRegVal; \
\
_wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\
/* toggle first bit ? */ \
if((EPRX_DTOG1 & wState)!= 0) \
_wRegVal ^= EPRX_DTOG1; \
/* toggle second bit ? */ \
if((EPRX_DTOG2 & wState)!= 0) \
_wRegVal ^= EPRX_DTOG2; \
_SetENDPOINT(bEpNum, _wRegVal); \
} /* _SetEPRxStatus */
/*----------------------------------------------------------------*/
/* GetEPTxStatus / GetEPRxStatus */
/* gets the status for tx/rx transfer (bits STAT_TX[1:0]/STAT_RX[1:0]) */
/* IN : bEpNum = endpoint number */
/* OUT: u16 status */
/*----------------------------------------------------------------*/
#define _GetEPTxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPTX_STAT)
#define _GetEPRxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPRX_STAT)
/*----------------------------------------------------------------*/
/* SetEPTxValid / SetEPRxValid */
/* sets directly the VALID tx/rx-status into the enpoint register */
/* IN : bEpNum = endpoint number */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID))
#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID))
/*----------------------------------------------------------------*/
/* GetTxStallStatus / GetRxStallStatus */
/* checks stall condition in an endpoint */
/* IN : bEpNum = endpoint number */
/* OUT: TRUE = endpoint in stall condition */
/*----------------------------------------------------------------*/
#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \
== EP_TX_STALL)
#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \
== EP_RX_STALL)
/*----------------------------------------------------------------*/
/* SetEP_KIND / ClearEP_KIND */
/* IN : bEpNum = endpoint number */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
(_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK))
#define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
(_GetENDPOINT(bEpNum) & EPKIND_MASK)))
/*----------------------------------------------------------------*/
/* Set_Status_Out / Clear_Status_Out */
/* sets/clears directly STATUS_OUT bit in the endpoint register */
/* to be used only during control transfers */
/* IN : bEpNum = endpoint number */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum)
#define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum)
/*----------------------------------------------------------------*/
/* SetEPDoubleBuff / ClearEPDoubleBuff */
/* sets/clears directly EP_KIND bit in the endpoint register */
/* IN : bEpNum = endpoint number */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum)
#define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum)
/*----------------------------------------------------------------*/
/* ClearEP_CTR_RX / ClearEP_CTR_TX */
/* clears bit CTR_RX / CTR_TX in the endpoint register */
/* IN : bEpNum = endpoint number */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\
_GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK))
#define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\
_GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK))
/*----------------------------------------------------------------*/
/* ToggleDTOG_RX / ToggleDTOG_TX */
/* toggles DTOG_RX / DTOG_TX bit in the endpoint register */
/* IN : bEpNum = endpoint number */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \
EP_DTOG_RX | _GetENDPOINT(bEpNum) & EPREG_MASK))
#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \
EP_DTOG_TX | _GetENDPOINT(bEpNum) & EPREG_MASK))
/*----------------------------------------------------------------*/
/* ClearDTOG_RX / ClearDTOG_TX */
/* IN : bEpNum = endpoint number */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\
_ToggleDTOG_RX(bEpNum)
#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\
_ToggleDTOG_TX(bEpNum)
/*----------------------------------------------------------------*/
/* SetEPAddress */
/* sets address in an endpoint register */
/* IN : bEpNum = endpoint number */
/* bAddr = address */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\
_GetENDPOINT(bEpNum) & EPREG_MASK | bAddr)
/*----------------------------------------------------------------*/
/* GetEPAddress */
/* IN : bEpNum = endpoint number */
/* OUT: none */
/*----------------------------------------------------------------*/
#define _GetEPAddress(bEpNum) ((u8)(_GetENDPOINT(bEpNum) & EPADDR_FIELD))
/*----------------------------------------------------------------*/
#ifdef STR7xx /*STR7xx family*/
#define _pEPTxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr))
#define _pEPTxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr))
#define _pEPRxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr))
#define _pEPRxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr))
#endif
#ifdef STR91x /*STR91x family*/
/* Pointers on endpoint(bEpNum) Count & Addr registers on PMA */
#define _pEPBufCount(bEpNum) ((u32 *)(_GetBTABLE()+bEpNum*8 + 4 + PMAAddr))
#define _pEPBufAddr(bEpNum) ((u32 *)(_GetBTABLE()+bEpNum*8 + PMAAddr))
#endif
/*----------------------------------------------------------------*/
/* SetEPTxAddr / SetEPRxAddr */
/* sets address of the tx/rx buffer */
/* IN : bEpNum = endpoint number */
/* wAddr = address to be set ( must be word aligned ) */
/* OUT: none */
/*----------------------------------------------------------------*/
#ifdef STR7xx /*STR7xx family*/
#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1))
#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1))
#endif
#ifdef STR91x /*STR91x family*/
#define _SetEPTxAddr(bEpNum , wAddr) {\
*_pEPBufAddr(bEpNum) &=0xFFFF0000; \
*_pEPBufAddr(bEpNum) |=((wAddr)&0x0FFFC);\
}
#define _SetEPRxAddr(bEpNum, wAddr) {\
*_pEPBufAddr(bEpNum) &=0x0000FFFF;\
*_pEPBufAddr(bEpNum) |=((wAddr<<16)&0xFFFC0000);\
}
#endif
/*----------------------------------------------------------------*/
/* GetEPTxAddr / GetEPRxAddr */
/* gets address of the tx/rx buffer */
/* IN : bEpNum = endpoint number */
/* IN : */
/* OUT: address of the buffer */
/*----------------------------------------------------------------*/
#ifdef STR7xx /*STR7xx family*/
#define _GetEPTxAddr(bEpNum) ((u16)*_pEPTxAddr(bEpNum))
#define _GetEPRxAddr(bEpNum) ((u16)*_pEPRxAddr(bEpNum))
#endif
#ifdef STR91x /*STR91x family*/
#define _GetEPTxAddr(bEpNum) ((u16)(*_pEPBufAddr(bEpNum) &0x0000FFFF))
#define _GetEPRxAddr(bEpNum) ((u16)((*_pEPBufAddr(bEpNum)&0xFFFF0000)>>16))
#endif
/*----------------------------------------------------------------*/
/* SetEPCountRxReg */
/* sets counter of rx buffer with no. of blocks */
/* IN : pdwReg = pointer to counter */
/* wCount = counter */
/* OUT: none */
/*----------------------------------------------------------------*/
#ifdef STR7xx /*STR7xx family*/
#define _BlocksOf32(dwReg,wCount,wNBlocks) {\
wNBlocks = wCount >> 5;\
if((wCount & 0x1f) == 0)\
wNBlocks--;\
*pdwReg = (u32)((wNBlocks << 10) | 0x8000);\
}/* _BlocksOf32 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -