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

📄 kitl.c

📁 我自己编译的armv4i wince60模拟器的bps源文件,已经验证可以使用,欢迎下载
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//------------------------------------------------------------------------------
//
//  File:  kitl.c
//
//  Support routines for KITL. 
//
//------------------------------------------------------------------------------

#include <bsp.h>
#include <kitl_cfg.h>
#include <fmd.h>


//------------------------------------------------------------------------------
//
// Platform entry point for KITL.  Called when KITLIoctl (IOCTL_KITL_STARTUP, ...) is called.
//
BOOL OEMKitlStartup(void)
{
    BOOL rc;
    OAL_KITL_ARGS *pArgs, args;
    CHAR *szDeviceId, buffer[OAL_KITL_ID_SIZE];

    KITL_RETAILMSG(ZONE_KITL_OAL, ("+OEMKitlStartup\r\n"));

    // Print banner.  Will remove when KITL-over-ethernet support is dropped
    // (in M3)
    KITLOutputDebugString("\n*********************************************\n");
    KITLOutputDebugString("*                                           *\n");
    KITLOutputDebugString("*  This image uses KITL-over-ethernet       *\n");
    KITLOutputDebugString("*                                           *\n");
    KITLOutputDebugString("*  PB Connectivity Options must be set to:  *\n");
    KITLOutputDebugString("*  Download:  \"Device Emulator\"             *\n");
    KITLOutputDebugString("*  Transport: \"Ethernet\"                    *\n");
    KITLOutputDebugString("*                                           *\n");
    KITLOutputDebugString("*********************************************\n\n");


    // Look for bootargs left by the bootloader or left over from an earlier boot.
    //
    pArgs      = (OAL_KITL_ARGS*)OALArgsQuery(OAL_ARGS_QUERY_KITL);
    szDeviceId = (CHAR*)OALArgsQuery(OAL_ARGS_QUERY_DEVID);

    // If we don't have bootargs in RAM, look first in NOR flash for the information
    // otherwise look on the SmartMedia NAND card (in case we're performing a NAND-only) boot.
    //
    if (pArgs == NULL)
    {
        SectorInfo si;
        UINT8 maccount = 0;

        // Get MAC address from NAND flash...
        //
        if (FMD_Init(NULL, NULL, NULL) == NULL)
        {
            KITL_RETAILMSG(ZONE_ERROR, ("ERROR: Failed to initialize NAND flash controller.\r\n"));
            return(FALSE);
        }

        // If block 0 isn't reserved, we can't trust that the values we read for the MAC address are
        // correct.  They may actually be valid logical sector numbers (we're overloading the use
        // of the logical sector number field).
        //
        if (!(FMD_GetBlockStatus(0) & BLOCK_STATUS_RESERVED))
        {
            KITL_RETAILMSG(ZONE_ERROR, ("ERROR: Block 0 isn't reserved - can't trust MAC address values stored in NAND.\r\n"));
            return(FALSE);
        }

        KITL_RETAILMSG(ZONE_KITL_OAL, ("INFO: Using KITL arguments stored on SmartMedia.\r\n"));
        memset(&args, 0, sizeof(args));
        args.flags = OAL_KITL_FLAGS_ENABLED | OAL_KITL_FLAGS_DHCP | OAL_KITL_FLAGS_VMINI;
        args.devLoc.IfcType = Internal;
        args.devLoc.BusNumber = 0;
        args.devLoc.LogicalLoc = BSP_BASE_REG_PA_CS8900A_IOBASE;
        args.ipAddress = 0;

        // We know the first block of NAND flash must be good, so we needn't worry about bad blocks when reading.
        //
        maccount = 0;
        do
        {
            if (!FMD_ReadSector(maccount, NULL, &si, 1))
            {
                KITL_RETAILMSG(ZONE_ERROR, ("ERROR: NAND flash read error (sector = 0x%x).\r\n", maccount));
                return(FALSE);
            }

            args.mac[maccount] = (UINT16)(si.dwReserved1 & 0xFFFF);

        } while(++maccount < 3);

        pArgs = &args;
    }        

    // If there isn't a device ID from the bootloader create one.
    //
    if (szDeviceId == NULL)
    {
        OALKitlCreateName(BSP_DEVICE_PREFIX, pArgs->mac, buffer);
        szDeviceId = buffer;
    }

    // Finally call KITL library.
    //
    rc = OALKitlInit(szDeviceId, pArgs, g_kitlDevices);

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

DWORD OEMEthGetSecs (void)
{
    SYSTEMTIME st;
    DWORD dwRet;
    static DWORD dwBias;
    static DWORD dwLastTime;

    OEMGetRealTime( &st );
    dwRet = ((60UL * (60UL * (24UL * (31UL * st.wMonth + st.wDay) + st.wHour) + st.wMinute)) + st.wSecond);
    dwBias = dwRet;

    if (dwRet < dwLastTime) {
        KITLOutputDebugString("! Time went backwards (or wrapped): cur: %u, last %u\n",
                              dwRet,dwLastTime);
    }
    dwLastTime = dwRet;
    return (dwRet);
}


//------------------------------------------------------------------------------
//
//  Function:  OALGetTickCount
//
//  This function is called by some KITL libraries to obtain relative time
//  since device boot. It is mostly used to implement timeout in network
//  protocol.
//

UINT32 OALGetTickCount()
{
    return OEMEthGetSecs () * 1000;
}

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


⌨️ 快捷键说明

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