📄 usbrc.c
字号:
/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP2RxValidStatus
INPUT/OUTPUT : endpoint direction / boolean
DESCRIPTION : Return true if the endpoint Rx is valided, false if not
-----------------------------------------------------------------------------*/
Bool GetEP2RxValidStatus()
{
if((USBEP2RB & STAT) == VALID)
return(TRUE);
else return(FALSE);
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP2RxCNT
INPUT/OUTPUT : Byte Received
DESCRIPTION : Return the byte number received through USB
-----------------------------------------------------------------------------*/
Byte GetEP2RxCNT()
{
Byte ByteReceived;
if((USBIDR & EP) == 2) // Last transaction on Endpoint 2
{
ByteReceived = (USBIDR & CNT);
return ByteReceived;
}
else return 0;
}
#endif
/********************************* Endpoint2 output Interrupt Pipe End ***************************/
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP0TxStatus
INPUT/OUTPUT : endpoint number and status values
DESCRIPTION : Write the status of Tx endpoint
-----------------------------------------------------------------------------*/
void SetEP0TxStatus(Byte Status)
{
USBEP0RA = (USBEP0RA & ~STAT) | Status;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP0StatusOut
INPUT/OUTPUT : endpoint number
DESCRIPTION : set the ST_OUT bit
-----------------------------------------------------------------------------*/
void SetEP0StatusOut(void)
{
USBEP0RA |= ST_OUT;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetResume
INPUT/OUTPUT : none
DESCRIPTION : set the RESUME bit in CTRL register
-----------------------------------------------------------------------------*/
void SetResume(void)
{
USBCTLR |= CTRL_RESUME;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearResume
INPUT/OUTPUT : none
DESCRIPTION : Clear the RESUME bit in CTRL register
-----------------------------------------------------------------------------*/
void ClearResume(void)
{
ClrBit(USBCTLR, 3);
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetSuspend
INPUT/OUTPUT : none
DESCRIPTION : set the SUSP bit in CTRL register
-----------------------------------------------------------------------------*/
void SetSuspend(void)
{
PADR &=0xfd; //clock =0 2-17-00
USBCTLR |= CtrlSusp;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearSuspend
INPUT/OUTPUT : none
DESCRIPTION : clear the SUSP bit in CTRL register
-----------------------------------------------------------------------------*/
void ClearSuspend(void)
{
USBCTLR &= (~CtrlSusp & 0x0f);
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetDeviceAddress
INPUT/OUTPUT : Device address
DESCRIPTION : Write the device address in the DADDR register
-----------------------------------------------------------------------------*/
void SetDeviceAddress(Byte DeviceAdress)
{
USBDADDR = DeviceAdress;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearEP0StatusOut
INPUT/OUTPUT : endpoint number
DESCRIPTION : clear the ST_OUT bit
-----------------------------------------------------------------------------*/
void ClearEP0StatusOut(void)
{
USBEP0RA &= ~ST_OUT;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearSusp
INPUT/OUTPUT : none
DESCRIPTION : clear the SUSP bit in ISTR register
-----------------------------------------------------------------------------*/
void ClearSusp(void)
{
USBISTR = ~Int_Susp;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearEsusp
INPUT/OUTPUT : none
DESCRIPTION : clear the ESUSP bit in ISTR register
-----------------------------------------------------------------------------*/
void ClearEsusp(void)
{
USBISTR = ~Int_Esusp;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearReset
INPUT/OUTPUT : none
DESCRIPTION : clear the RESET bit in ISTR register
-----------------------------------------------------------------------------*/
void ClearReset(void)
{
USBISTR = ~Int_Reset;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearCtr
INPUT/OUTPUT : none
DESCRIPTION : clear the CTR bit in ISTR register
-----------------------------------------------------------------------------*/
void ClearCtr(void)
{
USBISTR = ~Int_Ctr;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearSof
INPUT/OUTPUT : none
DESCRIPTION : clear the SOF bit in ISTR register
-----------------------------------------------------------------------------*/
void ClearSof(void)
{
USBISTR = ~Int_Sof;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP0StatusOut
INPUT/OUTPUT : Endpoint number / boolean
DESCRIPTION : Return true if the endpoint Tx ST_OUT bit is set, false if not
-----------------------------------------------------------------------------*/
Bool GetEP0StatusOut(void)
{
if (!(USBEP0RA & ST_OUT))
return(FALSE);
else
return (TRUE);
}
#ifdef USE_ENDPOINT1
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearEP1StatusOut
INPUT/OUTPUT : endpoint number
DESCRIPTION : clear the ST_OUT bit
-----------------------------------------------------------------------------*/
void ClearEP1StatusOut(void)
{
USBEP1RA &= ~ST_OUT;
}
#endif
#ifdef USE_ENDPOINT2
/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP2StallStatus
INPUT/OUTPUT : Endpoint number, endpoint direction / boolean
DESCRIPTION : Return true if the endpoint Tx/Rx is stalled, false if not
-----------------------------------------------------------------------------*/
Bool GetEP2StallStatus(Byte EndpointDir)
{
if (EndpointDir) // IN endpoint
{
if ((USBEP2RA & STAT) == STALL)
return(TRUE);
else
return (FALSE);
}
else // OUT endpoint
{
if ((USBEP2RB & STAT) == STALL)
return(TRUE);
else
return (FALSE);
}
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : SetEP2StatusOut
INPUT/OUTPUT : endpoint number
DESCRIPTION : set the ST_OUT bit
-----------------------------------------------------------------------------*/
void SetEP2StatusOut(void)
{
USBEP2RA |= ST_OUT;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : ClearEP2StatusOut
INPUT/OUTPUT : endpoint number
DESCRIPTION : clear the ST_OUT bit
-----------------------------------------------------------------------------*/
void ClearEP2StatusOut(void)
{
USBEP2RA &= ~ST_OUT;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP2StatusOut
INPUT/OUTPUT : Endpoint number / boolean
DESCRIPTION : Return true if the endpoint Tx ST_OUT bit is set, false if not
-----------------------------------------------------------------------------*/
Bool GetEP2StatusOut(void)
{
if (!(USBEP2RA & ST_OUT))
return(FALSE);
else
return (TRUE);
}
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : GetPid
INPUT/OUTPUT : none / token value
DESCRIPTION : Return the value of the last token PID received
-----------------------------------------------------------------------------*/
Byte GetPid(void)
{
return(USBPIDR & TP); // Read token PID
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEndpointNumber
INPUT/OUTPUT : none / endpoint number
DESCRIPTION : Return the value of endpoint addressed during the last transaction
-----------------------------------------------------------------------------*/
Byte GetEndpointNumber(void)
{
return((USBIDR & EP) >> 4); // Read Endpoint number
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP0TxValidStatus
INPUT/OUTPUT : Endpoint number, endpoint direction / boolean
DESCRIPTION : Return true if the endpoint Tx is valided, false if not
-----------------------------------------------------------------------------*/
Bool GetEP0TxValidStatus(void)
{
if((USBEP0RA & STAT) == VALID)
return(TRUE);
else return(FALSE);
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : GetEP0RxValidStatus
INPUT/OUTPUT : Endpoint number, endpoint direction / boolean
DESCRIPTION : Return true if the endpoint Rx is valided, false if not
-----------------------------------------------------------------------------*/
Bool GetEP0RxValidStatus()
{
if((USBEP0RB & STAT) == VALID)
return(TRUE);
else return(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -