⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kitl.c

📁 Windows CE 6.0 BSP for the Beagle Board.
💻 C
字号:
//
// Copyright (c) Special Computing.  All rights reserved. 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//------------------------------------------------------------------------------
//
//  File:  kitl.c
//
#include <bsp.h>
#include <kitl_cfg.h>
#include <devload.h>

//------------------------------------------------------------------------------
//  Local definition

#ifndef HKEY_LOCAL_MACHINE
#define HKEY_LOCAL_MACHINE          ((HKEY)(ULONG_PTR)0x80000002)
#endif

//------------------------------------------------------------------------------
//  Local functions

static BOOL SetDeviceDriverFlags(LPCWSTR szKeyPath, DWORD flags);

//------------------------------------------------------------------------------

BOOL OEMKitlStartup()
{
    BOOL rc = FALSE;
    OAL_KITL_ARGS *pArgs, args;
    UINT8 deviceId[OAL_KITL_ID_SIZE];
//    UINT32 sysIntr;

    KITL_RETAILMSG(ZONE_KITL_OAL, ("+OALKitlStart\r\n"));
    
    // First get boot args and device id
    pArgs = (OAL_KITL_ARGS*)OALArgsQuery(OAL_ARGS_QUERY_KITL);
//pArgs = NULL; // force serial kitl

    // If we don't get kitl arguments use default
    if (pArgs == NULL) {
        KITL_RETAILMSG(ZONE_WARNING, ("WARN: Boot arguments not found, use defaults\r\n"));
        memset(&args, 0, sizeof(args));
        args.flags = OAL_KITL_FLAGS_ENABLED|OAL_KITL_FLAGS_POLL;
        args.devLoc.IfcType = Internal;
        args.devLoc.BusNumber = 0;
        args.devLoc.LogicalLoc = KITL_UART_REGS_PA;
		args.baudRate = KITL_UART_DEFAULT_BAUD;
		args.dataBits = 8;
		args.stopBits = 0;    // 0 is 1 stop bit
		args.parity = 0;
		
		pArgs = &args;
    }        

	// Generate device name
    OALKitlCreateName(BSP_DEVICE_PREFIX, NULL, deviceId);

//    pArgs->flags |= OAL_KITL_FLAGS_EXTNAME;

    //// Initialize debug device
    //switch (pArgs->devLoc.IfcType) {
    //case Internal:
    //    //switch (pArgs->devLoc.LogicalLoc) {
    //    //case BSP_SMSC91C96_REGS_PA:
    //    //    //OUTREG16(&pCpld->LANCTL, 0);
    //    //    OALStall(1000);
    //    //    break;
    //    //}
    //    break;
    //}

    // Finally call KITL library
    rc = OALKitlInit(deviceId, pArgs, g_kitlDevices);
    KITL_RETAILMSG(1, ("OALKitlInit(rc = %d)\r\n", rc));

    // If it failed or KITL is disabled
    if (!rc || (pArgs->flags & OAL_KITL_FLAGS_ENABLED) == 0) goto cleanUp;
    
//    // Finalize initialization
//    switch (pArgs->devLoc.IfcType) {
//    case Internal:
//        switch (pArgs->devLoc.LogicalLoc) {
//        case OMAP2420_USBD_REGS_PA:
//#if 0
//            // Add second mapping for USB device interrupt & enable it
//            sysIntr = OALIntrTranslateIrq(IRQ_USB_GENI);  //IRQ_USB
//            OALIntrStaticTranslate(sysIntr, IRQ_USB_GENI);
//            OEMInterruptEnable(sysIntr, NULL, 0);
//#endif     
//			break;
//        }
//        break;
//    }

cleanUp:
    KITL_RETAILMSG(ZONE_KITL_OAL, ("-OALKitlStart(rc = %d)\r\n", rc));
    return rc;
}

