www.pudn.com > BIOS-S3C2410.rar > PowerManage.c


#include "def.h" 
#include "2410addr.h" 
#include "2410lib.h" 
#include "timer.h" 
#include "PowerManage.h" 
 
extern int PwrKeyChkEnd; 
extern U32	Console_Baud; 
 
//***************************************************************************** 
void LcdBackLightOff(void) 
{ 
	rGPBCON &= ~3; 
	rGPBCON |= 1;		//set GPB0 as output 
	rGPBDAT &= ~1;		//output 0; 
} 
 
//***************************************************************************** 
//__inline int PwrKeyWake(void) 
int PwrKeyWake(void) 
{ 
	int ret; 
	 
	ret = rEINTPEND&(1<<11);	//check if EINT15 is pending 
	rEINTPEND = ret;			//clear pending		 
	return ret; 
} 
 
//***************************************************************************** 
void PwrKeyChkInit(void) 
{ 
/*	rGPGCON &= ~0xfcf0; 
	rGPGCON |= 0xa000;		//set GPG7 as EINT15, GPG2,3,5,6 as input 
	rGPGUP  &= ~0x80;		//GPG7 pull-up enable 
	rGPGUP  |= 0x6c;		//GPG2,3,5,6 pull-up disable 
	 
	rGPBCON &= ~0xf000;		//set GPB6,7 as input 
	rGPBUP  |= 0xc0;		//GPG6,7 pull-up disable	 
	rGPECON &= ~0xfc00000; 
	rGPECON |= 0x4000000;	//set GPE11,12 as input, GPE13 as output 
	rGPEUP  |= 0x1800;		//GPE11,12 pull-up disable 
	 
	rGPEDAT &= ~0x2000;		//GPE13 output lo*/ 
	 
	rGPGCON &= ~((3<<12)|(3<<4)|(3<<22)|(3<<6)); 
	rGPGCON |= 2<<6;	//set GPG3 as eint11 
	rGPGUP  |= (1<<6)|(1<<2)|(1<<3);	//GPG6,2,3 input, pull-up disable 
	rGPGUP  &= ~(1<<3);					//GPG3 input, pull-up enable 
	 
	rGPECON &= ~((3<<26)|(3<<22)); 
	rGPECON |= (1<<22);		//GPE11 output 
	rGPEUP  |= 1<<13;		//GPE13 input pull-up disable 
	rGPEDAT &= ~(1<<13);	//GPE11 output 0 
	 
	rGPFCON &= ~((3<<4)|3); 
	rGPFUP  |= (1<<2)|1;	 
} 
 
//***************************************************************************** 
//每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 K4 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); 
}