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

📄 powermanage.c

📁 厂家正规的boot源代码
💻 C
字号:
#include "def.h"
#include "2410addr.h"
#include "2410lib.h"
#include "timer.h"
#include "PowerManage.h"

extern int PwrKeyChkEnd;
extern U32	Console_Baud;

//*****************************************************************************
void LcdBackLightOn(void)
{
	rGPGCON |=3<<8;
	rGPGDAT &=0x0<<4;		//output 0;
}

//*****************************************************************************
//__inline int PwrKeyWake(void)
int PwrKeyWake(void)
{
	int ret;
	
	ret = rEINTPEND&(1<<4);	//check if EINT4 is pending
	rEINTPEND = ret;			//clear pending		
	return ret;
}

//*****************************************************************************
void PwrKeyChkInit(void)
{

	rGPFCON =0x5aaa;
	rGPFUP =0x0;	
}

//*****************************************************************************
//每10ms检测一次,每次读10次键,共测750ms,第一次跳过.
void PwrKeyChk(U32 i)
{
	static U16 chk_times = 75;
	U32 cnt;
	
	if(chk_times!=75) {
		for(cnt=0; cnt<10; cnt++)
			if(rGPGDAT&(1<<3)) {
				PwrKeyChkEnd = -1;
				return;
			}
	}	
	chk_times--;
	if(!chk_times) {
		PwrKeyChkEnd = 0;
		ReleaseBiosTimerEvent(i);
	}
}

//*****************************************************************************
void EnterPowerOff(void)
{
	U32 r;
	
	Uart_Printf("Enter Power-off mode, press Reset or UP(EINT0) key to wake up\n");
	Uart_TxEmpty(0);	//Wait until UART0 Tx buffer empty.

	ConfigPowerOffGPIO();
	PwrKeyChkInit();

    rEINTPEND = 1<<11;					//clear EINT11
	rEXTINT1  = 0;						//EINT11 low-level interrupt
    rEINTMASK = rEINTMASK&~(1<<11); 	//SRCPND:EINT8_23 will be set by EINT19 after wake-up.
	ClearPending(BIT_EINT8_23|BIT_RTC);
	rINTMSK = BIT_ALLMSK;

	rRTCCON = 0x0;		//R/W disable, 1/32768, Normal(merge), No reset
	rADCCON |= (1<<2);	//ADC additional power down

	rGSTATUS3 = (U32)StartPointAfterPowerOffWakeUp;
	rGSTATUS4 = 0xbe50dead;
	
	//MISCCR[13:12] set usb port0,1 suspend
	//MISCCR[2] Previous state at STOP(?) mode (???)
	//MISCCR[1:0] D0~D31 pull-up disable	
	rMISCCR |= 0x3007;

	rLCDCON1 &= ~1;		//Before entering STOP mode, LCD must be off
	
	//=================================================================
	//  VERY IMPORTANT NOTE 
	//  To enter STOP/SLIDLE mode, MMU TLB-fill operation should be prohibited
	//  because MTT table is in SDRAM and SDRAM is in the self-refresh mode.
	//  So, we will fill TLB before entering SDRAM self-refresh 
	//  instead of disabling MMU.
	r = rREFRESH;	//To fill TLB for the special register used in EnterPWDN
	r = rCLKCON;
    //=================================================================
    	
	//EnterPWDN(0x7fff8);	//POWER_OFF mode
	rCLKCON = 0x7fff8;		//needn't set sdram sel-refresh, directly power-down
	//Never return here.
}

/******************************************************************************
【函数功能】Slow Mode Test
******************************************************************************/
void Slow_Mode_Test( void )
{
	puts("Prepare to enter slow mode, set baud rate to 9600 and press any key to continue\n");
	SetSysFclk(FCLK_48M);
	SetClockDivider(0, 0);
	ChangeSlowMode(CLKSLOW_PLL_OFF);	//disable MPLL and UPLL, enter slow mode
	Uart_Init(0, Console_Baud);
	getch();
	printf("Enter slow mode FCLK = %d, HCLK = %d, PCLK = %d\n", SYS_FCLK, SYS_HCLK, SYS_PCLK);
}

⌨️ 快捷键说明

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