📄 power.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: power.c
//
#include <windows.h>
#include <ceddk.h>
#include <nkintr.h>
#include <oal.h>
#include <vrc5477.h>
//------------------------------------------------------------------------------
//
// External: g_oalLastSysIntr
//
// This global variable should be set by interrupt handler to last SYSINTR
// when interrupt occurs. It is used by fake (busy loop) idle/power off OAL
// implementations.
//
extern volatile UINT32 g_oalLastSysIntr;
//------------------------------------------------------------------------------
//
// Function: OEMPowerOff
//
// Called when the system is to transition to it's lowest power mode (off).
// On Vrc5477 there isn't way how to power off system, so implementation
// uses fake power off.
//
void OEMPowerOff(void)
{
VRC5477_REGS *pVRC5477Regs = OALPAtoUA(VRC5477_REG_PA);
UINT32 sysIntr, mask0, mask1, mask2, mask3;
RETAILMSG(TRUE, (L"*** Power OFF ***\n"));
// Save the current interrupt masks
mask0 = INREG32(&pVRC5477Regs->INTCTRL0);
mask1 = INREG32(&pVRC5477Regs->INTCTRL1);
mask2 = INREG32(&pVRC5477Regs->INTCTRL2);
mask3 = INREG32(&pVRC5477Regs->INTCTRL3);
// Disable all interrupts
CLRREG32(&pVRC5477Regs->INTCTRL0, 0x88888888);
CLRREG32(&pVRC5477Regs->INTCTRL1, 0x88888888);
CLRREG32(&pVRC5477Regs->INTCTRL2, 0x88888888);
CLRREG32(&pVRC5477Regs->INTCTRL3, 0x88888888);
// Let BSP do board specific stuff
BSPPowerOff();
// Now enable interrupt if it was enabled as wakeup source
for (sysIntr = SYSINTR_FIRMWARE; sysIntr < SYSINTR_MAXIMUM; sysIntr++) {
// Skip if sysIntr isn't allowed as wake source
if (!OALPowerWakeSource(sysIntr)) continue;
// Enable it as interrupt
OEMInterruptEnable(sysIntr, NULL, 0);
}
// Then power off KITL
OALKitlPowerOff();
// There isn't power off CPU mode, so we use busy loop
do {
g_oalLastSysIntr = SYSINTR_NOP;
INTERRUPTS_ON();
while (g_oalLastSysIntr == SYSINTR_NOP);
INTERRUPTS_OFF();
} while (!OALPowerWakeSource(g_oalLastSysIntr));
// Save wake source
g_oalWakeSource = g_oalLastSysIntr;
// Restore KITL
OALKitlPowerOn();
// Then let BSP do board specific stuff
BSPPowerOn();
// Restore original interrupt masks
OUTREG32(&pVRC5477Regs->INTCTRL0, mask0);
OUTREG32(&pVRC5477Regs->INTCTRL1, mask1);
OUTREG32(&pVRC5477Regs->INTCTRL2, mask2);
OUTREG32(&pVRC5477Regs->INTCTRL3, mask3);
RETAILMSG(TRUE, (L"*** Power ON ***\n"));
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -