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

📄 idle.c

📁 Windows CE 6.0 BSP for VOIP sample phone. Intel PXA270 platform.
💻 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 OR INDEMNITIES.
//
//------------------------------------------------------------------------------
//
//  File:  idle.c
//

#include <windows.h>
#include <nkintr.h>
#include <pkfuncs.h>
#include <bulverde_base_regs.h>
#include <bulverde_memctrl.h>
#include <bulverde_clkmgr.h>
#include <oal.h>
#include <bsp_cfg.h>
#include <xllp_lcd.h>

//------------------------------------------------------------------------------
// Defines 

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

//------------------------------------------------------------------------------
// Global Variables 
 
//------------------------------------------------------------------------------
// Local Variables 
volatile PBULVERSE_MEMCTRL_REG m_pMemCtrl = 0; 
volatile PBULVERDE_CLKMGR_REG m_pClkMgr = 0;
volatile LCDRegs * m_pLCDRegs = 0;

//------------------------------------------------------------------------------
// Local Functions 
//
//  Function:     OALCPUIdle
//
//  This function is called by the common implementation of variable OEMIdle.
//  OEMIdle is called by the kernel when there are no threads ready to 
//  run. The CPU should be put into a reduced power mode if possible and halted. 
//  It is important to be able to resume execution quickly upon receiving an 
//  interrupt.
//
//  Interrupts are off when OALCPUIdle is called. Interrrupts are also turned off when OALCPUIdle returns.
//

void OALCPUIdle()
{
    INT32 usedCounts, idleCounts;
    UINT32 regVal = 0;
    
    extern void CPUEnterIdle(void);
    extern void CPUEnterDeepIdle(void);
    extern void CPUFreqChange(void);
    extern void CPUFreqSet(void);

    if (!m_pMemCtrl)
        m_pMemCtrl = (PBULVERSE_MEMCTRL_REG) OALPAtoUA(BULVERDE_BASE_REG_PA_MEMC);

    if (!m_pClkMgr)
        m_pClkMgr = (PBULVERDE_CLKMGR_REG) OALPAtoUA(BULVERDE_BASE_REG_PA_CLKMGR);

    if (!m_pLCDRegs)
        m_pLCDRegs = (LCDRegs *) OALPAtoUA(BULVERDE_BASE_REG_PA_LCD);

    // Enable Auto power down of SDRAM & synchronous flash
    //
    m_pMemCtrl->mdrefr |= MEMCTRL_MDREFR_APD;


    // Find how many hi-res ticks was already used
    usedCounts = OALTimerCountsSinceSysTick();

    // We will be waiting this much time
    idleCounts = g_oalTimer.actualCountsPerSysTick;

    // Go into deep idle if we are going to idle for more than 5ms
    // and if both the USB controller and LCD controller are not active
    if ((idleCounts - usedCounts > OEM_TICKS_1MS * 5) &&
         (m_pClkMgr->cken & XLLP_CLKEN_USBCLIENT) == 0 && 
          !(m_pLCDRegs->LCCR0 & LCD_ENB))
    {
        // set CCCR[CPDIS] = 1 to disable core PLL (and thus enter 13MHz mode)
        m_pClkMgr->cccr |= 0x80000000;

        CPUFreqChange();

        // write MDREFR with a new value for refresh interval
        m_pMemCtrl->mdrefr &= 0xFFFFF002;

        // going into idle now will really go in deep idle since we are in 13M mode
        CPUEnterIdle();
        INTERRUPTS_OFF();

        // clear CCCR[CPDIS] to re-enable core PLL (and thus return from 13MHz mode to normal mode)
        // Also set PLL_EARLY_ENABLE=1 to reduce the freq switch time
        regVal = m_pClkMgr->cccr;
        regVal = (regVal & 0x7FFFFFFF) | 0x04000000;
        m_pClkMgr->cccr = regVal;

        // wait for Core PLL to lock
        while((m_pClkMgr->ccsr & 0x20000000) == 0);

        // exit out of 13M mode
        CPUFreqChange(); 

        // set the correct operating frequency
        CPUFreqSet();

        // write MDREFR with a new value for refresh interval
        m_pMemCtrl->mdrefr |= 0x1F;
    }
    else
    {
        // No need to turn interrupts on, CPUEnterIdle will do this automatically.
        // The scheduler does not handle interrupts that occur before 
        // CPUEnterIdle executes! 

        // Do not call INTERRUPTS_ON()
        
        CPUEnterIdle();
        INTERRUPTS_OFF();
    }
   
}
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//
//  Function:     OEMIdle
//
//  This function is called by the kernel when there are no threads ready to 
//  run. The CPU should be put into a reduced power mode if possible and halted. 
//  It is important to be able to resume execution quickly upon receiving an 
//  interrupt.
//
//  Interrupts are disabled when OEMIdle is called and when it returns.
//
//  This implementation doesn't change system tick. It is intend to be used
//  with variable tick implementation. However it should work with fixed
//  variable tick implementation also (with lower efficiency because maximal
//  idle time is 1 ms).
//
VOID OEMIdle(DWORD idleParam)
{
    UINT32 baseMSec;
    INT32 usedCounts, idleCounts;
    ULARGE_INTEGER idle;

    // Get current system timer counter
    baseMSec = CurMSec;
    
    // Find how many hi-res ticks was already used
    usedCounts = OALTimerCountsSinceSysTick();

    // We should wait this time
    idleCounts = g_oalTimer.actualCountsPerSysTick;
    
    // Move SoC/CPU to idle mode
    OALCPUIdle();

    // When there wasn't timer interrupt modify idle time
    if (CurMSec == baseMSec) {
        idleCounts = OALTimerCountsSinceSysTick();
    }

    // Get real idle value. If result is negative we didn't idle at all.
    idleCounts -= usedCounts;
    if (idleCounts < 0) idleCounts = 0;

    // Update idle counters
    idle.LowPart = curridlelow;
    idle.HighPart = curridlehigh;
    idle.QuadPart += idleCounts;
    curridlelow  = idle.LowPart;
    curridlehigh = idle.HighPart;
}


⌨️ 快捷键说明

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