⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_regs1.h

📁 意法半導體STR710,USB範例程式,模擬U盤
💻 H
📖 第 1 页 / 共 2 页
字号:
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
PROJECT  : ARM7 USB Core
MODULE  :  USB_regs.h
AUTHOR :  MCD Application Team
CREATION DATE : 21/04/2004
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DESCRIPTION : Operations with Endpoint registers and Packet Memory Area
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
MODIFICATIONS :
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

#define RegBase  (0xC0800800L)  // Registers Base address 
#define PMAAddr  (0xC0800000L)  // Packet memory area address 

// General registers
#define USB_CNTR    ((volatile unsigned *)(RegBase + 0x40))	// Control register           
#define USB_ISTR    ((volatile unsigned *)(RegBase + 0x44))	// Interrupt status register
#define USB_FNR     ((volatile unsigned *)(RegBase + 0x48)) // Frame number register
#define USB_DADDR   ((volatile unsigned *)(RegBase + 0x4C))	// Device address register
#define USB_BTABLE  ((volatile unsigned *)(RegBase + 0x50))	// Buffer Table address register

// Endpoint registers
#define EP0REG  ((volatile unsigned *)(RegBase))

#define ENDP0	 ((BYTE)0)
#define ENDP1	 ((BYTE)1)
#define ENDP2	 ((BYTE)2)
#define ENDP3	 ((BYTE)3)
#define ENDP4	 ((BYTE)4)
#define ENDP5	 ((BYTE)5)
#define ENDP6	 ((BYTE)6)
#define ENDP7	 ((BYTE)7)
#define ENDP8	 ((BYTE)8)
#define ENDP9	 ((BYTE)9)
#define ENDP10	 ((BYTE)10)
#define ENDP11	 ((BYTE)11)
#define ENDP12	 ((BYTE)12)
#define ENDP13	 ((BYTE)13)
#define ENDP14	 ((BYTE)14)
#define ENDP15	 ((BYTE)15)


/*******************************************************************************/
/* USB_ISTR interrupt flags  */
/*******************************************************************************/
#define ISTR_CTR   (0x8000)
#define ISTR_DOVR  (0x4000)
#define ISTR_ERR   (0x2000)
#define ISTR_WKUP  (0x1000)
#define ISTR_SUSP  (0x0800)
#define ISTR_RESET (0x0400)
#define ISTR_SOF   (0x0200)
#define ISTR_ESOF  (0x0100)
#define ISTR_DIR   (0x0010)	

/*******************************************************************************/
// USB_CNTR control register bits definitions
/*******************************************************************************/
#define CNTR_CTRM   (0x8000)  // Correct TRansfer Mask
#define CNTR_DOVRM  (0x4000)  // DMA over/underrun mask
#define CNTR_ERRM   (0x2000)
#define CNTR_WKUPM  (0x1000)
#define CNTR_SUSPM  (0x0800)
#define CNTR_RESETM (0x0400)
#define CNTR_SOFM   (0x0200)
#define CNTR_ESOFM  (0x0100)
#define CNTR_RESUME (0x0010)
#define CNTR_FSUSP  (0x0008)
#define CNTR_LPMODE (0x0004)
#define CNTR_PDWN   (0x0002)
#define CNTR_FRES   (0x0001)

//===============================================================================
// Endpoint register 
//===============================================================================
// bit positions
#define EP_CTR_RX   (0x8000)	
#define EP_CTR_TX   (0x0080)
#define EP_DTOG_RX  (0x4000)
#define EP_DTOG_TX  (0x0040)
#define EP_SETUP    (0x0800)	
// EP_TYPE[1:0]
#define EP_BULK        (0x0000)
#define EP_CONTROL     (0x0200)
#define EP_ISOCHRONOUS (0x0400)
#define EP_INTERRUPT   (0x0600)
#define EP_T_FIELD    (0x0600)
#define EP_T_MASK     (0xF9FF & EPREG_MASK)
// EP_KIND
#define EP_KIND       (0x0100)
#define EPKIND_MASK   (0xFEFF & EPREG_MASK)
// STAT_TX[1:0]
#define EP_TX_DIS   (0x0000)
#define EP_TX_STALL (0x0010)
#define EP_TX_NAK   (0x0020)
#define EP_TX_VALID (0x0030)
#define EPTX_STAT   (0x0030)
#define EPTX_DTOG1    (0x0010)
#define EPTX_DTOG2    (0x0020)
#define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK)
// STAT_RX[1:0]
#define EP_RX_DIS   (0x0000)
#define EP_RX_STALL (0x1000)
#define EP_RX_NAK   (0x2000)
#define EP_RX_VALID (0x3000)
#define EPRX_STAT   (0x3000)
#define EPRX_DTOG1    (0x1000)
#define EPRX_DTOG2    (0x2000)
#define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK)

// definitions
#define EPREG_MASK  (0x8F8F)  // to write 

typedef enum _EP_DBUF_DIR{
 EP_DBUF_ERR,
 EP_DBUF_OUT,
 EP_DBUF_IN  
}EP_DBUF_DIR;

enum EP_BUF_NUM{
 EP_NOBUF,
 EP_BUF0 ,
 EP_BUF1
};

#define EPADDR_FIELD  (0x000F)
//----------------------------------------------------------------

