📄 sleep.c
字号:
/*****************************************
NAME: SLEEP.C
DESC: S3C2460X SLEEP mode test code
HISTORY:
2004.06.16 : ver 0.0
******************************************/
#include "def.h"
#include "option.h"
#include "2460addr.h"
#include "2460lib.h"
#include "2460slib.h"
//#include "lcdlib.h"
#include "idle.h"
#include "sleep.h"
extern void __main();
void (*run)(void);
static void LcdEnvidOnOff(unsigned int onoff)
{
if(onoff==1)
rLCDCON1 = rLCDCON1|(3); // ENVID On using Per Frame method
else
rLCDCON1 &= (~3); // ENVID Off using Per Frame method
}
static void __irq Eint0Int(void)//EINT0
{
rEINTPEND=BIT_EINT_0;
ClearPending(BIT_EXT0_3);
printf("__isr EINT0 for SLEEP wake-up.\n\n");
}
static void __irq AlarmInt(void)
{
ClearPending(BIT_RTC);
printf("__isr Alarm int.\n");
}
void ConfigSleepGPIO(void)
{
// Check point
// *** There must not be input floating pins
}
static int onTest = 0;
void Test_SleepMode(void)
{
if( ( rRSTSTAT & (1<<3) ) && !(onTest) ) //Wake-up from SLEEP mode
{
#if CHECK_SDRAM_SELFREFRESH
Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Check NONCACHEABLE AREA
#endif
#if AC97_USE
printf("AC97Codec is going to Normal mode, now.\n");
AC97_Init();
AC97_Codec_Init(22050);
#endif
printf("Wake-up from SLEEP mode\n");
//Check wake-up source
if( rWKUPSTAT & (1<<0) ) // EINT?
{
printf("\n__ Wake-up by EINT\n");
rWKUPSTAT |= (1<<0);
}
else if( rWKUPSTAT & (1<<1) ) // RTC?
{
printf("\n__ Wake-up by RTC\n");
rWKUPSTAT |= (1<<1);
}
else//( rWKUPSTAT & (1<<3) ) // KEY Pad?
{
printf("\n__ Wake-up by key pad\n");
printf("\rWKUPSTAT=0x%x\n", rWKUPSTAT);
rWKUPSTAT |= (1<<3);
}
// The RTC/Key pad does not request INT, only wake the CPU up from sleep mode.
// because all of the int. registers goes to reset state except some GPIO registers(EINTPEND...).
//Unmask interrupt
rINTMSK=rINTMSK&~(BIT_EXT0_3);
rINTMSK=rINTMSK&~(BIT_EXT0_3|BIT_RTC);// RTC is only to test
rEINTMASK=rEINTMASK&~(BIT_EINT_0);
printf("SLEEP mode test is done\n");
rEINTMASK=BIT_EINT_ALLMSK;
rINTMSK=BIT_ALLMSK;
onTest=1;
}
else//Entering into SLEEP mode
{
printf("[SLEEP Mode Test]\n");
//printf("nBATT_FLT pin should be tested.\n");
LcdEnvidOnOff(0); //Before entering SLEEP mode, LCD must be off
Delay(1);
printf("Entering into SLEEP mode\n");
printf("S3C2460 will wake up by EINT0\n");
#if USE_RTC_ALARM
printf("or RTC alarm interrupt.\n");
#endif
//Write SLEEP information into BACKUP AREA
#if CHECK_SDRAM_SELFREFRESH
Test_InitSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Write test data into NONCACHEABLE AREA
#endif
ConfigSleepGPIO();
rRSTCNT=0xffff;
//Config EINT0
rGPJCON = (rGPJCON & ~(0x3)) | (1<<1);
rEINTCON0=0x2; //falling
//Interrupt service routine
pISR_EXT0_3=(unsigned int)Eint0Int; //for EINT0
pISR_RTC=(unsigned int)AlarmInt;
#if USE_RTC_ALARM
SetAlarmWakeUp(5);
#endif
rADCCON|=(1<<2);// To reduce ADC power consumption
//tark ????? USB suspend
rGPJDAT&=~(1<<2);
rGPJCON=rGPJCON&~(3<<4)|(1<<4);//USB off
#if AC97_USE
printf("AC97Codec is going to LP mode, now.\n");
AC97_Init();
AC97_Codec_Init(22050);
AC97_Codec_Cmd(0, 0x26, 0x1000); // AC97CODEC is going to LP mode.
rAC_GLBCTRL&=~(1<<2);
printf("\nNow, SMDK2460 is entering SLEEP mode.\n");
while(!(rUTRSTAT0 & 0x4)); //Wait until tx shifter is empty, to avoid broken character.
#endif
#if (WHICH_PORT == 1) //400 or 496PKG
SRAMKey_Run = 0x10000000;// Change if you want..
#else //416PKG
SRAMKey_Run = 0x20000000;// Change if you want..
#endif
while(!(rUTRSTAT0 & 0x4)); //Wait until tx shifter is empty, to avoid broken character.
//***Enter SLEEP mode
#if USE_WFI
if( !( rPWRCFG & (3<<6) ) )
rPWRCFG |= (3<<6);
MMU_WaitForInterrupt(); // WFI drive the S3C2460 into sleep mode
#else
rPWRMODECON = 0x2bed; // Issue sleep mode command
#endif
}
}
void Test_WarmReset(void)
{
//Return from WarmReset
if( ( rRSTSTAT & (1<<1) ) && !(onTest) )
{
printf("[WarmReset Test]\n");
#if CHECK_SDRAM_SELFREFRESH
Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Check NONCACHEABLE AREA
#endif
onTest=1;
printf("\n[Warm Reset] Test is Done!!!\n");
}
//WarmReset Ready
else
{
printf("[WarmReset Test]\n");
#if CHECK_SDRAM_SELFREFRESH
Test_InitSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Write test data into NONCACHEABLE AREA
#endif
rRSTCNT=0xffff;
SRAMKey_Run = (int)__main;// Change if you want..
rGPJDAT&=~(1<<2);
rGPJCON=rGPJCON&~(3<<4)|(1<<4);//USB off
//Push Warm Reset Botton
printf("Now, Push Warm Reset Botton. \n");
while(1);
}
}
void Test_SoftReset(void)
{
//return from soft reset
if( ( rRSTSTAT & (1<<5) ) && !(onTest) )
{
printf("[SoftReset Test]\n");
#if CHECK_SDRAM_SELFREFRESH
Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Check NONCACHEABLE AREA
#endif
onTest=1;
printf("\n[SoftReset] Test is Done!!!\n");
}
//SoftReset Ready
else
{
printf("[SoftReset Test]\n");
#if CHECK_SDRAM_SELFREFRESH
Test_InitSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Write test data into NONCACHEABLE AREA
#endif
rRSTCNT=0xffff;
SRAMKey_Run = (int)__main;// Change if you want..
rGPJDAT&=~(1<<2);
rGPJCON=rGPJCON&~(3<<4)|(1<<4);//USB off
//SoftReset
printf("Now, Soft Reset causes reset on S3C2460 except SDRAM. \n");
while(!(rUTRSTAT0 & 0x4)); //Wait until tx shifter is empty, to avoid broken character.
rSWRSTCON=0x2460; //Software Reset
}
}
void Test_WDTReset(void)
{
//Return from WarmReset
if( ( rRSTSTAT & (1<<2) ) && !(onTest) )
{
printf("[Watch-dog Reset Test]\n");
#if CHECK_SDRAM_SELFREFRESH
Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Check NONCACHEABLE AREA
#endif
onTest=1;
printf("\n[Watch-dog Reset] Test is Done!!!\n");
}
//WDT Ready
else
{
printf("[Watch-dog Reset Test]\n");
#if CHECK_SDRAM_SELFREFRESH
Test_InitSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Write test data into NONCACHEABLE AREA
#endif
rRSTCNT=0xffff;
rWTCON = 0; // clear wtcon
rWTDAT = 8448 ; // WDT clock = 128/1M --> 128us*8448 = 1s
rWTCNT = 8448 ;
SRAMKey_Run = (int)__main;// Change if you want..
rGPJDAT&=~(1<<2);
rGPJCON=rGPJCON&~(3<<4)|(1<<4);//USB off
// WDT reset enable
printf("After 1 sec the WDT reset will be assered. ..\n");
while(!(rUTRSTAT0 & 0x4)); //Wait until tx shifter is empty, to avoid broken character.
rWTCON = ((PCLK/1000000-1)<<8) |( 1<<5) | (3<<3) | (1);
while(1);
}
}
void Test_BattFault(void)
{
//Return from BATT_FLT
if( ( rRSTSTAT & (1<<2) ) && !(onTest) )
{
printf("[nBATT_FAULT signal Test]\n");
#if CHECK_SDRAM_SELFREFRESH
Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Check NONCACHEABLE AREA
#endif
#if 0
//Unmask interrupt
rINTMSK=rINTMSK&~(BIT_EINT0_2);
//Unmask sub interrupt
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT0);
#endif
onTest=1;
printf("[nBATT_FAULT signal Test is done]\n");
}
//BAT_FLT Ready
else
{
printf("[nBATT_FAULT signal Test]\n");
#if CHECK_SDRAM_SELFREFRESH
Test_InitSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Write test data into NONCACHEABLE AREA
#endif
rRSTCNT=0xffff;
// For hidden test(PWRCFG[15]).. Tark??????????????
//Config EINT0
rGPJCON = (rGPJCON & ~(0x3)) | (1<<1);
rEINTCON0=0x2; //falling
SetAlarmWakeUp(5);
rPWRCFG |= (1<<15);
// For hidden test(PWRCFG[15]).. Tark??????????????
rGPJDAT&=~(1<<2);
rGPJCON=rGPJCON&~(3<<4)|(1<<4);//USB off
rPWRCFG |= 3; // E-sleep
SRAMKey_Run = (int)__main;// Change if you want..
printf("Make the BATFLT low, then push Warm Reset Botton on SMDK2460\n");
printf("And then release BATFLT(make high)\n");
while(1);
}
}
/*
void Test_SleepMode_Hard(void)
{
//Wake-up from SLEEP mode
if(rALIVECON & 1<<2)//Wake-up from SLEEP mode
{
MMU_EnableICache();
if(SRAMKey_Count<100000)
{
//printf("0x%x",SRAMKey_Count);
//Uart_TxEmpty(0);
SRAMKey_Count++;
ConfigSleepGPIO();
#if USE_RTC_ALARM
SetAlarmWakeUp(1);
#else
rGPCON_L=rGPCON_L&~(3<<18)|(2<<18); //GP9=EINT9
rEXTINTC1=rEXTINTC1&~(7<<24)|(2<<24); //EINT9=falling edge triggered
//rEXTINTC1=rEXTINTC1&~(7<<24)|(1<<24); //EINT9=high level
#endif
printf("%05d\n",SRAMKey_Count);
while(!(rUTRSTAT0 & 0x4)); //Wait until tx shifter is empty, to avoid broken character.
#if USE_WFI
rINTMSK=rINTMSK&~(BIT_EINT7_10);
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT9);
rPWRMAN &= ~(0xffff);
rPWRMAN |= ((1<<12)|(0xa3)); // WFI & SLEEP
MMU_WaitForInterrupt(); // After WFI, the S3C2460 enters sleep mode
#else
rPWRMAN = rPWRMAN & ~(1<<12);// not use WFI
rPWRMAN &= ~(0xffff);
rPWRMAN |= (0xa3); // SLEEP
#endif
}
else
{
//Restore the port configurations
Port_Init();
printf("SLEEP hard test is done\n");
run=(void (*)(void))main;
run();
}
}
//Entering into SLEEP mode
else
{
printf("Entering into SLEEP mode and wakeup hard test\n");
LcdEnvidOnOff(0); //Before entering SLEEP mode, LCD must be off
Delay(1);
//Write SLEEP information into BACKUP AREA
SRAMKey_Count=0x0; // This is count for sleep hard loop test
printf("S3C2460 will wake up by EINT9 connected with Function Generator.\n");
//printf("Or RTC alarm(every 1 sec).\n");
while(!(rUTRSTAT0 & 0x4)); //Wait until tx shifter is empty, to avoid broken character.
ConfigSleepGPIO();
#if USE_RTC_ALARM
SetAlarmWakeUp(1);
#else
//Wake-up(EINT9)
rGPCON_L=rGPCON_L&~(3<<18)|(2<<18); //GP9=EINT9
rEXTINTC1=rEXTINTC1&~(7<<24)|(2<<24); //EINT9=falling edge triggered
//rEXTINTC1=rEXTINTC1&~(7<<24)|(1<<24); //EINT9=high level
pISR_EINT7_10=(unsigned int)Eint9Int_Hard;
rEINTPEND=BIT_EINTPEND_EINT9;
ClearPending(BIT_EINT7_10);
#endif
SRAMKey_Run = (int)Test_SleepMode_Hard;//xxx;// Change if you want..
//SRAMKey_Run = 0x10000000;
//***Enter SLEEP mode
#if USE_WFI
rINTMSK=rINTMSK&~(BIT_EINT7_10);
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT9);
rPWRMAN &= ~(0xffff);
rPWRMAN |= ((1<<12)|(0xa3)); // WFI & SLEEP
MMU_WaitForInterrupt(); // After WFI, the S3C2460 enters sleep mode
#else
rPWRMAN = rPWRMAN & ~(1<<12);// not use WFI
rPWRMAN &= ~(0xffff);
rPWRMAN |= (0xa3); // SLEEP
#endif
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -