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

📄 init.c

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 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.
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004-2007, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//
//  File:  init.c
//
//  MX27 ADS board initialization code.
//
//-----------------------------------------------------------------------------
#include <bsp.h>
#include <pehdr.h>
#include <Romldr.h>
#include "regs.h" // for PMIC

//-----------------------------------------------------------------------------
// Types
#ifndef BSP_NO_TRUST
typedef BOOL (* OEMLoadInit_t)(LPWSTR lpszName);
typedef DWORD (* OEMLoadModule_t)(LPBYTE lpData, DWORD cbData);
#endif // BSP_NO_TRUST

//-----------------------------------------------------------------------------
// External Functions

// External Functions
extern BOOL OALDisplaySplashScreen(void);
extern wdogReset_c WdogGetReset(void);
extern BOOL OALPmicWrite(UINT32 addr, UINT32 data);

#ifndef BSP_NO_TRUST
extern BOOL InitPubKey(const BYTE *KeyBlob, DWORD cbKeyBlob);
extern BOOL OEMCertifyModuleInit(LPWSTR lpModuleName);
extern DWORD OEMCertifyModule(LPBYTE lpData, DWORD cbData);
#endif // BSP_NO_TRUST
extern UINT32 OALTimerGetClkFreq(void);
extern UINT32 OALTimerGetClkPrescalar(void);
extern BOOL OALPmicInit(UINT32 voltCodeNormal, UINT32 voltCodeStandby);

//-----------------------------------------------------------------------------
// External Variables


#ifndef BSP_NO_TRUST
extern OEMLoadInit_t pOEMLoadInit;
extern OEMLoadModule_t pOEMLoadModule;

/*
 * This is the public used to verify the signature of trusted applications.
 */
static const unsigned char g_bSignPublicKeyBlob[] = {
    0x06,0x02,0x00,0x00,0x00,0x24,0x00,0x00,0x52,0x53,0x41,0x31,0x00,0x02,
    0x00,0x00,0x01,0x00,0x01,0x00,0x53,0x93,0xe8,0x12,0x13,0x63,0x44,0x9e,
    0x07,0xd7,0xb7,0xa3,0x20,0x2c,0x2f,0xe7,0x95,0x23,0xba,0xec,0x79,0xa9,
    0x37,0xd3,0x09,0xd7,0x53,0x47,0x27,0x76,0x10,0x1d,0xbd,0x22,0x61,0xd0,
    0x82,0x91,0x26,0xf6,0x1f,0x94,0x74,0x24,0xbc,0xe6,0xd1,0x07,0x86,0x2f,
    0xad,0x60,0x50,0x7e,0x55,0xb5,0x58,0x46,0xcd,0xe9,0xf5,0x89,0xb1,0xe5
};
#endif // BSP_NO_TRUST

#if !(UNDER_CE >= 600)
// WinCE 6.00 does not define lpNKHaltSystem.
extern void (*lpNKHaltSystem)(void);
#endif

//-----------------------------------------------------------------------------
// Global Variables

//
//  Global:  dwOEMDrWatsonSize
BOOL coldBoot = FALSE;

//
//  Global:  dwOEMDrWatsonSize
//
//  Global variable which specify DrWatson buffer size. It can be fixed
//  in config.bib via FIXUPVAR.
//
#define DR_WATSON_SIZE_NOT_FIXEDUP (-1)
DWORD dwOEMDrWatsonSize = DR_WATSON_SIZE_NOT_FIXEDUP;

//-----------------------------------------------------------------------------
//
// Function: OEMHaltSystem
//
// Function turns on leds to indicate error condition before system halt.
//
// Parameters:
//
// Returns:
//      
//
//-----------------------------------------------------------------------------
void OEMHaltSystem(void)
{
    CSP_PBC_REGS *pPBC;

    // On both on board leds
    pPBC = (PCSP_PBC_REGS)OALPAtoVA((UINT32)BSP_BASE_REG_PA_PBC_BASE, FALSE);
    OUTREG16(&pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_LED_1));
    OUTREG16(&pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_LED_2));
}

//------------------------------------------------------------------------------
//
//  Function:  OEMInit
//
//  This is Windows CE OAL initialization function. It is called from kernel
//  after basic initialization is made.
//
void OEMInit()
{

    wdogReset_c ResetType;
    
    OALMSG(OAL_FUNC, (L"+OEMInit\r\n"));

    // Set memory size for DrWatson kernel support.
    dwNKDrWatsonSize = 0;
    if (dwOEMDrWatsonSize != DR_WATSON_SIZE_NOT_FIXEDUP)
    {
        dwNKDrWatsonSize = dwOEMDrWatsonSize;
    }

    // Define optional kernel supported features.
    pOEMIsProcessorFeaturePresent = OALIsProcessorFeaturePresent;

#if (UNDER_CE >= 600) // WinCE 6.00 uses g_pOemGlobal data structure.
    // Initialize system halt handler.
    g_pOemGlobal->pfnHaltSystem = OEMHaltSystem;

    // Give kernel access to the profiling functions.
    g_pOemGlobal->pfnProfileTimerEnable  = OEMProfileTimerEnable;
    g_pOemGlobal->pfnProfileTimerDisable = OEMProfileTimerDisable;
#else
    // Initialize system halt handler.
    lpNKHaltSystem = OEMHaltSystem;
#endif

    // Expose the processor type.
    CEProcessorType = PROCESSOR_ARM920;

    // Initilize cache globals
    OALCacheGlobalsInit();

    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"   Cache:\r\n"));
    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"       L1Flags:       0x%08x\r\n",
                                       g_oalCacheInfo.L1Flags));
    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"       L1ISetsPerWay: 0x%08x (%d)\r\n",
                                       g_oalCacheInfo.L1ISetsPerWay,
                                       g_oalCacheInfo.L1ISetsPerWay));
    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"       L1INumWays:    0x%08x (%d)\r\n",
                                       g_oalCacheInfo.L1INumWays,
                                       g_oalCacheInfo.L1INumWays));
    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"       L1ILineSize:   0x%08x (%d)\r\n",
                                       g_oalCacheInfo.L1ILineSize,
                                       g_oalCacheInfo.L1ILineSize));
    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"       L1ISize:       0x%08x (%d)\r\n",
                                       g_oalCacheInfo.L1ISize,
                                       g_oalCacheInfo.L1ISize));
    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"       L1DSetsPerWay: 0x%08x (%d)\r\n",
                                       g_oalCacheInfo.L1DSetsPerWay,
                                       g_oalCacheInfo.L1DSetsPerWay));
    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"       L1DNumWays:    0x%08x (%d)\r\n",
                                       g_oalCacheInfo.L1DNumWays,
                                       g_oalCacheInfo.L1DNumWays));
    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"       L1DLineSize:   0x%08x (%d)\r\n",
                                       g_oalCacheInfo.L1DLineSize,
                                       g_oalCacheInfo.L1DLineSize));
    OALMSGS(OAL_CACHE && OAL_VERBOSE, (L"       L1DSize:       0x%08x (%d)\r\n",
                                       g_oalCacheInfo.L1DSize,
                                       g_oalCacheInfo.L1DSize));

#ifndef BSP_NO_TRUST
    // Set the module signature verification hooks.
    pOEMLoadInit = OEMCertifyModuleInit;
    pOEMLoadModule = OEMCertifyModule;

    // Initialize the signature verification public key.
    InitPubKey(g_bSignPublicKeyBlob, sizeof(g_bSignPublicKeyBlob));
#endif // BSP_NO_TRUST

    // Clean RAMFree Signature for Cold Boot
    //
    ResetType = WdogGetReset();
    if(ResetType == wdogResetPowerOn)
    {
        // Power On Reset
        OALMSG(OAL_INFO, (L"Power on Reset - Clear RAM\r\n"));
        // NKForceCleanBoot() is required for WinCE .Net 4.2 and later.
        // deprecated: memset((void*)pTOC->ulRAMFree, 0, sizeof(DWORD)*3);
        NKForceCleanBoot();
        coldBoot = TRUE;
    }
	
    // Initialize interrupts
    if (!OALIntrInit()) {
        OALMSG(OAL_ERROR, (
            L"ERROR: OEMInit: failed to initialize interrupts\r\n"
        ));
    }

    // Display splash screen
    OALDisplaySplashScreen();

    // Initialize system clock
    OALTimerInit(RESCHED_PERIOD, OEM_TICKS_1MS, OEM_TICKS_MARGIN);

    // Initialize the PMIC interface
    OALPmicInit(BSP_PMIC_NORMAL_VOLT, BSP_PMIC_STANDBY_VOLT);

    // adjust ARM to 400MHz if necessary
#if (BSP_CSCR_ARMSRC==1) && (BSP_CSCR_ARMDIV==0)
    {
    CSP_PLLCRC_REGS *pPLLCRC = (CSP_PLLCRC_REGS*)OALPAtoUA(CSP_BASE_REG_PA_CRM);
    DWORD oldclk;
    DWORD clkreg = INREG32(&pPLLCRC->CSCR);


    // first raise pmic voltage
    OALMSG(OAL_INFO,(TEXT("OEMInit: raising PMIC voltage\r\n")));

    OALPmicWrite(MC13783_SW0_ADDR, 0x17);

    oldclk = clkreg;
    INSREG32BF(&clkreg,PLLCRC_CSCR_ARMSRC,BSP_CSCR_ARMSRC);
    INSREG32BF(&clkreg,PLLCRC_CSCR_ARMDIV,BSP_CSCR_ARMDIV);

    OALMSG(OAL_INFO,
            (TEXT("OEMInit: Updating CSCR from 0x%x to 0x%x ...\r\n"),oldclk, clkreg));

    OUTREG32(&pPLLCRC->CSCR, clkreg);

    clkreg = INREG32(&pPLLCRC->CSCR);
    OALMSG(OAL_INFO,(TEXT("OEMInit: Updated CSCR to 0x%x\r\n"),clkreg));
    }
#endif

    // Initialize the KITL connection if required
    KITLIoctl(IOCTL_KITL_STARTUP, NULL, 0, NULL, 0, NULL);

    OALMSG(OAL_FUNC, (L"-OEMInit\r\n"));
}

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

⌨️ 快捷键说明

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