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

📄 init.c

📁 Intel DBPXA27X评估板OAL层代码.
💻 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:  init.c
//
//  Intel Mainstone II board initialization code.
//
#include <bsp.h>
#ifdef MODULE_CERTIFY
#include <secload.h>
#endif
// External function prototypes.
//
extern void IPMRegisterMapping(void);
extern TURN_ON_BTB(void);
extern void InitDebugSerial(UINT32 DbgSerPhysAddr, BOOL bUsePhysAddresses);

// A home for miscellaneous actions that must be performed after Sleep
//  reset (resume) as well as on power up.
// Defined in debug.c because of linker reasons in other modules.
// Post-sleep execution occurs in pmgr.c\PmgrOsResumeOptionalFn()
extern void OEMExecuteAfterAllResets(void);


// Function pointers for Saving/Restoring CoProc Register
extern void (* pOEMInitCoProcRegisterSavedArea) (LPBYTE pArea);
extern void (* pOEMRestoreCoProcRegister) (LPBYTE);
extern void (* pOEMSaveCoProcRegister)(LPBYTE);

// Saving/Restoring CoProc Register Prototypes
void OEMInitCoProcRegisterSavedArea(LPBYTE pArea);
void OEMSaveCoProcRegister( LPBYTE pArea );
void OEMRestoreCoProcRegister( LPBYTE pArea);

// Function to enable the CP0 & CP1 access bits in CP15
extern void Xllp_Set_CoProc_Access(void);

// Prototypes for Assembly routines used for saving/restoring CoProc Registers
extern void Xllp_Save_WMMX_Regs(LPBYTE pArea);
extern void Xllp_Restore_WMMX_Regs(LPBYTE pArea);

extern DWORD cbNKCoProcRegSize;
extern DWORD fNKSaveCoProcReg;

#ifdef USING_XSCALEBROWSER
static BYTE TraceBuffer[20][268]; // space for 20 captures
#endif


// External global variables.
//
extern DWORD dwNKDrWatsonSize;
extern DWORD CEProcessorType;   // From nkarm.h in the private tree

// Cache-related variables.
//
#define ZBANK_BASE_C_VIRTUAL        0x9A500000
DWORD CacheBufferFlag;  // NOTE: this needn't be a const variable and OEMCacheRangeFlush won't be called before KernelRe locate.
const LPVOID gpvCacheFlushBaseMemoryAddress = (LPVOID)ZBANK_BASE_C_VIRTUAL;

// Common timer routine constants.
//
const DWORD OEMTimerFreq     = OEM_CLOCK_FREQ;
const int OEMMinTickDistance = (OEM_CLOCK_FREQ / 20000);    // 50 us

//------------------------------------------------------------------------------
//
//  Function:  OEMInit
//
//  This is Windows CE OAL initialization function. It is called from kernel
//  after basic initialization is made.
//
void OEMInit()
{
    volatile MAINSTONEII_BLR_REGS *pBLRegs = (volatile MAINSTONEII_BLR_REGS *) OALPAtoVA(MAINSTONEII_BASE_REG_PA_FPGA, FALSE);

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

    //
    // Expose the MainstoneII processor type.
    CEProcessorType = PROCESSOR_ARM920;
#ifdef MODULE_CERTIFY
    LOADAUTH_Init();
#endif

    // Enable the branch-target buffer.
    //
    TURN_ON_BTB();

    // Set memory size for DrWatson kernel support.
    //
    dwNKDrWatsonSize = 128 * 1024;

    // Intialize optional kernel functions.
    //
    pOEMIsProcessorFeaturePresent = OALIsProcessorFeaturePresent;

    #if defined(USING_COPROCSUPPORT) || defined(USING_XSCALEBROWSER)
    // Setup Saving & Restoring of CoProcessor Registers

    //Assembly routine to turn on CP0 access bit located in cpregXsc1.s
    // NOTE:  If access bits are not enabled, when saving/restoring/accessing
    //  CP0, will get an undefined exception!!!!
    // Note:  The save/restore functions assume bit is enabled, a user can
    //  create an IOCTL that can disable it and cause undefined exceptions!!

    // NSC: commented out
    // ENABLE_COPROC_ACCESS();

    //Set the buffer size to 8 bytes, to accomidate 16X64-bits + 6X32-bits (with alignment)
    cbNKCoProcRegSize = 156;  //Add 4 bytes to save off flags (keeping alignment)
    fNKSaveCoProcReg = 1;

    // Now setup the callback pointers
    pOEMInitCoProcRegisterSavedArea = OEMInitCoProcRegisterSavedArea;
    pOEMRestoreCoProcRegister = OEMRestoreCoProcRegister;
    pOEMSaveCoProcRegister = OEMSaveCoProcRegister;

#endif //USING_COPROCSUPPORT

#ifdef USING_XSCALEBROWSER
    XSCBwrInitExecutionTrace(TraceBuffer, sizeof(TraceBuffer));
#endif //USING_XSCALEBROWSER

    // Initialize interrupts.
    //
    if (!OALIntrInit())
    {
        OALMSG(OAL_ERROR, (
                          L"ERROR: OEMInit: failed to initialize interrupts.\r\n"
                          ));
    }

    // Initialize system clock.
    //
    OALTimerInit(1, OEM_TICKS_1MS, OEM_TICK_COUNT_MARGIN);

    // Initialize the KITL connection if required.
    //
    OALKitlStart();

    // Switch on the audio amplifier.
    //
    pBLRegs->misc_wr2 &= ~(1 << 2);
	IPMRegisterMapping();

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


VOID OALStall(UINT32 microSec)
{
    volatile PBULVERDE_OST_REG pOSTRegs = NULL;

    pOSTRegs = (PBULVERDE_OST_REG)OALPAtoVA(BULVERDE_BASE_REG_PA_OST, FALSE);

    XllpOstDelayMicroSeconds(pOSTRegs, microSec);
}


VOID OEMInitDebugSerial(void)
{
    UINT32 *pDbgSerPhysAddr = (UINT32*) OALArgsQuery(BSP_ARGS_QUERY_DBGSERIAL);

    if (pDbgSerPhysAddr)
    {
        InitDebugSerial(*pDbgSerPhysAddr, FALSE);
    }
}

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


/* ************************************************************************* */
/*
OEMInitCoProcRegisterSavedArea

   This function sets up the memory area allocated for use in saving/restoring
   CoProcessor registers.  This function is called for every thread created.

Parameters
   Pointer to a memory are defined above by the value of cbNkCoProcRegSize

Return Value
   None
*/
/* ************************************************************************* */
void OEMInitCoProcRegisterSavedArea(LPBYTE pArea)
{
    // Set initial state of CoProc Reg Area (which will in turn be the Register value) here
    memset(pArea,0,156);

}


/* ************************************************************************* */
/*
OEMSaveCoProcRegister

   This function calls the Assembly routines to read the contents of the
   CoProcessor register, storing it in pArea.  It is only called when both
   cbNkCoProcRegSize and fNKSaveCoProcReg are fo non-zero values.  This
   function is called every time a thread is to be switched out, so it
   adds to the overall worst-case time of thread switches!

Parameters
   Pointer to a memory are defined above by the value of cbNkCoProcRegSize

Return Value
   None
*/
/* ************************************************************************* */
void OEMSaveCoProcRegister( LPBYTE pArea )
{
#ifdef USING_XSCALEBROWSER
    if (XSCBwrThreadID == GetCurrentThreadId() )
    {
        XSCBwrExecutionTraceOff(0);
        XSCBwrSaveThreadContextArea.ThreadId = XSCBwrThreadID;
        XSCBwrSaveThreadContextArea.ContextPtr = (DWORD) pArea;
        Xllp_Save_WMMX_Regs((LPBYTE)
                            &XSCBwrSaveThreadContextArea.Context_Area[0] );
        return;
    }
#endif // USING_XSCALEBROWSER
    Xllp_Save_WMMX_Regs( pArea );
}


/* ************************************************************************* */
/*
OEMRestoreCoProcRegister

   This function calls the Assembly routines to set the contents of the
   CoProcessor register back to what was stored in pArea.  It is only called
   when both cbNkCoProcRegSize and fNKSaveCoProcReg are fo non-zero values.
   This function is called every time a thread is to be switched in, so it
   adds to the overall worst-case time of thread switches!

Parameters
   Pointer to a memory are defined above by the value of cbNkCoProcRegSize

Return Value
   None
*/
/* ************************************************************************* */
void OEMRestoreCoProcRegister( LPBYTE pArea)
{
#ifdef USING_XSCALEBROWSER
    if (XSCBwrSaveThreadContextArea.ContextPtr == (DWORD) pArea )
    {
        Xllp_Restore_WMMX_Regs( (LPBYTE)&XSCBwrSaveThreadContextArea.Context_Area[0] );
        if ( XSCBwrThreadID == (DWORD) INVALID_HANDLE_VALUE )
        {
            XSCBwrSaveThreadContextArea.ContextPtr = 0;
        }
        else
        {
            XSCBwrExecutionTraceOn(0);
        }
        return;
    }
#endif //USING_XSCALEBROWSER
    Xllp_Restore_WMMX_Regs( pArea );
}





//
// void OEMExecuteAfterAllResets(void);
//   The purpose of this function is to provide a single location for operations that
//   must be performed after Sleep reset as well as at power-on, but which do not belong
//   to a particular driver and are not ideal for low-level assembly startup code.
//
//  It is called from OEMInit() at poweron and from PmgrOsSuspendOptionalFn() after Sleep.
//
// A natural home for this function would be cfwBvd1.c, but that causes linking problemms
//  in at least one driver.

void OEMExecuteAfterAllResets(void)
{

    volatile BULVERDE_MEMCTRL_REG *v_pMEMC = (volatile BULVERDE_MEMCTRL_REG *) OALPAtoVA(BULVERDE_BASE_REG_PA_MEMC, FALSE);

    //  Configure the Arbiter Control Register so that LCD has higher priority than the DMA and GASKET.
    //  Park at the GASKET.  LCD has weight 15, DMA has weight 1, and GASKET has weight 2.
#ifdef BSP_C0_BULVERDE
    v_pMEMC->arb_cntl = 0x01000234; //Park fixed
#else
    v_pMEMC->arb_cntl = 0x000002F1; //no park,  Gasket 1 < LCD weight 2 < DMA 15
#endif

} // OEMExecuteAfterAllResets()

⌨️ 快捷键说明

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