📄 xllp_udc.c
字号:
XLLP_UDC_INTERRUPTS_T udcEndpointNum - an endpoint or event number
XLLP_UDC_EP_INTERRUPT_TYPE_T interruptType - PC or FIFO error interrupts
Output Arguments:
None
Return Value:
None
*******************************************************************************/
void XllpUdcClearInterrupt (P_XLLP_UDC_T pUdcHandle,
XLLP_UDC_INTERRUPTS_T udcEndpointNum,
XLLP_UDC_EP_INTERRUPT_TYPE_T interruptType)
{
XLLP_UINT32_T bitNum;
volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;
// Write one to the corresponding bit of the UDC's interrupt status registers
// UDCISR0 and UDCISR1 to clear the endpoint's and event's interrupt.
if (udcEndpointNum < INT_ENDPOINT_Q)
{
bitNum = (udcEndpointNum << 1) | interruptType;
pRegs->UDCISR0 = (1 << bitNum);
// Clear the Endpoint FIFO Error bit in the Endpoint's UDCCSR register
pRegs->UDCCSR[udcEndpointNum] =
(pRegs->UDCCSR[udcEndpointNum] & XLLP_UDC_UDCCSR_DME) | XLLP_UDC_UDCCSR_EFE;
}
else if (udcEndpointNum < (INT_ENDPOINT_X + 1))
{
udcEndpointNum -= INT_ENDPOINT_Q;
bitNum = ((udcEndpointNum & 0xff) << 1) | interruptType;
pRegs->UDCISR1 = (1 << bitNum);
// Clear the Endpoint FIFO Error bit in the Endpoint's UDCCSR register
pRegs->UDCCSR[udcEndpointNum] =
(pRegs->UDCCSR[udcEndpointNum] & XLLP_UDC_UDCCSR_DME) | XLLP_UDC_UDCCSR_EFE;
}
else if (udcEndpointNum >= INT_RESET)
{
bitNum = (udcEndpointNum & 0x1f);
pRegs->UDCISR1 = (1 << bitNum);
}
}
/******************************************************************************
Function Name:
XllpUdcGetStatusInterrupt
Description:
This function returns the status of the Endpoint's or Event's interrupts.
Global Register Modified:
None
Input Arguments:
P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle
XLLP_UDC_INTERRUPTS_T udcEndpointNum - an endpoint or event number
XLLP_UDC_EP_INTERRUPT_TYPE_T interruptType - PC or FIFO error interrupts
Output Arguments:
P_XLLP_UINT32_T intStatus - the status of the Endpoint's or Event's interrupt.
One would be returned, if the corresponding bit in the
UDC interrupt status register is set.
Return Value:
None
*******************************************************************************/
void XllpUdcGetStatusInterrupt (P_XLLP_UDC_T pUdcHandle,
XLLP_UDC_INTERRUPTS_T udcEndpointNum,
XLLP_UDC_EP_INTERRUPT_TYPE_T interruptType,
P_XLLP_UINT32_T intStatus)
{
XLLP_UINT32_T bitNum;
volatile P_XLLP_UDC_REGISTERS_T pRegs = (P_XLLP_UDC_REGISTERS_T)pUdcHandle->pRegsBase;
// Read status one of the corresponding bits in the UDC's interrupt status registers
// UDCISR0 and UDCISR1.
if (udcEndpointNum < INT_ENDPOINT_Q)
{
bitNum = (udcEndpointNum << 1) | interruptType;
*intStatus = (pRegs->UDCISR0 >> bitNum) & 1;
}
else if (udcEndpointNum < (INT_ENDPOINT_X + 1))
{
udcEndpointNum -= INT_ENDPOINT_Q;
bitNum = ((udcEndpointNum & 0xff) << 1) | interruptType;
*intStatus = (pRegs->UDCISR1 >> bitNum) & 1;
}
else if (udcEndpointNum >= INT_RESET)
{
bitNum = (udcEndpointNum & 0x1f);
*intStatus = (pRegs->UDCISR1 >> bitNum) & 1;
}
}
/******************************************************************************
Function Name:
XllpUdcWriteDwordFifo
Description:
This function writes the specified number of bytes to the Endpoint's FIFO.
Global Register Modified:
None
Input Arguments:
P_XLLP_VUINT32_T pReg - a pointer to the Endpoints FIFO
void *src - a pointer to the data buffer
XLLP_INT32_T len - number of bytes to write
Output Arguments:
None
Return Value:
None
*******************************************************************************/
void XllpUdcWriteDwordFifo(P_XLLP_VUINT32_T pReg, void *src, XLLP_INT32_T len)
{
XLLP_INT32_T i;
XLLP_UINT32_T temp[16];
P_XLLP_UINT32_T p1;
P_XLLP_VUINT8_T pBuff, pTemp;
if (len == 0)
{
return;
}
if (len > sizeof(temp) && ((XLLP_UINT32_T)src & 0x3))
{
// ERROR alignment, return
return;
}
if ((XLLP_UINT32_T) src & 0x3)
{
memcpy (temp, src, len);
p1 = temp;
}
else
{
p1 = src;
}
if (((XLLP_INT32_T) len & 0x3) == 0)
{
// 4 byte aligned
for (i=0; i<(len>>2); i++)
{
*pReg = *p1++;
}
}
else
{
for (i=0; i<(len>>2); i++)
{
// all words
*pReg = *p1++;
}
pBuff = (P_XLLP_VUINT8_T)p1;
pTemp = (P_XLLP_VUINT8_T)pReg;
for (i=0; i<(len&0x3); i++)
{
*pTemp = *pBuff++;
}
}
}
/******************************************************************************
Function Name:
XllpUdcReadDwordFifo
Description:
This function reads the specified number of bytes to the Endpoint's FIFO.
Global Register Modified:
None
Input Arguments:
P_XLLP_VUINT32_T pReg - a pointer to the Endpoints FIFO
void *buf - a pointer to the data buffer
XLLP_INT32_T len - number of bytes to read
Output Arguments:
None
Return Value:
None
*******************************************************************************/
void XllpUdcReadDwordFifo (P_XLLP_VUINT32_T pReg, void *buf, XLLP_INT32_T len)
{
XLLP_INT32_T i;
XLLP_UINT32_T temp[16], rdat;
P_XLLP_UINT32_T p1;
XLLP_BOOL_T copyback;
P_XLLP_VUINT8_T pBuff, pTemp;
if (((XLLP_UINT32_T) buf & 0x3) != 0 && len > sizeof(temp))
{
// ERROR alignment, return
return;
}
if (((XLLP_UINT32_T)buf & 0x3) != 0)
{
p1 = temp;
copyback = XLLP_TRUE;
}
else
{
p1 = buf;
copyback = XLLP_FALSE;
}
if (((XLLP_INT32_T)len & 0x3) == 0)
{
// 4 byte aligned
for (i=0; i<(len>>2); i++)
{
*p1++ = *pReg;
}
}
else
{
for (i=0; i<(len>>2); i++)
{
// all words
*p1++ = *pReg;
}
rdat = *pReg;
pBuff = (P_XLLP_VUINT8_T)p1;
pTemp = (P_XLLP_VUINT8_T)&rdat;
for (i=0; i<(len&0x3); i++)
{
*pBuff++ = *pTemp++;
}
}
if (copyback)
{
memcpy (buf, temp, len);
}
}
/******************************************************************************
Function Name:
XllpUdcBuildListOfActiveEndpoints
Description:
This function fills the list of the endpoints that are used in the active
configuration, active interface, and active alternate interface. This list
will be processed from the main UDC's interrupt handler to accelerate the
determination which of the Endpoints A-X generated the interrupt.
Global Register Modified:
None
Input Arguments:
P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle
XLLP_UINT32_T configuration
XLLP_UINT32_T interface
XLLP_UINT32_T settings
Output Arguments:
P_XLLP_UINT32_T pNumActiveEndpoints - the total number of the endpoints in
the list of the active endpoints will
be returned.
Return Value:
None
*******************************************************************************/
void XllpUdcBuildListOfActiveEndpoints (P_XLLP_UDC_T pUdcHandle,
XLLP_UINT32_T configuration,
XLLP_UINT32_T interface,
XLLP_UINT32_T settings,
P_XLLP_UINT32_T pNumActiveEndpoints)
{
XLLP_UINT32_T i = 1, j = 0;
P_XLLP_UDC_EP_CONFIG_TABLE_T pConfigTable = (P_XLLP_UDC_EP_CONFIG_TABLE_T)
pUdcHandle->pConfigTable;
// Find all of the Endpoints that supports the active configuration and interface
// and build the table of active endpoints.
while (pConfigTable[i].usbConfigNum > 0)
{
if (pConfigTable[i].usbConfigNum == configuration)
{
if (pConfigTable[i].usbInterfaceNum == interface)
{
if (pConfigTable[i].usbIntAltSettingsNum == settings)
{
pUdcHandle->listOfActiveEndpoints[j].udcEndpointNum =
pConfigTable[i].udcEndpointNum;
pUdcHandle->listOfActiveEndpoints[j].usbEndpointNum =
pConfigTable[i].usbEndpointNum;
// Enable endpoint's packet complete interrupt
XllpUdcEnableInterrupt (pUdcHandle,
pConfigTable[i].udcEndpointNum,
PACKET_COMPL_INT);
// Enable endpoint's FIFO error interrupt
XllpUdcEnableInterrupt (pUdcHandle,
pConfigTable[i].udcEndpointNum,
FIFO_ERROR_INT);
++j;
}
}
}
++i;
}
*pNumActiveEndpoints = j;
}
/******************************************************************************
Function Name:
XllpUdcControlProcessIdle
Description:
This function is an entry point of Endpoint 0 state machine.
It processes the setup stage of the setup transaction.
Global Register Modified:
None.
Input Arguments:
P_XLLP_UDC_T pUdcHandle - a pointer to the UDC's handle
Output Arguments:
P_XLLP_UINT32_T pControlXferStatus - this argument is not used
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -