欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

system.c

WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
C
第 1 页 / 共 2 页
字号:
                    SetRegistryConfig(*pSysIntr, (DWORD)*pioPortBase);

                    break;
                }
                if (function == 0 && !(pciConfig.HeaderType & 0x80)) 
                    break;
            }
            if (bFoundIt || length == 0)
                break;
        }

        if (bFoundIt || (length == 0 && device == 0))
            break;
    }

    if (!bFoundIt) {
        DEBUGMSG(ZONE_ERROR, (TEXT("UHCD: Error, can't find USB Controller\r\n")));
        return FALSE;
    }
    DEBUGMSG(ZONE_INIT, (TEXT("UHCD: Revision Stepping value = 0x%02X\r\n"), pciConfig.RevisionID));

    portBase = pciConfig.u.type0.BaseAddresses[UHCD_PIIX4_ADDRESS_REG];

    // If I/O, clear bottom bit and indicate we're in I/O space
    if (portBase & 0x1) {
        inIoSpace = 1;
        portBase &= ~0x1;
    }

    ioPhysicalBase.LowPart = portBase;

    if (HalTranslateBusAddress(PCIBus, bus, ioPhysicalBase, &inIoSpace, 
                               &ioPhysicalBase)) {
        if (!inIoSpace) {
            if ((*pioPortBase = (PUCHAR)MmMapIoSpace(ioPhysicalBase, 
                                                     portRange, FALSE)) == NULL) {
                // We may as well not continue
                DEBUGMSG(ZONE_INIT | ZONE_ERROR, 
                         (TEXT("UHCD: Error mapping I/O Ports.\r\n")));
                return FALSE;
            }
        } else {
            *pioPortBase = (PUCHAR)ioPhysicalBase.LowPart;
        }
    } else {
        DEBUGMSG(ZONE_INIT | ZONE_ERROR, 
                 (TEXT("UHCD: Error translating I/O Ports.\r\n")));
        return FALSE;
    }

    DEBUGMSG(ZONE_INIT, 
             (TEXT("UHCD: ioPhysicalBase 0x%X, IoSpace 0x%X\r\n"),
              ioPhysicalBase.LowPart, inIoSpace));
    DEBUGMSG(ZONE_INIT, 
             (TEXT("UHCD: ioPortBase 0x%X, portBase 0x%X\r\n"),
              *pioPortBase, portBase));

    return TRUE;
}


/* InitializeUHCI
 *
 *  Configure and initialize UHCI card
 *
 * Return Value:
 *  Return TRUE if card could be located and configured, otherwise FALSE
 */
static BOOL 
InitializeUHCI(
    SUhcdPdd * pPddObject,    // IN - Pointer to PDD structure
    LPCWSTR szDriverRegKey)   // IN - Pointer to active registry key string
{
    DWORD dwUseExistingSettings = 1;
    PUCHAR ioPortBase = NULL;
    DWORD dwSysIntr;
    BOOL fResult = FALSE;
    LPVOID pobMem = NULL;
    LPVOID pobUhcd = NULL;

    if (!GetRegistryConfig(&dwUseExistingSettings, &dwSysIntr, (DWORD *)&ioPortBase)) {
        RETAILMSG(1,(TEXT("!UHCD: Error reading registry settings\r\n")));
        return FALSE;
    }
    DEBUGMSG(ZONE_INIT,(TEXT("UHCD: Read config from registry: Use existing: %u, SysIntr: %u, I/O base: %X\r\n"),
                        dwUseExistingSettings,dwSysIntr,ioPortBase));
    fResult   = ConfigureUHCICard(!!dwUseExistingSettings,&ioPortBase, &dwSysIntr);

    if(fResult)
    {
        // The PDD can supply a buffer of contiguous physical memory here, or can let the 
        // MDD try to allocate the memory from system RAM.  In our case, let the MDD do it.
        pobMem = UhcdMdd_CreateMemoryObject(gcTotalAvailablePhysicalMemory, 
                                            gcHighPriorityPhysicalMemory, NULL,NULL); 

        if(pobMem)
        {
            pobUhcd = UhcdMdd_CreateUhcdObject(pPddObject, pobMem,
                    szDriverRegKey, ioPortBase, dwSysIntr);

            fResult = pobUhcd ? TRUE : FALSE;
        }
        else
            fResult = FALSE;

        if(!fResult)
        {
            if(pobUhcd)
                UhcdMdd_DestroyUhcdObject(pobUhcd);
            if(pobMem)
                UhcdMdd_DestroyMemoryObject(pobMem);

            pobUhcd = NULL;
            pobMem = NULL;
        }
    }

    pPddObject->lpvMemoryObject = pobMem;
    pPddObject->lpvUhcdMddObject = pobUhcd;

    return fResult;
}

