?? sleep.c
字號:
printf("Power On Reset\n\n");
rGSTATUS2=(1<<0);
SLEEP_COUNT=0;
return;
}
if(rGSTATUS2&(1<<1))
{
printf("Sleep Wake-DN\n\n");
rGSTATUS2=(1<<1);
printf("EINTPEND=0x%x\n",rEINTPEND);
printf("SRCPND=0x%x\n",rSRCPND);
// Added for wake-DN 100Hz.
SLEEP_COUNT = SLEEP_COUNT+1;
printf("SLEEP_COUNT=%d\n", SLEEP_COUNT);
if(SLEEP_COUNT>1000000)
{
printf("\n\nSleep count is %d... any key to continue\n\n", SLEEP_COUNT);
getc();
}
Test_SleepMode();// goto sleep mode again.
}
if(rGSTATUS2&(1<<2))
{
printf("Watchdog Reset\n\n");
rGSTATUS2=(1<<2);
return;
}
}
//=========================================================================
void Test_SleepMode(void)
{
int i, mode, error=0;
U32 portStatus[33+3];
printf("[Sleep Mode Test]: EINT0/EINT11/Alarm\n");
rGPGDN |= (1<<3);
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //GPF0=EINT0
rEXTINT0=rEXTINT0&~(7<<0)|(0x2<<0); //EINT0=falling edge triggered
rGPGDN |= (1<<3);
rGPGCON=rGPGCON & ~(3<<6)|(2<<6); //GPG3=EINT11
rEXTINT1=rEXTINT1&~(7<<12)|(2<<12); //EINT11=falling edge triggered
rGPGSLPCON = 0xffffffff;
printf("\nNow, I am entering Sleep mode.\n");
Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
pISR_EINT0 = (U32)Eint0Int;
pISR_EINT8_23 = (U32)Eint8_23Int;
pISR_RTC = (U32)AlarmInt;
rEINTPEND |= ((1<<3)|(1<<0)); // clear EINT11 pending bit in rEINTPEND
rSRCPND = BIT_EINT0 | BIT_RTC | BIT_EINT8_23;
rINTPND = BIT_EINT0 | BIT_RTC | BIT_EINT8_23;
rEINTMASK &= ~((1<<11)|(1<<0));
rINTMSK &=~(BIT_EINT0|BIT_RTC|BIT_EINT8_23);
// alarm wakeup
//SetAlarmWakeUp2();
ConfigSleepGPIO();
rADCCON|=(1<<2);
/* Pin Configuration in Sleep Mode */
rMISCCR|=(1<<12); //USB port0 = suspend
rMISCCR|=(1<<13); //USB port1 = suspend
Lcd_EnvidOnOff(0); //LCD must be off before entering Sleep mode.
// Entering the SLEEP mode
//*************************//
#if 1
rPWRCFG |= ((0xffff<<16)|(3<<6)); // EINT_WAKE_MASK
MMU_WaitForInterrupt();
#else
rPWRMODECON |= (0x2BED<<0); // Go To BED
//*************************//
#endif
}
int batt_flag=0;
//=========================================================================
static void __irq BattFaultInt(void)
{
rINTMSK |= (BIT_BAT_FLT); // mask.
ClearPending(BIT_BAT_FLT)
printf("BATT_FLT interrDNt occured\n");
batt_flag=1;
//Batt_Sleep();
}
//================================================================================
void Test_BattFaultInterrDNt(void)
{
int i;
printf("Battery fault interrDNt test.\n");
printf("Detect low-level.\n");
printf("0 : Reset system during nBATT_FLT=0.\n");
printf("4 : System will be wake-DN from sleep mode during nBATT_FLT=0.\n");
printf("6 : System will ignore Eint0 signal during nBATT_FLT=0.\n");
printf("7 : Disable Battery function.\n");
printf("Select battery function : ");
i = GetIntNum() & 0x7;
rMISCCR = (rMISCCR & ~(0x1f<<20)) | (i<<20);
// [22:20]
// if 0, System will be Reset during nBATT_FLT=0.
// if 4, System will be wake-DN from sleep mode during nBATT_FLT=0.
// if 6, System will ignore nBATT_FLT signal.
// if 7, Disable Battery function.
pISR_BAT_FLT = (U32)BattFaultInt;
rSRCPND = BIT_BAT_FLT;
rINTPND = BIT_BAT_FLT;
rINTMSK = rINTMSK & ~(BIT_BAT_FLT); // unmask.
while(batt_flag==0)
{
if(Uart_GetKey()){
break;
}
}
batt_flag=0;
//Batt_Sleep();
printf("exit.\n");
}
void Batt_Sleep(void)
{
int i;
U32 portStatus[33+3];
int error=0;
int mode;
printf("[Sleep Mode Test]\n");
printf("nBATT_FLT pin should be tested.\n");
printf("S3C2442 will wake DN by EINT0 .\n");
/////////////////////////////////////////// add for battery fault...
#if 1
printf("6 : System will ignore Eint0 signal during nBATT_FLT=0.\n");
printf("rMISCCR:%x\n", rMISCCR);
#endif
/////////////////////////////////////////// add for battery fault...end
//Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
#if 0
SelectEintType();
#else
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //PF0=EINT0
rEXTINT0=rEXTINT0&~(7<<0)|(2<<0); //EINT0=falling edge triggered
#endif
#if 1 //test whether or not the interrDNt pending bit retain the wake-DN source.
pISR_EINT0=(U32)Eint0Int;
pISR_EINT8_23=(U32)Eint8_23Int;
pISR_RTC=(U32)AlarmInt;
rINTMSK = ~(BIT_EINT0|BIT_EINT8_23|BIT_RTC);
for(i=0;i<100;i++);
rSRCPND = BIT_EINT0|BIT_EINT8_23|BIT_RTC;
rINTPND = BIT_EINT0|BIT_EINT8_23|BIT_RTC;
rEINTPEND=rEINTPEND;
rSRCPND=rSRCPND;
rINTPND=rINTPND;
#endif
rEINTMASK = rEINTMASK&~(1<<11); //SRCPND:EINT8_23 will be set by EINT11 after wake-DN.
rINTMSK = BIT_ALLMSK;
// NOTE: Any interrDNt can't be used in Sleep mode.
// because SDRAM is in self-refresh mode and ISR code will access SDRAM.
printf("Alarm wake-DN (y/n)? ");
if(getc()=='y')
{
printf("S3C2442 will wake DN by RTC alarm(10 sec) or EINT0 .\n");
SetAlarmWakeDN();
}
rRTCCON=0x0; // R/W disable, 1/32768, Normal(merge), No reset
rADCCON|=(1<<2);
rMISCCR|=(1<<12); //USB port0 = suspend
rMISCCR|=(1<<13); //USB port1 = suspend
//rMISCCR|=(1<<2); //Previous state at STOP(?) mode (???)
rMISCCR &= ~(1<<2); //Previous state at STOP(?) mode (???)
// rGSTATUS3=(U32)StartPointAfterSleepWakeDN; // memory control part in startDN code.
printf("set restart address:%x\n", rGSTATUS3);
rGSTATUS4=0xaaaaaaaa;
//Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
ConfigSleepGPIO();
ConfigMiscIO();
rMISCCR=rMISCCR|(3<<0);
Lcd_EnvidOnOff(0); //Before entering Sleep mode, LCD must be off
rMISCCR = (rMISCCR & ~(0x7<<20)) | (6<<20); // set 6.
//=================================================================
// VERY IMPORTANT NOTE
// To enter SLEEP/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.
rREFRESH;//To fill TLB for the special register used in EnterPWDN
rCLKCON;
//=================================================================
//EnterPWDN(0xffff8); //Sleep mode
}
/************************ Sleep Mode by 100hz test ************************/
//================================================================================
void Check_SleepWakeDN_100Hz(void)
{
}
//================================================================================
void Test_SleepMode_100Hz(void)
{
}
void Test_StopMode(void)
{
int i;
U32 portStatus[33+3]; // +3 is for 2412 GPJ port.
int error=0;
int mode;
printf("[STOP Mode Test]\n");
printf("S3C2413 will wake DN by EINT0 .\n");
Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
// Save the port configurations
for(i=0;i<36;i++) {
portStatus[i]=*( (volatile U32 *)0x56000000 + i); // 0x5600_0000:GPACON addr.
}
// ConfigSleepGPIO();
// ConfigMiscIO();
printf("S3C2413 will wake DN by EINT0 (Falling Edge Triggered).\n");
rGPGDN |= (1<<3);
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //GPF0=EINT0
rEXTINT0=rEXTINT0&~(7<<0)|(0x2<<0); //EINT0=falling edge triggered
printf("S3C2413 will wake DN by EINT11 (Falling Edge Triggered).\n");
rGPGDN |= (1<<3);
rGPGCON=rGPGCON & ~(3<<6)|(2<<6); //GPG3=EINT11
rEXTINT1=rEXTINT1&~(7<<12)|(4<<12); //EINT11=falling edge triggered
printf("\nNow, I am entering Stop mode.\n");
Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
pISR_EINT0 = (U32)Eint0Int;
pISR_EINT8_23 = (U32)Eint8_23Int;
pISR_RTC = (U32)AlarmInt;
pISR_TICK = (U32)Tick_WakeDN;
rEINTPEND |= ((1<<3)|(1<<0)); // clear EINT11 pending bit in rEINTPEND
rSRCPND = BIT_EINT0 | BIT_RTC | BIT_EINT8_23|BIT_TICK;
rINTPND = BIT_EINT0 | BIT_RTC | BIT_EINT8_23|BIT_TICK;
rEINTMASK &= ~((1<<11)|(1<<0));
rINTMSK &=~(BIT_EINT0|BIT_RTC|BIT_EINT8_23|BIT_TICK);
rADCCON|=(1<<2); // ADC stanby.
rMISCCR|=(1<<12); //USB port0 = suspend
rMISCCR|=(1<<13); //USB port1 = suspend
Lcd_EnvidOnOff(0); //Before entering Sleep mode, LCD must be off
Delay(1);
Led_Display(0x5);
printf("locktime = %08x\n",rLOCKTIME);
printf("OSCSET = %08x\n",rOSCSET);
Uart_TxEmpty(1);
//SetAlarmWakeUp2();
//rRTCCON = 0x0; // R/W disable, but interrupt will be generated.
//rTICNT0 = (1<<7); //Tick time interrupt enable, Tick time count value 127
Tick_Count_Set_power(127); // 1> value
// Entering the STOP mode
//*************************//
#if 1
rPWRCFG |= (2<<6);
MMU_WaitForInterrupt();
#else
rPWRMODECON |= (1<<16);
//*************************//
__asm
{
nop;
nop;
nop;
nop;
nop;
nop;
nop;
nop;
nop;
nop;
nop;
nop;
}
// Wake-Up from STOP mode
rPWRMODECON &= ~(1<<16);
#endif
//Restore the port configurations
for(i=0;i<36;i++){
*( (volatile U32 *)0x56000000 + i)=portStatus[i];
}
Led_Display(0xa);
Lcd_EnvidOnOff(1);
rINTMSK |=(BIT_EINT0|BIT_RTC|BIT_EINT8_23|BIT_TICK);
rINTMSK =BIT_ALLMSK;
printf("Return to Normal Mode.\n");
}
void Test_SoftMode(void)
{
printf("Software reset Test \n",rRSTSTAT);
//Check wake-up reset
if( rRSTSTAT & (1<<0) ) // nRESET?
{
printf("\n__ Wake-up by nRESET\n");
rRSTSTAT |= (1<<0);
}
else if( rRSTSTAT & (1<<2) ) // WDTRST?
{
printf("\n__ Wake-up by WDTRST\n");
rRSTSTAT |= (1<<2);
}
else if( rRSTSTAT & (1<<3) ) // SLEEP?
{
printf("\n__ Wake-up by SLEEP\n");
rRSTSTAT |= (1<<3);
}
else if( rRSTSTAT & (1<<4) ) // ESLEEP?
{
printf("\n__ Wake-up by ESLEEP\n");
rRSTSTAT |= (1<<4);
}
else if( rRSTSTAT & (1<<5) ) // SWRST?
{
printf("\n__ Wake-up by SWRST\n");
rRSTSTAT |= (1<<5);
}
rSWRSTCON = 0x533c2412;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -