📄 sleep.c
字号:
/*****************************************
NAME: STOP.C
DESC: STOP & SLEEP mode test code
HISTORY:
2003.04.21 : ver 0.0
******************************************/
#include "def.h"
#include "option.h"
#include "24a0addr.h"
#include "24a0lib.h"
#include "24a0slib.h"
#include "lcdlib.h"
#include "stop.h"
#include "idle.h"
#include "sleep.h"
static void __irq EintInt(void)//EINT0,1
{
rEINTMASK |= ( (BIT_EINTPEND_EINT1)|(BIT_EINTPEND_EINT0) );
rINTMSK |= (BIT_EINT0_2);
if(rEINTPEND&(1<<0))
{
rEINTPEND=BIT_EINTPEND_EINT0;
Uart_Printf("__isr EINT0 for SLEEP wake-up.\n\n");
}
else if(rEINTPEND&(1<<1))
{
rEINTPEND=BIT_EINTPEND_EINT1;
Uart_Printf("__isr EINT1 for SLEEP wake-up.\n\n");
}
else
Uart_Printf("__isr EINT Error!!\n\n");
ClearPending(BIT_EINT0_2);
}
static void __irq Eint9Int(void)
{
rEINTMASK |=(BIT_EINTPEND_EINT9);
rINTMSK |= (BIT_EINT7_10);
rEINTPEND=BIT_EINTPEND_EINT9;
ClearPending(BIT_EINT7_10);
Uart_Printf("__isr EINT9 for SLEEP wake-up.\n\n");
}
static void __irq Eint11Int(void)
{
//This routine is not serveced....
rEINTMASK |= (BIT_EINTPEND_EINT11);
rINTMSK |= (BIT_EINT11_14);
ClearPending(BIT_EINT11_14);
rEINTPEND=BIT_EINTPEND_EINT11;
Uart_Printf("It seems strange that the EINT11 wake the S3C24A0 up.\n");
}
static void __irq AlarmInt(void)
{
//This routine is not serveced....
rINTMSK=rINTMSK|(BIT_RTC);
ClearPending(BIT_RTC);
Uart_Printf("It seems strange that the Alarm wake the S3C24A0 up.\n");
}
static void __irq Eint9Int_Hard(void)
{
/*EINT 9(Function Generator)*/
//This test needs External Function Generator to generate INT request
rEINTMASK=rEINTMASK|(BIT_EINTPEND_EINT9);
rINTMSK=rINTMSK|(BIT_EINT7_10);
rEINTPEND=BIT_EINTPEND_EINT9;
ClearPending(BIT_EINT7_10);
Uart_Printf(".");
rINTMSK=rINTMSK&~(BIT_EINT7_10);
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT9);
}
#define CHECK_SDRAM_SELFREFRESH (TRUE)
//#define XTAL_ENABLE_SLEEPMODE (FALSE)
#define CHOOSE_EINT0_TYPE (FALSE)
#define USE_RTC_ALARM (FALSE)
void Set_SleepKey()
{
Uart_Printf("Write sleep-key into internal alive-SRAM. \n");
rALIVECON |= 1<<3;
//SRAMKey_Sleep0 = 0xaaaa5555; //Sleep key0
//SRAMKey_Sleep1 = 0x5555aaaa; //Sleep key1
SRAMKey_Count = 0x0; //Repeat test counter
//SRAMKey_Run = //Restart pointer
}
void Clear_SleepKey(void)
{
int i;
int error=0;
Uart_Printf("Erase sleep-keys in the internal SRAM.\n");
//SRAMKey_Sleep0 = 0;
//SRAMKey_Sleep1 = 0;
SRAMKey_Count = 0;
SRAMKey_Run = 0;
rALIVECON &= 0x1;
}
void ConfigSleepGPIO(void)
{
// Check point
// 1) NC pin: input pull-up on
// 2) If input is drived externally: input pull-up off
// 3) If a connected component draws some current: output low.
// 4) If a connected component draws no current: output high.
// 5) UART Tx: Output(H) and enable pull-up
// UART Rx: Input and disable pull-up
//CAUTION:Follow the configuration order for setting the ports.
// 1) setting value(GPnDAT)
// 2) setting control register(GPnCON)
// 3) configure pull-up resistor(GPnUP)
//rRSTCNT= 35; // 83.3*2048*RSTCNT Value = 6ms
//rALIVECON=1; // 32768HZ
//rRSTCNT = 1; // 83.3*2048*1 = 62.5ms
//Initialize rEXTINTC0,rEXTINTC1,rEXTINTC2
rEINTMASK=0xfffff;
rEXTINTC0=0x0;
rEXTINTC1=0x100;
rEXTINTC2=0x0;
//GPIO configuration in Sleep mode(These value should be modified suitably for your system)
//GP5 has some problem so....
//Ports :GP31 GP30 GP29 GP28 GP27 GP26 GP25 GP24 GP23 GP22 GP21 GP20 GP19 GP18 GP17 GP16
//GPDAT :0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
//GPOEN :i O O i i i i i i i i i i i i i
//GPPU :x o o x x x x x x x x x x x o o
//-------------------------------------------------------------------------------------------
//Ports :GP15 GP14 GP13 GP12 GP11 GP10 GP09 GP08 GP07 GP06 GP05 GP04 GP03 GP02 GP01 GP00
//GPDAT :0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
//GPOEN :i i i i i i i i i i i i i i i i
//GPPU :o x o x x o x o x x x x o o x x
rGPDAT_SLEEP = (1<<30)|(1<<29);
rGPOEN_SLEEP = ~( (1<<30)|(1<<29) );
rGPPU_SLEEP =0x9ffc5af3;
Uart_Printf("\n\n@@@ rGPDAT_SLEEP=0x%x\n",rGPDAT_SLEEP);
Uart_Printf("@@@ rGPOEN_SLEEP=0x%x\n",rGPOEN_SLEEP);
Uart_Printf("@@@ rGPPU_SLEEP=0x%x\n\n",rGPPU_SLEEP);
//Set output value during SLEEP mode
rPERIDAT_SLEEP0=0x80913202; //1000, 0000, 1001, 0001 \ 0011, 0010, 0000, 0010
rPERIDAT_SLEEP1=0x28; // 0100, 1000
//Enable the output during SLEEP mode
rPERIOEN_SLEEP0=0x1f73c3; // 0001, 1111 \ 0111, 0011, 1100, 0011
rPERIOEN_SLEEP1=0x300000; // 0011, 0000 \ 0000, 0000, 0000, 0000
//Configure pull-up during SLEEP mode
rPERIPU_SLEEP=0x5000f00; // 0101, 0000, 0000 \ 0000, 1111, 0000, 0000
rALIVECON |= (1<<0);//Alive block uses RTC clk
rRSTCNT= 0x10; //about 1sec
//rPERIOEN_SLEEP0 &= ( ~(1<<8) & ~(1<<6) );
Uart_Printf("\n @@@PERIOEN_SLEEP0=0x%x @@@\n\n", rPERIOEN_SLEEP0);
/*
//Set output value during SLEEP mode
rDATRinSLEEP0=0x80912222;//1000, 0000, 1001, 0001 \ 0010, 0010, 0010, 0010
rDATRinSLEEP1=0x00040010;//0000, 0000, 0000, 0100 \ 0000, 0000, 0001, 0000
//Configure pull-up during SLEEP mode
rENPUinSLEEP =0x050f0600;//0000, 0101, 0000, 1111 \ 0000, 0110, 0000, 0000
#if XTAL_ENABLE_SLEEPMODE//Xtal is enabled during SLEEP mode
//Set power settle down time
rALIVECON=0; // 12MHZ, 83.3ns
//rRSTCNT= 0x1; // 83.3*2048*RSTCNT Value = 6ms
rRSTCNT= 0x50;
rOENinSLEEP0=(1<<21)|(1<<20)| //XmiDATA[7:0] | XeaHREADY
(1<<19)|(1<<18)|(1<<17)|(1<<16)| //XeaHDATA[31:0] | XeaHADDR[31:0] | XeaHWRITE,SIZE[2:0] | XeaHTRANS[1:0],BURST[2:0]
(0<<15)|(1<<14)|(1<<13)|(1<<12)| //XjTDO | XsXTOUT | XsdDAT[3:0] | XmsSDIO
(0<<11)|(0<<10)|(1<< 9)|(0<< 8)| //XvSD | XvVD[23:0] | UdSUSPND | UdOEN
(1<< 7)|(0<< 6)|(0<< 5)|(0<< 4)| //usSUSPND | usOEN[1:0] | XspiCLK,MISO,MOSI | X2sLRCK,CLK
(0<< 3)|(1<< 2)|(1<< 1)|(1<< 0); //Reserved | XdDATA[31:0] | XpDATA[31:0] | XrDATA[31:0]
#else
//Set power settle down time
rALIVECON=1; // 32.768KHZ,
rRSTCNT= 0x10; //about 1sec
//rRSTCNT= 0xff; //Boaz
//rRSTCNT= 0x0; //Boaz
//rRSTCNT= 0x80; //Boaz
rOENinSLEEP0=(1<<21)|(1<<20)| //XmiDATA[7:0] | XeaHREADY
(1<<19)|(1<<18)|(1<<17)|(1<<16)| //XeaHDATA[31:0] | XeaHADDR[31:0] | XeaHWRITE,SIZE[2:0] | XeaHTRANS[1:0],BURST[2:0]
(0<<15)|(0<<14)|(1<<13)|(1<<12)| //XjTDO | XsXTOUT | XsdDAT[3:0] | XmsSDIO
(0<<11)|(0<<10)|(1<< 9)|(0<< 8)| //XvSD | XvVD[23:0] | UdSUSPND | UdOEN
(1<< 7)|(0<< 6)|(0<< 5)|(0<< 4)| //usSUSPND | usOEN[1:0] | XspiCLK,MISO,MOSI | X2sLRCK,CLK
(0<< 3)|(1<< 2)|(1<< 1)|(1<< 0); //Reserved | XdDATA[31:0] | XpDATA[31:0] | XrDATA[31:0]
#endif
*/
}
void Test_SleepMode(void)
{
int i;
if(rALIVECON & 1<<3)//Wake-up from SLEEP mode
{
#if CHECK_SDRAM_SELFREFRESH
Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Check NONCACHEABLE AREA
#endif
Uart_Printf("AC97Codec is going to Normal mode, now.\n");
AC97_Init();
AC97_Codec_Init(22050);
Clear_SleepKey();
Uart_Printf("Wake-up from SLEEP mode\n");
//Uart_Printf("Check whether or not the interrupt pending bit retain the wake-up source.\n");
#if 1
//Unmask interrupt
if(rEINTPEND&(1<<19))// The RTC does not request INT, only wake the CPU up from sleep mode.
Uart_Printf("\nALARM for SLEEP mode wake-up.\n\n");
//rINTMSK=rINTMSK&~(BIT_EINT7_10);
rINTMSK=rINTMSK&~(BIT_EINT0_2);
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT0);
/*
//Unmask sub interrupt
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT0);
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT1);
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT10);
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT11);
//for(i=0;i<100;i++);
*/
#endif
Port_Init();
Uart_Printf("SLEEP mode test is done\n");
}
else//Entering into SLEEP mode
{
Uart_Printf("[SLEEP Mode Test]\n");
Uart_Printf("nBATT_FLT pin should be tested.\n");
LcdEnvidOnOff(0); //Before entering SLEEP mode, LCD must be off
Delay(1);
Uart_Printf("Entering into SLEEP mode\n");
Uart_Printf("S3C24A0 will wake up by EINT0/1/9 or RTC alarm.\n");
//Write SLEEP information into BACKUP AREA
Set_SleepKey();
//Test_InitSDRAM((_BACKUPFORSLEEP_STARTADDRESS+0x50), 0x100000); //Write test data into BACKUP AREA
#if CHECK_SDRAM_SELFREFRESH
Test_InitSDRAM(_NONCACHE_STARTADDRESS,0x400000); //Write test data into NONCACHEABLE AREA
#endif
ConfigSleepGPIO();
//Wake-up(EINT0)
#if CHOOSE_EINT0_TYPE
SelectEintType();
#else
rGPCON_L= ( rGPCON_L & ~(3<<0) ) | (2<<0); //GP0=EINT0
rEXTINTC0=rEXTINTC0&~(7<<0)|(2<<0); //EINT0=falling edge triggered
#endif
//Wake-up(EINT1)
rGPCON_L=rGPCON_L&~(3<<2)|(2<<2); //GP1=EINT1
rEXTINTC0=rEXTINTC0&~(7<<4)|(2<<4); //EINT0=falling edge triggered
//Wake-up(EINT9)
rGPCON_L=rGPCON_L&~(3<<20)|(2<<18); //GP9=EINT9
rEXTINTC1=rEXTINTC1&~(7<<28)|(2<<24); //EINT9=falling edge triggered
//To test.... EINT11 can not wake-up the S3C24A0 from Sleep mode
rGPCON_M=rGPCON_M&~(3<<0)|(2<<0); //GP11=EINT11
rEXTINTC2=rEXTINTC2&~(7<<0)|(2<<0); //EINT11=falling edge triggered
rEXTINTC0=0x222;
rEXTINTC1=0x2222222;
rEXTINTC2=0x22222222;
//Interrupt service routine
pISR_EINT0_2=(U32)EintInt;
pISR_RTC=(U32)AlarmInt;
pISR_EINT7_10=(U32)Eint9Int;
pISR_EINT11_14=(U32)Eint11Int;
//Clear sub interrupt pending
rEINTPEND=BIT_EINTPEND_EINT11;
rEINTPEND=BIT_EINTPEND_EINT9;
rEINTPEND=BIT_EINTPEND_EINT1;
rEINTPEND=BIT_EINTPEND_EINT0;
rEINTPEND=BIT_EINTPEND_PWMKUP;
rEINTPEND=BIT_EINTPEND_ALLMSK;
//Clear interrupt pending
ClearPending(BIT_EINT11_14);
ClearPending(BIT_EINT7_10);
ClearPending(BIT_EINT0_2);
ClearPending(BIT_RTC);
#if 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -