📄 sc2450pdd.cpp
字号:
RETAILMSG(DBG, (_T("%s UfnPdd_AbortTransfer\r\n"),
pszFname));
ValidateTransferDirection(pContext, peps, pTransfer);
DEBUGCHK(pTransfer == peps->pTransfer);
CompleteTransfer(pContext, peps, UFN_CANCELED_ERROR);
if (dwEndpoint == 0) {
pContext->Ep0State = EP0_STATE_IDLE;
}
ResetEndpoint( pContext,peps);
UNLOCK_ENDPOINT(peps);
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
BOOL HW_USBClocks(CEDEVICE_POWER_STATE cpsNew)
{
if (cpsNew == D0) //power on
{
RETAILMSG(0, (TEXT("HW_USBClocks::D0 \r\n")));
if(pIOPregs->GPFDAT & (1<<2)) //check cable connection, for powerconsumption
{
// Set the Normal mode
pIOPregs->GPHCON = (pIOPregs->GPHCON & ~(0x3<<28)) | (0x1<<28);
pIOPregs->GPHUDP = (pIOPregs->GPHUDP & ~(0x3<<28));
pIOPregs->GPHDAT = (pIOPregs->GPHDAT & ~(0x1<<14)) | (0x1<<14);
pIOPregs->MISCCR &= ~(1<<12);
// Enable the PHY Power
pCLKPWR->PWRCFG |= (1<<4);
// First USB PHY has to be reset, and after 10us, func and host has to be reset.
pCLKPWR->USB_CLKCON = (0<<31)|(1<<2)|(0<<1)|(0<<0); //pullup disable
pCLKPWR->USB_RSTCON = (0<<2)|(0<<1)|(1<<0);
Sleep(2);
pCLKPWR->USB_RSTCON = (1<<2)|(0<<1)|(0<<0);
Sleep(2);
pCLKPWR->USB_RSTCON = (0<<2)|(0<<1)|(0<<0);
pCLKPWR->USB_CLKCON = (1<<31)|(1<<2)|(0<<1)|(0<<0);//pull up enable
// Set USB PHY Control
// Ref. Clock (48MHz), Clock (X-tal), Host Clock (Ext. X-tal), D-stream (Device Mode)
pCLKPWR->USB_PHYCTRL = (0<<3)|(1<<2)|(0<<1)|(0<<0);
// Set USB PHY Power
// 48Mhz clock on ,PHY2.0 analog block power on,XO block power on,
// XO block power in suspend mode,PHY 2.0 Pll power on ,suspend signal for save mode disable
pCLKPWR->USB_PHYPWR = (0<<31)|(3<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0);
// Set USB Clock Control
// Vbus detect enable and D+ Pull up, USB2.0 Function clock Enable,
// USB1.1 HOST disable,USB2.0 PHY test enable
}
}
// Should be implemented
else if (cpsNew == D4) //power off
{
RETAILMSG(0, (TEXT("HW_USBClocks::D4 \r\n")));
pCLKPWR->USB_CLKCON = (0<<31)|(0<<2)|(0<<1)|(0<<0); //pullup disable
// disable the PHY Power
pCLKPWR->PWRCFG &= ~(1<<4);
// Set the Normal mode regulator disable
pIOPregs->GPHCON = (pIOPregs->GPHCON & ~(0x3<<28)) | (0x1<<28);
pIOPregs->GPHUDP = (pIOPregs->GPHUDP & ~(0x3<<28)) | (0x2<<28);
pIOPregs->GPHDAT = (pIOPregs->GPHDAT & ~(0x1<<14));
pIOPregs->MISCCR |= (1<<12);
}
return TRUE;
}
// This does not do much because there is not any way to control
// power on this controller.
static
CEDEVICE_POWER_STATE
SetPowerState(
PCTRLR_PDD_CONTEXT pContext,
CEDEVICE_POWER_STATE cpsNew
)
{
SETFNAME();
PREFAST_DEBUGCHK(pContext);
DEBUGCHK(VALID_DX(cpsNew));
ValidateContext(pContext);
RETAILMSG(DBG, (_T("%s SetPowerState\r\n"),
pszFname));
// Adjust cpsNew.
if (cpsNew != pContext->cpsCurrent) {
if (cpsNew == D1 || cpsNew == D2) {
// D1 and D2 are not supported.
cpsNew = D0;
}
else if (pContext->cpsCurrent == D4) {
// D4 can only go to D0.
cpsNew = D0;
}
}
if (cpsNew != pContext->cpsCurrent) {
DEBUGMSG(ZONE_POWER, (_T("%s Going from D%u to D%u\r\n"),
pszFname, pContext->cpsCurrent, cpsNew));
if ( (cpsNew < pContext->cpsCurrent) && pContext->hBusAccess ) {
SetDevicePowerState(pContext->hBusAccess, cpsNew, NULL);
}
switch (cpsNew) {
case D0:
HW_USBClocks(D0);
KernelIoControl(IOCTL_HAL_DISABLE_WAKE, &pContext->dwSysIntr,
sizeof(pContext->dwSysIntr), NULL, 0, NULL);
if (pContext->fRunning) {
// Cause the IST to restart.
pContext->fRestartIST = TRUE;
SetInterruptEvent(pContext->dwSysIntr);
}
break;
case D3:
KernelIoControl(IOCTL_HAL_ENABLE_WAKE, &pContext->dwSysIntr,
sizeof(pContext->dwSysIntr), NULL, 0, NULL);
break;
case D4:
HW_USBClocks((CEDEVICE_POWER_STATE)D4);
KernelIoControl(IOCTL_HAL_DISABLE_WAKE, &pContext->dwSysIntr,
sizeof(pContext->dwSysIntr), NULL, 0, NULL);
break;
}
if ( (cpsNew > pContext->cpsCurrent) && pContext->hBusAccess ) {
SetDevicePowerState(pContext->hBusAccess, cpsNew, NULL);
}
pContext->cpsCurrent = cpsNew;
}
return pContext->cpsCurrent;
}
// EINT2 Test Code by woo
DWORD
HW_InitRegisters()
{
#if 1
v_gBspArgs = (volatile BSP_ARGS *)VirtualAlloc(0, sizeof(BSP_ARGS), MEM_RESERVE, PAGE_NOACCESS);
if (!v_gBspArgs)
{
RETAILMSG(1, (TEXT("#####:common Argument Area VirtualAlloc failed!\r\n")));
return FALSE;
}
if (!VirtualCopy((PVOID)v_gBspArgs, (PVOID)(IMAGE_SHARE_ARGS_UA_START), sizeof(BSP_ARGS), PAGE_READWRITE | PAGE_NOCACHE ))
{
RETAILMSG(1, (TEXT("#####::BSP Common Argument Are VirtualCopy failed!\r\n")));
return FALSE;
}
pCLKPWR = (volatile S3C2450_CLKPWR_REG*)VirtualAlloc(0, sizeof(S3C2450_CLKPWR_REG), MEM_RESERVE, PAGE_NOACCESS);
if (!pCLKPWR)
{
DEBUGMSG(1, (TEXT("pCLKPWR: VirtualAlloc failed!\r\n")));
return(FALSE);
}
if (!VirtualCopy((PVOID)pCLKPWR, (PVOID)(S3C2450_BASE_REG_PA_CLOCK_POWER >> 8), sizeof(S3C2450_CLKPWR_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("pCLKPWR: VirtualCopy failed!\r\n")));
return(FALSE);
}
pIOPregs = (volatile S3C2450_IOPORT_REG *)VirtualAlloc(0, sizeof(S3C2450_IOPORT_REG), MEM_RESERVE, PAGE_NOACCESS);
if(!pIOPregs) {
DEBUGMSG(1, (TEXT("pIOPregs: VirtualAlloc failed!\r\n")));
return(FALSE);
}
if(!VirtualCopy((PVOID)pIOPregs, (PVOID)(S3C2450_BASE_REG_PA_IOPORT >> 8), sizeof(S3C2450_IOPORT_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("pIOPregs: VirtualCopy failed!\r\n")));
return(FALSE);
}
#endif
#if (BSP_TYPE == BSP_SMDK2443)
pIOPregs->EXTINT0 = (READEXTINT0(pIOPregs->EXTINT0) & ~(0xf<<8)) | (1<<11) | (7<<8);
#elif (BSP_TYPE == BSP_SMDK2450)
pIOPregs->EXTINT0 = (pIOPregs->EXTINT0 & ~(0xf<<8)) | (0<<11) | (7<<8); //filter enable,
#endif
pIOPregs->GPFCON &= ~(3<<4);
pIOPregs->GPFCON |= (2<<4);
// end woo
return 0;
}
// end woo
static
VOID
FreeCtrlrContext(
PCTRLR_PDD_CONTEXT pContext
)
{
PREFAST_DEBUGCHK(pContext);
DEBUGCHK(!pContext->hevInterrupt);
DEBUGCHK(!pContext->hIST);
DEBUGCHK(!pContext->fRunning);
pContext->dwSig = GARBAGE_DWORD;
UnmapRegisterSet(pContext);
if (pContext->hBusAccess) CloseBusAccessHandle(pContext->hBusAccess);
if (pContext->dwSysIntr) {
KernelIoControl(IOCTL_HAL_DISABLE_WAKE, &pContext->dwSysIntr,
sizeof(pContext->dwSysIntr), NULL, 0, NULL);
}
if (pContext->dwIrq != IRQ_UNSPECIFIED) {
KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &pContext->dwSysIntr,
sizeof(DWORD), NULL, 0, NULL);
}
DeleteCriticalSection(&pContext->csIndexedRegisterAccess);
LocalFree(pContext);
}
DWORD
WINAPI
UfnPdd_Deinit(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
RETAILMSG(DBG, (_T("%s UfnPdd_Deinit\r\n"),
pszFname));
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) pvPddContext;
ValidateContext(pContext);
FUNCTION_ENTER_MSG();
FreeCtrlrContext(pContext);
InterruptDisable(g_PlugSysIntr);
SetEvent(g_PlugEvent);
WaitForSingleObject(g_PlugThread, INFINITE);
CloseHandle(g_PlugEvent);
CloseHandle(g_PlugThread);
CloseHandle(g_SdCardDetectThread);
g_PlugThread = NULL;
g_PlugEvent = NULL;
g_SdCardDetectThread = NULL;
if (v_gBspArgs)
{
VirtualFree((PVOID) v_gBspArgs, 0, MEM_RELEASE);
v_gBspArgs = NULL;
}
if (pIOPregs)
{
VirtualFree((PVOID)pIOPregs, 0, MEM_RELEASE);
pIOPregs = NULL;
}
if (pCLKPWR)
{
VirtualFree((PVOID)pCLKPWR, 0, MEM_RELEASE);
pCLKPWR = NULL;
}
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
DWORD
WINAPI
UfnPdd_Start(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
DWORD dwRet;
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) pvPddContext;
ValidateContext(pContext);
FUNCTION_ENTER_MSG();
DEBUGCHK(!pContext->fRunning);
BOOL fIntInitialized = FALSE;
// Create the interrupt event
pContext->hevInterrupt = CreateEvent(0, FALSE, FALSE, NULL);
if (pContext->hevInterrupt == NULL) {
dwRet = GetLastError();
RETAILMSG(DBG, (_T("%s Error creating interrupt event. Error = %d\r\n"),
pszFname, dwRet));
goto EXIT;
}
fIntInitialized = InterruptInitialize(pContext->dwSysIntr,
pContext->hevInterrupt, NULL, 0);
if (fIntInitialized == FALSE) {
dwRet = ERROR_GEN_FAILURE;
RETAILMSG(DBG, (_T("%s interrupt initialization failed\r\n"),
pszFname));
goto EXIT;
}
InterruptDone(pContext->dwSysIntr);
pContext->fExitIST = FALSE;
pContext->hIST = CreateThread(NULL, 0, ISTMain, pContext, 0, NULL);
if (pContext->hIST == NULL) {
RETAILMSG(DBG, (_T("%s IST creation failed\r\n"), pszFname));
dwRet = GetLastError();
goto EXIT;
}
pContext->fRunning = TRUE;
dwRet = ERROR_SUCCESS;
EXIT:
if (pContext->fRunning == FALSE) {
DEBUGCHK(dwRet != ERROR_SUCCESS);
if (fIntInitialized) InterruptDisable(pContext->dwSysIntr);
if (pContext->hevInterrupt) CloseHandle(pContext->hevInterrupt);
pContext->hevInterrupt = NULL;
}
FUNCTION_LEAVE_MSG();
return dwRet;
}
// Stop the device.
DWORD
WINAPI
UfnPdd_Stop(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
RETAILMSG(DBG, (_T("%s UfnPdd_Stop\r\n"),
pszFname));
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) pvPddContext;
ValidateContext(pContext);
DEBUGCHK(pContext->fRunning);
// Stop the IST
pContext->fExitIST = TRUE;
InterruptDisable(pContext->dwSysIntr);
SetEvent(pContext->hevInterrupt);
WaitForSingleObject(pContext->hIST, INFINITE);
CloseHandle(pContext->hevInterrupt);
CloseHandle(pContext->hIST);
pContext->hIST = NULL;
pContext->hevInterrupt = NULL;
ResetDevice(pContext);
pContext->fRunning = FALSE;
// end woo
DEBUGMSG(ZONE_FUNCTION, (_T("%s Device has been stopped\r\n"),
pszFname));
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
DWORD
WINAPI
UfnPdd_IsConfigurationSupportable(
PVOID pvPddContext,
UFN_BUS_SPEED Speed,
PUFN_CONFIGURATION pConfiguration
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
RETAILMSG(DBG, (_T("%s UfnPdd_IsConfigurationSupportable\r\n"),
pszFname));
DEBUGCHK((Speed == BS_FULL_SPEED) | (Speed == BS_HIGH_SPEED));
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) pvPddContext;
ValidateContext(pContext);
// This PDD does not have any special requirements that cannot be
// handled through IsEndpointSupportable.
DWORD dwRet = ERROR_SUCCESS;
FUNCTION_LEAVE_MSG();
return dwRet;
}
//
// Is this endpoint supportable.
DWORD
WINAPI
UfnPdd_IsEndpointSupportable(
PVOID pvPddContext,
DWORD dwEndpoint,
UFN_BUS_SPEED Speed,
PUSB_ENDPOINT_DESCRIPTOR pEndpointDesc,
BYTE bConfigurationValue,
BYTE bInterfaceNumber,
BYTE bAlternateSetting
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
RETAILMSG(DBG, (_T("%s UfnPdd_IsEndpointSupportable\r\n"),
pszFname));
//RETAILMSG(1, (_T("%s UfnPdd_IsEndpointSupportable\r\n"),
// pszFname));
DEBUGCHK(EP_VALID(dwEndpoint));
DEBUGCHK((Speed == BS_FULL_SPEED) | (Speed == BS_HIGH_SPEED));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -