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

📄 utils.c

📁 Windows CE 6.0 BSP for VOIPAC Board (PXA270) Version 2b.
💻 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:  utils.c
//
//  Generic "utility" routines for the Intel Mainstone II bootloader.
//
#include <windows.h>
#include <bulverde.h>
#include <mainstoneii.h>
#include <oal_memory.h>
#include "loader.h"

extern BOOLEAN g_SerialUSBDownload;
extern BOOL SerialReadData (DWORD cbData, LPBYTE pbData);

//------------------------------------------------------------------------------
//
//  Function:  SpinForever
//
//  Halts the bootloader.
//
void SpinForever(void)
{
    KITLOutputDebugString("SpinForever...\r\n");

    while (1)
    {
        ;
    }
}


//------------------------------------------------------------------------------
//
//  Function:  OutputDebugStringW
//
//  Output unicode string to debug serial port.
//
void OutputDebugStringW(LPCWSTR string)
{
    while (*string != L'\0') OEMWriteDebugByte((UINT8)*string++);
}


//------------------------------------------------------------------------------
//
//  Function:  OEMReadData
//
//  Reads data from the download transport.
//
BOOL OEMReadData(DWORD cbData, LPBYTE pbData)
{
    if( g_SerialUSBDownload )
    {
        return(SerialReadData(cbData, pbData));
    }
    else
    {
        // TODO: increment bytes read to track download progress.
        return(EbootEtherReadData(cbData, pbData));
    }
    
    // We won't get here but...
    return 0;
}


//------------------------------------------------------------------------------
//
//  Function:  OEMShowProgress
//
//  Updates a download progress indicator.
//
void OEMShowProgress(DWORD dwPacketNum)
{
}


static UINT32 IsLeapYear(UINT32 Year)
{
    UINT32 Leap;

    Leap = 0;
    if ((Year % 4) == 0)
    {
        Leap = 1;
        if ((Year % 100) == 0)
        {
            Leap = (Year % 400) ? 0 : 1;
        }
    }

    return(Leap);
}


#define ORIGINYEAR  1980
#define JAN1WEEK    2       /* Tuesday */
static unsigned int monthtable[]      = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static unsigned int monthtable_leap[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

static void FormatSystemTime(UINT32 CurrTime, LPSYSTEMTIME pSysTime)
{
    UINT32 ms, sec, min, hour, day, month, year, leap;
    UINT32 *mtbl;

    ms   = 0;
    sec  = CurrTime % 60;
    min  = (CurrTime / 60);
    hour = (min / 60);
    day  = (hour / 24);

    pSysTime->wMilliseconds = ms;
    pSysTime->wSecond       = sec;
    pSysTime->wMinute       = (min % 60);
    pSysTime->wHour         = (hour % 24);
    pSysTime->wDayOfWeek    = (day + JAN1WEEK) % 7;

    year = ORIGINYEAR;
    while (TRUE)
    {
        leap = IsLeapYear(year);
        if (day < 365+leap)
            break;
        day -= 365+leap;
        year++;
    }
    pSysTime->wYear = year;

    mtbl = leap ? monthtable_leap : monthtable;
    for (month=0; month<12; month++) {
        if (day < mtbl[month])
            break;
        day -= mtbl[month];
    }

    pSysTime->wDay = day+1;
    pSysTime->wMonth = month+1;

    return;

}


BOOL OEMGetRealTime(LPSYSTEMTIME pSysTime)
{
    volatile BULVERDE_RTC_REG *pRTCRegs = NULL;
    UINT32 CurrTime = 0;

    // Get the RTC value.
    //
    pRTCRegs = (volatile XLLP_RTC_T *)OALPAtoVA(BULVERDE_BASE_REG_PA_RTC, FALSE);
    CurrTime  = pRTCRegs->rcnr;

    FormatSystemTime(CurrTime, pSysTime);

    return(TRUE);

}


DWORD OEMKitlGetSecs(void)
{
    SYSTEMTIME st;

    OEMGetRealTime( &st );

    return((60UL * (60UL * (24UL * (31UL * st.wMonth + st.wDay) + st.wHour) + st.wMinute)) + st.wSecond);
}


//------------------------------------------------------------------------------
//
//  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 OEMKitlGetSecs () * 1000;
}


//------------------------------------------------------------------------------
//
//  Function:  NKCreateStaticMapping
//
//  Stub needed by mainstoneii_usbfn_rndiskitl.lib. When linking with EBOOT.exe
//  use the stub. When linking with KITL.dll use the real function.
//

VOID* NKCreateStaticMapping(DWORD phBase, DWORD size)
{
    return OALPAtoUA(phBase << 8);
}


//------------------------------------------------------------------------------
//
//  Function:  INTERRUPTS_ENABLE
//
//  Stub needed by mainstoneii_usbfn_rndiskitl.lib. When linking with EBOOT.exe
//  use the stub. When linking with KITL.dll use the real function.
//

BOOL INTERRUPTS_ENABLE(BOOL fEnable) 
{
    return FALSE;
}

⌨️ 快捷键说明

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