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

📄 utils.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 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 PMC bootloader.
//
#include <bsp.h>

// For Real Time Clock Support
void InitRTC(void);

extern void Launch(DWORD dwLaunchAddr);

static DWORD g_dwTickCount = 0;
PCSP_EPIT_REG g_pEPIT;

static void InitTimer(void)
{
	g_pEPIT = (PCSP_EPIT_REG) OALPAtoUA(CSP_BASE_REG_PA_EPIT1);
	if (g_pEPIT == NULL)
    {
        OALMSG(OAL_ERROR, (L"+InitTimer:  EPIT1 null pointer!\r\n"));
        return;
    }
    
    // Disable EPIT and clear all configuration bits
    OUTREG32(&g_pEPIT->CR, 0);

    // Assert software reset for the timer
    OUTREG32(&g_pEPIT->CR, CSP_BITFMASK(EPIT_CR_SWR));

    // Wait for the software reset to complete
    while (INREG32(&g_pEPIT->CR) & CSP_BITFMASK(EPIT_CR_SWR));

    // Enable timer for "free-running" mode where timer rolls
    // over from 0x00000000 to 0xFFFFFFFF
    OUTREG32(&g_pEPIT->CR,
        CSP_BITFVAL(EPIT_CR_EN, EPIT_CR_EN_ENABLE) |
        CSP_BITFVAL(EPIT_CR_ENMOD, EPIT_CR_ENMOD_RESUME) |
        CSP_BITFVAL(EPIT_CR_OCIEN, EPIT_CR_OCIEN_DISABLE) |
        CSP_BITFVAL(EPIT_CR_RLD, EPIT_CR_RLD_ROLLOVER) |
        CSP_BITFVAL(EPIT_CR_PRESCALAR, 0x20) | // divide by 32 to produce 1 ms tick
        CSP_BITFVAL(EPIT_CR_SWR, EPIT_CR_SWR_NORESET) |
        CSP_BITFVAL(EPIT_CR_IOVW, EPIT_CR_IOVW_NOOVR) |
        CSP_BITFVAL(EPIT_CR_DBGEN, EPIT_CR_DBGEN_ACTIVE) |
        CSP_BITFVAL(EPIT_CR_WAITEN, EPIT_CR_WAITEN_ENABLE) |
        CSP_BITFVAL(EPIT_CR_DOZEN, EPIT_CR_DOZEN_ENABLE) |
        CSP_BITFVAL(EPIT_CR_STOPEN, EPIT_CR_STOPEN_ENABLE) |
        CSP_BITFVAL(EPIT_CR_OM, EPIT_CR_OM_DICONNECT) |
        CSP_BITFVAL(EPIT_CR_CLKSRC, EPIT_CR_CLKSRC_CKIL)); // select 32khz clock as source


}


void PMCPlatformInit(void)
{

	// TODO: Is the RTC needed?
#if 0
    SYSTEMTIME st;

    // Initialize the RTC
    InitRTC();

    // Check real time clock, initialize if necessary (used for polling in net routines)
    OEMGetRealTime(&st);
    if ((st.wYear < 1601) ||
        (st.wMonth < 1) ||
        (st.wMonth > 12) ||
        (st.wDay < 1) ||
        (st.wDay > 31) ||
        (st.wHour > 23) ||
        (st.wMinute > 59) ||
        (st.wSecond > 59) ||
        (st.wMilliseconds > 999)) {

            OALMSG(OAL_ERROR, (TEXT("ERROR: Invalid time returned from OEMGetRealTime: Year: %u, Month: %u, Day: %u, Hour: %u, Minute: %u, second: %u\n"),
                           st.wYear, st.wMonth,st.wDay, st.wHour, st.wMinute,st.wSecond));
            OALMSG(OAL_INFO, (TEXT("INFO: Resetting real time clock to default date\n")));

        OEMSetRealTime(&default_time);
    }
    else
    {
        OEMSetRealTime(&st);
    }

#endif
	
	// Initialize timer for 1 ms count
	InitTimer();
	
}

//-----------------------------------------------------------------------------
//
// Function: OEMEthGetSecs
//
// Function returns a free-running seconds count.
//
// Parameters:
//
// Returns:
//      DWORD dwSeconds - the count of seconds
//
//-----------------------------------------------------------------------------
DWORD OEMEthGetSecs(void)
{
    SYSTEMTIME st;

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

void Launch2(unsigned int dwPhysLaunchAddr)
{
  	
    PCSP_IPU_REGS g_pIPU;
    PCSP_PBC_REGS g_pPBC;
  	
    // Turn off LCD via PBC to avoid displaying junk on the screen before PMC GUI launches
    g_pPBC = (PCSP_PBC_REGS) OALPAtoUA(BSP_BASE_REG_PA_PBC_BASE);    
    OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_CLEAR_LCDON));

    // Turn OFF LCD backlight
    g_pIPU = (PCSP_IPU_REGS)OALPAtoUA(CSP_BASE_REG_PA_IPU);
    INSREG32BF(&g_pIPU->SDC_CUR_BLINK_PWM_CTRL, IPU_SDC_CUR_BLINK_PWM_CTRL_PWM, 0);
    
    // Jump...
    //
    Launch(dwPhysLaunchAddr);
}

⌨️ 快捷键说明

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