extern volatile WORD wIstr;  // USB_ISTR register last read value
/*----------------------------------------------------------------*/
/*				   FUNCTION PROTOTYPES							  */
/*							&									  */
/*						M A C R O s 							  */ 
/*----------------------------------------------------------------*/
//----------------------------------------------------------------
// SetCNTR
//----------------------------------------------------------------
void SetCNTR(WORD);
#define _SetCNTR(wRegValue)	 (*USB_CNTR   = (WORD)wRegValue)
//----------------------------------------------------------------
// SetISTR
//----------------------------------------------------------------
void SetISTR(WORD);
#define _SetISTR(wRegValue)	 (*USB_ISTR   = (WORD)wRegValue)
//----------------------------------------------------------------
// SetDADDR
//----------------------------------------------------------------
void SetDADDR(WORD);
#define _SetDADDR(wRegValue) (*USB_DADDR  = (WORD)wRegValue)
//----------------------------------------------------------------
// SetBTABLE
//----------------------------------------------------------------
void SetBTABLE(WORD);
#define _SetBTABLE(wRegValue)(*USB_BTABLE = (WORD)(wRegValue & 0xFFF8))
//----------------------------------------------------------------
// GetCNTR
//----------------------------------------------------------------
WORD GetCNTR(void); 
#define _GetCNTR()   ((WORD) *USB_CNTR)
//----------------------------------------------------------------
// GetISTR
//----------------------------------------------------------------
WORD GetISTR(void);
#define _GetISTR()   ((WORD) *USB_ISTR)
//----------------------------------------------------------------
// GetFNR
//----------------------------------------------------------------
WORD GetFNR(void);
#define _GetFNR()    ((WORD) *USB_FNR)
//----------------------------------------------------------------
// GetDADDR
//----------------------------------------------------------------
WORD GetDADDR(void);
#define	_GetDADDR()  ((WORD) *USB_DADDR)
//----------------------------------------------------------------
// GetBTABLE
//----------------------------------------------------------------
WORD GetBTABLE(void);
#define _GetBTABLE() ((WORD) *USB_BTABLE)
//----------------------------------------------------------------
// SetENDPOINT
//----------------------------------------------------------------
void SetENDPOINT(BYTE,WORD);
#define _SetENDPOINT(bEpNum,wRegValue)  (*(EP0REG + bEpNum)= (WORD)wRegValue)
//----------------------------------------------------------------
// GetENDPOINT
//----------------------------------------------------------------
WORD GetENDPOINT(BYTE);
#define _GetENDPOINT(bEpNum)  		    ((WORD)(*(EP0REG + bEpNum)))

//----------------------------------------------------------------
// SetEPType
// sets the type in the endpoint register(bits EP_TYPE[1:0])
// IN : bEpNum = endpoint number
//		wType  = type definition
// OUT: none
//----------------------------------------------------------------
void SetEPType(BYTE,WORD);
#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
//----------------------------------------------------------------
WORD GetEPType(BYTE);
#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
//----------------------------------------------------------------
void SetEPTxStatus(BYTE,WORD); 
#define _SetEPTxStatus(bEpNum,wState) {\
 register WORD _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
//----------------------------------------------------------------
void SetEPRxStatus(BYTE,WORD);
#define _SetEPRxStatus(bEpNum,wState) {\
 register WORD _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
// gets the status for tx transfer (bits STAT_TX[1:0])
// IN : bEpNum  = endpoint number
// OUT: 
//----------------------------------------------------------------
WORD GetEPTxStatus(BYTE);
#define _GetEPTxStatus(bEpNum) ((WORD)_GetENDPOINT(bEpNum) & EPTX_STAT)

//----------------------------------------------------------------
// GetEPRxStatus
// IN : bEpNum  = endpoint number
// OUT: 
//----------------------------------------------------------------
WORD GetEPRxStatus(BYTE);
#define _GetEPRxStatus(bEpNum) ((WORD)_GetENDPOINT(bEpNum) & EPRX_STAT)

//----------------------------------------------------------------
// SetEPTxValid
// sets directly the VALID tx-status into the enpoint register
// IN : bEpNum = endpoint number
// OUT: none
//----------------------------------------------------------------
void SetEPTxValid(BYTE);
#define _SetEPTxValid(bEpNum)     (_SetEPTxStatus(bEpNum, EP_TX_VALID))

//----------------------------------------------------------------
// SetEPRxValid
// sets directly the VALID rx-status into the enpoint register
// IN : bEpNum = endpoint number
// OUT: none
//----------------------------------------------------------------
void SetEPRxValid(BYTE);
#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
//----------------------------------------------------------------
BOOL GetTxStallStatus(BYTE);
#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \
													 == EP_TX_STALL)
BOOL GetRxStallStatus(BYTE);
#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \
													 == EP_RX_STALL)
//----------------------------------------------------------------
// SetEP_KIND
// IN : bEpNum  = endpoint number
// OUT: none
//----------------------------------------------------------------
void SetEP_KIND(BYTE);
#define _SetEP_KIND(bEpNum)	   (_SetENDPOINT(bEpNum, \
					    (_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK))
//----------------------------------------------------------------
// ClearEP_KIND
// IN : bEpNum  = endpoint number
// OUT: none

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -