// Interrupt thread routine.
static
DWORD
WINAPI
ISTMain(
LPVOID lpParameter
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) lpParameter;
ValidateContext(pContext);
CeSetThreadPriority(pContext->hIST, pContext->dwISTPriority);
WaitForSingleObject(pContext->hBootCompleteEvent, INFINITE);
RETAILMSG(1,(TEXT("[UFNPDD] USB IST START\r\n")));
pContext->FirstCall = FALSE;
SetOtgDevicePower(pContext, D0);
while (!pContext->fExitIST)
{
pContext->fRestartIST = FALSE;
// Disable All Endpoint interrupts
WriteReg(DAINTMSK, 0); // Disable All Endpoint
// Clear any outstanding device & endpoint interrupts
// USB Device Interrupt Status - Write a '1' to Clear
WriteReg(GINTSTS, INT_RESUME | INT_EPMIS | INT_SDE | INT_RESET | INT_SUSPEND);
// Enable Device General interrupts
WriteReg(GINTMSK, INT_RESUME | INT_OUT_EP | INT_IN_EP | INT_EPMIS | INT_SDE | INT_RESET | INT_SUSPEND | INT_OTG);
// Enable Endpoint0 interrupt
EnableEndpointInterrupt(pContext, 0, USB_IN_TRANSFER);
EnableEndpointInterrupt(pContext, 0, USB_OUT_TRANSFER);
while (TRUE)
{
DWORD dwWait = WaitForSingleObject(pContext->hevInterrupt, INFINITE);
if (pContext->fExitIST || pContext->fRestartIST)
{
break;
}
if (dwWait == WAIT_OBJECT_0)
{
HandleUSBEvent(pContext);
InterruptDone(pContext->dwSysIntr);
}
else
{
ERRMSG( (_T("%s WaitForMultipleObjects failed. Exiting IST.\r\n"), pszFname));
break;
}
}
// Notify Detach Event to MDD
pContext->pfnNotify(pContext->pvMddContext, UFN_MSG_BUS_EVENTS, UFN_DETACH);
pContext->fSpeedReported = FALSE;
pContext->attachedState = UFN_DETACH;
// Disable Device interrupts - write Zeros to Disable
WriteReg(GINTMSK, 0);
// Disable endpoint interrupts - write Zeros to Disable
WriteReg(DAINTMSK, 0);
}
FUNCTION_LEAVE_MSG();
return 0;
}
|