//------------------------------------------------------------------------------
//
//  This function creates a unique kitl ID name
//  Note: UUID from OMAP3 chip used, not mac address.
//
VOID OALKitlCreateName(CHAR *pPrefix, UINT16 mac[3], CHAR *pBuffer)
{
    UINT32 code=0, count, d;
    INT32 j;
    OMAP3_DEVICE_DIEID_REGS *pDevIdRegs = OALPAtoUA(OMAP3_DEVICE_DIEID_REGS_PA);

    OALMSG(OAL_KITL&&OAL_FUNC, (
        L"+OALKitlCreateName('%hs', 0x%04x:0x%04x:0x%04x, 0x%08x)\r\n", pPrefix, mac[0],mac[1],mac[2], pBuffer
    ));

    // Copy prefix    
    count = 0;
    while (count < OAL_KITL_ID_SIZE - 1 && pPrefix[count] != '\0') {
        pBuffer[count] = pPrefix[count];
        count++;
    }

    // Create unique part of name from SoC ID
    code  = INREG32(&pDevIdRegs->ulDIE_ID_0);
    code ^= INREG32(&pDevIdRegs->ulDIE_ID_1);
    code ^= INREG32(&pDevIdRegs->ulDIE_ID_2);
    code ^= INREG32(&pDevIdRegs->ulDIE_ID_3);

    // Convert it to hexa number    
    for (j = 28; j >= 0 && count < OAL_KITL_ID_SIZE - 1; j -= 4) {
        d = (code >> j) & 0xF;
        pBuffer[count++] = d < 10 ? '0' + d : 'A' + d - 10;
    }
    pBuffer[count] = '\0';

    OALMSG(OAL_KITL&&OAL_FUNC, (
        L"-OALKitlCreateName(pBuffer = '%hs')\r\n", pBuffer
    ));
}

//------------------------------------------------------------------------------
//
//  Function:  OALKitlInitRegistry
//
VOID OALKitlInitRegistry()
{
    DEVICE_LOCATION devLoc;

    // Just to make sure there is no flag by default
    SetDeviceDriverFlags(L"Drivers\\BuiltIn\\OTG", 0);
    SetDeviceDriverFlags(L"Drivers\\BuiltIn\\HCD", 0);
    SetDeviceDriverFlags(L"Drivers\\BuiltIn\\UFN", 0);

    // Get KITL device location
    if (!OALKitlGetDevLoc(&devLoc)) goto cleanUp;

    // Depending on device bus
    switch (devLoc.IfcType) {
    case Internal:
        switch (devLoc.LogicalLoc) {
        case OMAP2420_USBD_REGS_PA:
            // Make sure that USB drivers are not loaded
            DEBUGMSG(1, (L"OALKitlInitRegistry\r\n"));
            SetDeviceDriverFlags(L"Drivers\\BuiltIn\\OTG", DEVFLAGS_NOLOAD);
            SetDeviceDriverFlags(L"Drivers\\BuiltIn\\HCD", DEVFLAGS_NOLOAD);
            SetDeviceDriverFlags(L"Drivers\\BuiltIn\\UFN", DEVFLAGS_NOLOAD);
            break;
        }
        break;
    }

cleanUp:
    return;
}

//------------------------------------------------------------------------------
UINT32 OALGetTickCount()
{
    return (CurMSec);
}

//------------------------------------------------------------------------------

DWORD OEMEthGetSecs()
{
    return OALGetTickCount()/1000;
}

//------------------------------------------------------------------------------

static BOOL SetDeviceDriverFlags(LPCWSTR szKeyPath, DWORD flags)
{
    BOOL rc = FALSE;
    HKEY hKey;
    UINT32 value;

    // Open/create key
    if (NKRegCreateKeyEx(
        HKEY_LOCAL_MACHINE, szKeyPath, 0, NULL, 0, 0, NULL,
         &hKey, &value
    ) != ERROR_SUCCESS) goto cleanUp;

    // Set value
    rc = NKRegSetValueEx(
        hKey, L"Flags", 0, REG_DWORD, (UCHAR*)&flags, sizeof(DWORD)
    ) == ERROR_SUCCESS;

    // Close key
    NKRegCloseKey(hKey);

cleanUp:
    return rc;
}

//------------------------------------------------------------------------------

⌨️ 快捷键说明

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