📄 usb_regs.c
字号:
* Output : None
* Return : None
*******************************************************************************/
void SetEPDblBuffCount(BYTE bEpNum, BYTE bDir, WORD wCount)
{
SetEPDblBuf0Count(bEpNum, bDir,wCount);
SetEPDblBuf1Count(bEpNum, bDir,wCount);
}
/*******************************************************************************
* Function Name : GetEPDblBuf0Count
* Description : Get buffer0 bytes count
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : buffer0 bytes count
*******************************************************************************/
WORD GetEPDblBuf0Count(BYTE bEpNum)
{
return(_GetEPDblBuf0Count(bEpNum));
}
/*******************************************************************************
* Function Name : GetEPDBuf1Count
* Description : Get buffer1 bytes count
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : buffer1 bytes count
*******************************************************************************/
WORD GetEPDblBuf1Count(BYTE bEpNum)
{
return(_GetEPDblBuf1Count(bEpNum));
}
/*******************************************************************************
* Function Name : Free User buffer
* Description : Toggles the SW_Buf bit
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : None
*******************************************************************************/
void FreeUserBuffer(BYTE bEpNum, BYTE bDir)
{
if(bDir== EP_DBUF_OUT)
{ /* OUT double buffered endpoint */
_ToggleDTOG_TX(bEpNum);
}
else if(bDir == EP_DBUF_IN)
{ /* IN double buffered endpoint */
_ToggleDTOG_RX(bEpNum);
}
}
/*******************************************************************************
* Function Name : ToWord
* Description : Puts 2 bytes into a single word
* Input : -bh : MSB byte
-bl : LSB byte
* Output : None
* Return : Word
*******************************************************************************/
WORD ToWord(BYTE bh, BYTE bl)
{
WORD wRet;
wRet = (WORD)bl | ((WORD)bh << 8);
return(wRet);
}
/*******************************************************************************
* Function Name : ByteSwap
* Description : Swaps two bytes in a word
* Input : wSwW: word
* Output : None
* Return : Word swapped
*******************************************************************************/
WORD ByteSwap(WORD wSwW)
{
BYTE bTemp;
WORD wRet;
bTemp = (BYTE)(wSwW & 0xff);
wRet = (wSwW >> 8) | ((WORD)bTemp << 8);
return(wRet);
}
/* DMA Functions */
/*******************************************************************************
* Function Name : SetDMAburstTxSize
* Description : Configure the Burst Size for a Tx Endpoint
* Input : DestBsize: Destination Burst Size
* Output : None
* Return : None
*******************************************************************************/
void SetDMABurstTxSize(BYTE DestBsize)
{
*DMABSIZE &=~0xEF;
*DMABSIZE = (DestBsize<<4);
}
/*******************************************************************************
* Function Name : SetDMABurstRxSize
* Description : Configure the Burst Size for a Rx Endpoint
* Input : SrcBsize: Source Burst
* Output : None
* Return : None
*******************************************************************************/
void SetDMABurstRxSize(BYTE SrcBsize)
{
*DMABSIZE &=~0x7;
*DMABSIZE = SrcBsize;
}
/*******************************************************************************
* Function Name : DMAUnlinkedModeTxConfig
* Description : Configure a Tx Endpoint to trigger TX Unlinked DMA request
* Note : Up to three endpoints could be configured to trigger DMA
request, an index[0:2] must be associated to an endpoint
* Input : -bEpNum: endpoint number[0:9]
* -index: 0,1 or 2
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeTxConfig(BYTE bEpNum ,BYTE index)
{
*DMACR2 &=~(0x0F<<(4*index));
*DMACR2 |=bEpNum<<(4*index);
}
/*******************************************************************************
* Function Name : DMAUnlinkedModeTxEnable
* Description : Enable a Tx endpoint to trigger Tx DMA request
* Input : -index :0,1 or 2 = index associated to endpoint in function
* "DMAUnlinkedModeTxConfig"
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeTxEnable(BYTE index)
{
*DMACR3 &=~0x01; /*DMA Tx linked mode disabled*/
*DMACR2 &=~0x3000;
*DMACR2 |=(index+1)<<12;
}
/*******************************************************************************
* Function Name : DMAUnlinkedModeTxDisable
* Description : Enable a Tx endpoint to trigger Tx DMA request
* Input : index :0,1 or 2 = index associated to endpoint in function
* "DMAUnlinkedModeTxConfig"
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeTxDisable(BYTE index)
{
*DMACR2 &=~0x3000;
}
/*******************************************************************************
* Function Name : DMAUnlinkedModeRxEnable
* Description : Enable a Rx Endpoint to trigger Rx DMA
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeRxEnable(BYTE bEpNum)
{
*DMACR3 &=~0x80; /*DMA Rx linked mode disabled*/
*DMACR1 |=(0x1<<bEpNum);
}
/*******************************************************************************
* Function Name : DMAUnlinkedModeRxDisable
* Description : Disable a Rx Endpoint to trigger Rx DMA
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : None
*******************************************************************************/
void DMAUnlinkedModeRxDisable(BYTE bEpNum)
{
*DMACR1 &=~(0x1<<bEpNum);
}
/*******************************************************************************
* Function Name : DMALinkedModeRxConfig
* Description : Configure a Rx endpoint to trigger DMA linked request
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeRxConfig(BYTE bEpNum)
{
*DMACR3 &=~0x1E00;
*DMACR3 |=bEpNum<<9;
}
/*******************************************************************************
* Function Name : DMALinkedModeTxConfig
* Description : Configure a Tx endpoint to trigger DMA linked request
* Input : bEpNum: endpoint number[0:9]
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeTxConfig(BYTE bEpNum)
{
*DMACR3 &=~0x1E;
*DMACR3 |=bEpNum<<1;
}
/*******************************************************************************
* Function Name : DMALinkedModeRxEnable
* Description : Enable the DMA Linked Rx mode
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeRxEnable(void)
{
*DMACR3 |=0x100;
*DMACR3 |=0x2000;
}
/*******************************************************************************
* Function Name : DMALinkedModeTxEnable
* Description : Enable the DMA Linked Tx mode
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeTxEnable(void)
{
*DMACR3 |=0x1;
*DMACR3 |=0x20;
}
/*******************************************************************************
* Function Name : DMALinkedModeRxDisable
* Description : Disable the DMA Linked Rx mode
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeRxDisable(void)
{
*DMACR3 &=~0x100;
*DMACR3 &=~0x2000;
}
/*******************************************************************************
* Function Name : DMALinkedModeTxDisable
* Description : Disable the DMA Linked Tx mode
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMALinkedModeTxDisable(void)
{
*DMACR3 &=~0x1;
*DMACR3 &=~0x20;
}
/*******************************************************************************
* Function Name : USB_DMASynchEnable
* Description : Enable the Synchronization Logic
* Input : TRUE or FALSE
* Output : None
* Return : None
*******************************************************************************/
void DMASynchEnable(void)
{
*DMACR3 |=0x40;
}
/*******************************************************************************
* Function Name : USB_DMASynchDisable
* Description : Disable the Synchronization Logic
* Input : TRUE or FALSE
* Output : None
* Return : None
*******************************************************************************/
void DMASynchDisable(void)
{
*DMACR3 &=~0x40;
}
/*******************************************************************************
* Function Name : SetDMALLITxLength
* Description : Set the DMA LLI Tx length
* Input : length
* Output : None
* Return : None
*******************************************************************************/
void SetDMALLITxLength(BYTE length)
{
*DMALLI &=~0xFF;
*DMALLI |= length;
}
/*******************************************************************************
* Function Name : SetDMALLIRxLength
* Description : Set the DMA LLI Rx length
* Input : length
* Output : None
* Return : None
*******************************************************************************/
void SetDMALLIRxLength(BYTE length )
{
*DMALLI &=~0xFF00;
*DMALLI |= length<<8;
}
/*******************************************************************************
* Function Name : SetDMALLIRxPacketNum
* Description : Set the LLI_RX_NPACKETS field in register USB_DMABSIZE register
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SetDMALLIRxPacketNum(BYTE PacketNum)
{
*DMABSIZE &=0xFF;
*DMABSIZE |=(PacketNum<<8);
}
/*******************************************************************************
* Function Name : GetDMALLIPacketNum
* Description : gets the LLI_RX_NPACKETS field value
* Input : None
* Output : None
* Return : LLI_RX_NPACKETS field value
*******************************************************************************/
BYTE GetDMALLIRxPacketNum(void)
{
return((BYTE)(*DMABSIZE & 0xFF00)>>8);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -