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

📄 utils.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  File:  utils.c
//
//  Generic "utility" routines for the Emdoor XSBASE270_G bootloader.
//
#include <windows.h>
#include <bulverde.h>
#include <XSBASE270_G.h>
#include <oal_memory.h>
#include "loader.h"

//------------------------------------------------------------------------------
//
//  Function:  SpinForever
//
//  Halts the bootloader.
//
void SpinForever(void)
{
    EdbgOutputDebugString("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)
{

    // TODO: increment bytes read to track download progress.

    return(EbootEtherReadData(cbData, pbData));
}


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

⌨️ 快捷键说明

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