/* UhcdPdd_Init
 *
 *   PDD Entry point - called at system init to detect and configure UHCI card.
 *
 * Return Value:
 *   Return pointer to PDD specific data structure, or NULL if error.
 */
extern DWORD 
UhcdPdd_Init(
    DWORD dwContext)  // IN - Pointer to context value. For device.exe, this is a string 
                      //      indicating our active registry key.
{
    SUhcdPdd *  pPddObject = malloc(sizeof(SUhcdPdd));
    BOOL        fRet = FALSE;

    if (pPddObject) {
        fRet = InitializeUHCI(pPddObject, (LPCWSTR)dwContext);

        if(!fRet)
        {
            free(pPddObject);
            pPddObject = NULL;
        }
    }

    return (DWORD)pPddObject;
}

/* UhcdPdd_CheckConfigPower
 *
 *    Check power required by specific device configuration and return whether it
 *    can be supported on this platform.  For CEPC, this is trivial, just limit to
 *    the 500mA requirement of USB.  For battery powered devices, this could be 
 *    more sophisticated, taking into account current battery status or other info.
 *
 * Return Value:
 *    Return TRUE if configuration can be supported, FALSE if not.
 */
extern BOOL UhcdPdd_CheckConfigPower(
    UCHAR bPort,         // IN - Port number
    DWORD dwCfgPower,    // IN - Power required by configuration
    DWORD dwTotalPower)  // IN - Total power currently in use on port
{
    return ((dwCfgPower + dwTotalPower) > 500) ? FALSE : TRUE;
}

extern void UhcdPdd_PowerUp(DWORD hDeviceContext)
{
    SUhcdPdd * pPddObject = (SUhcdPdd *)hDeviceContext;
    UhcdMdd_PowerUp(pPddObject->lpvUhcdMddObject);

    return;
}

extern void UhcdPdd_PowerDown(DWORD hDeviceContext)
{
    SUhcdPdd * pPddObject = (SUhcdPdd *)hDeviceContext;

    UhcdMdd_PowerDown(pPddObject->lpvUhcdMddObject);

    return;
}


extern BOOL UhcdPdd_Deinit(DWORD hDeviceContext)
{
    SUhcdPdd * pPddObject = (SUhcdPdd *)hDeviceContext;

    if(pPddObject->lpvUhcdMddObject)
        UhcdMdd_DestroyUhcdObject(pPddObject->lpvUhcdMddObject);
    if(pPddObject->lpvMemoryObject)
        UhcdMdd_DestroyMemoryObject(pPddObject->lpvMemoryObject);

    return TRUE;
}


extern DWORD UhcdPdd_Open(DWORD hDeviceContext, DWORD AccessCode,
        DWORD ShareMode)
{
    UnusedParameter(hDeviceContext);
    UnusedParameter(AccessCode);
    UnusedParameter(ShareMode);

    return 1; // we can be opened, but only once!
}


extern BOOL UhcdPdd_Close(DWORD hOpenContext)
{
    UnusedParameter(hOpenContext);

    return TRUE;
}


extern DWORD UhcdPdd_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
    UnusedParameter(hOpenContext);
    UnusedParameter(pBuffer);
    UnusedParameter(Count);

    return (DWORD)-1; // an error occured
}


extern DWORD UhcdPdd_Write(DWORD hOpenContext, LPCVOID pSourceBytes,
        DWORD NumberOfBytes)
{
    UnusedParameter(hOpenContext);
    UnusedParameter(pSourceBytes);
    UnusedParameter(NumberOfBytes);

    return (DWORD)-1;
}


extern DWORD UhcdPdd_Seek(DWORD hOpenContext, LONG Amount, DWORD Type)
{
    UnusedParameter(hOpenContext);
    UnusedParameter(Amount);
    UnusedParameter(Type);

    return (DWORD)-1;
}


extern BOOL UhcdPdd_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn,
        DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
    UnusedParameter(hOpenContext);
    UnusedParameter(dwCode);
    UnusedParameter(pBufIn);
    UnusedParameter(dwLenIn);
    UnusedParameter(pBufOut);
    UnusedParameter(dwLenOut);
    UnusedParameter(pdwActualOut);

    return FALSE;
}


// Manage WinCE suspend/resume events

// This gets called by the MDD's IST when it detects a power resume.
// The CEPC does not have power suspend/resume functionality so
// there's nothing we need to do beyond merely providing the entry point.
extern void UhcdPdd_InitiatePowerUp (void)
{
    return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -