📄 sleep.c.bak
字号:
#if 1
Uart_Printf("\nBattery fault interrupt setting.\n");
Uart_Printf("Detect low-level.\n");
Uart_Printf("0 : Reset system during nBATT_FLT=0.\n");
Uart_Printf("4 : System will be wake-up from sleep mode during nBATT_FLT=0.\n");
Uart_Printf("6 : System will ignore Eint0 signal during nBATT_FLT=0.\n");
Uart_Printf("7 : Disable Battery function.\n");
Uart_Printf("Select battery function : ");
i = Uart_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-up from sleep mode during nBATT_FLT=0.
// if 6, System will ignore nBATT_FLT signal.
// if 7, Disable Battery function.
Uart_Printf("rMISCCR:%x\n", rMISCCR);
pISR_BAT_FLT = (U32)BattFaultInt;
rSRCPND = BIT_BAT_FLT;
rINTPND = BIT_BAT_FLT;
rINTMSK = rINTMSK & ~(BIT_BAT_FLT); // unmask.
#endif
/////////////////////////////////////////// add for battery fault...end
#if 0
Uart_Printf("Check SDRAM for self-refresh test\n");
for(i=_NONCACHE_STARTADDRESS;i<(_NONCACHE_STARTADDRESS+0x400000);i+=4)
{
//Uart_Printf("%x=%x(%x)\n",i,*((U32 *)i),i^0x55555555);
if(*((U32 *)i)!=(i^0x55555555))
{
Uart_Printf("Mem Error:%x=%x(%x)\n",i,*((U32 *)i),i^0x55555555);
error++;
}
if(error>20)
break;
}
if(error)
Uart_Printf("SDRAM self-refresh test:FAILED\n");
else
Uart_Printf("SDRAM self-refresh test:O.K.\n");
#endif
Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
#if 1
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 interrupt pending bit retain the wake-up 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-up.
rINTMSK = BIT_ALLMSK;
// NOTE: Any interrupt can't be used in Sleep mode.
// because SDRAM is in self-refresh mode and ISR code will access SDRAM.
Uart_Printf("Alarm wake-up (y/n)? ");
if(Uart_Getch()=='y')
{
Uart_Printf("S3C2440 will wake up by RTC alarm(10 sec) or EINT0 .\n");
SetAlarmWakeUp();
}
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
rGSTATUS3=(U32)StartPointAfterSleepWakeUp; // memory control part in startup code.
Uart_Printf("set restart address:%x\n", rGSTATUS3);
rGSTATUS4=0xaaaaaaaa;
Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
ConfigSleepGPIO();
ConfigMiscIO();
//Max1718_Set(110);
rMISCCR=rMISCCR|(3<<0); // Data[31:0] pull-up disable.
Lcd_EnvidOnOff(0); //Before entering Sleep mode, LCD must be off
//=================================================================
// 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
//Never return here.
}
int batt_flag=0;
//================================================================================
static void __irq BattFaultInt(void)
{
rINTMSK |= (BIT_BAT_FLT); // mask.
ClearPending(BIT_BAT_FLT)
Uart_Printf("BATT_FLT interrupt occured\n");
batt_flag=1;
//Batt_Sleep();
}
//================================================================================
void Test_BattFaultInterrupt(void)
{
int i;
Uart_Printf("Battery fault interrupt test.\n");
Uart_Printf("Detect low-level.\n");
Uart_Printf("0 : Reset system during nBATT_FLT=0.\n");
Uart_Printf("4 : System will be wake-up from sleep mode during nBATT_FLT=0.\n");
Uart_Printf("6 : System will ignore Eint0 signal during nBATT_FLT=0.\n");
Uart_Printf("7 : Disable Battery function.\n");
Uart_Printf("Select battery function : ");
i = Uart_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-up 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();
Uart_Printf("exit.\n");
}
void Batt_Sleep(void)
{
int i;
U32 portStatus[33+3];
int error=0;
int mode;
Uart_Printf("[Sleep Mode Test]\n");
Uart_Printf("nBATT_FLT pin should be tested.\n");
Uart_Printf("S3C2440 will wake up by EINT0 .\n");
/////////////////////////////////////////// add for battery fault...
#if 1
Uart_Printf("6 : System will ignore Eint0 signal during nBATT_FLT=0.\n");
Uart_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 interrupt pending bit retain the wake-up 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-up.
rINTMSK = BIT_ALLMSK;
// NOTE: Any interrupt can't be used in Sleep mode.
// because SDRAM is in self-refresh mode and ISR code will access SDRAM.
Uart_Printf("Alarm wake-up (y/n)? ");
if(Uart_Getch()=='y')
{
Uart_Printf("S3C2440 will wake up by RTC alarm(10 sec) or EINT0 .\n");
SetAlarmWakeUp();
}
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
rGSTATUS3=(U32)StartPointAfterSleepWakeUp; // memory control part in startup code.
Uart_Printf("set restart address:%x\n", rGSTATUS3);
rGSTATUS4=0xaaaaaaaa;
Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
ConfigSleepGPIO();
ConfigMiscIO();
rMISCCR=rMISCCR|(3<<0); // Data line pull-up disable.
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_SleepWakeUp_100Hz(void)
{
}
//================================================================================
void Test_SleepMode_100Hz(void)
{
}
void Test_StopMode(void)
{
int i;
U32 portStatus[33+3]; // +3 is for 2440 GPJ port.
int error=0;
int mode;
Uart_Printf("[STOP Mode Test]\n");
Uart_Printf("S3C2440 will wake up by EINT0 .\n");
Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
rMISCCR = (rMISCCR & ~(7<<8) & ~(7<<4)) | (3<<8) | (2<<4); // CLKSEL0=FCLK, CLKSEL1=HCLK
// Save the port configurations
for(i=0;i<33;i++) {
portStatus[i]=*( (volatile U32 *)0x56000000 + i); // 0x5600_0000:GPACON addr.
}
for(i=0;i<3;i++)
portStatus[i+33]=*( (volatile U32 *)0x560000d0 + i); // 0x5600_00d0:GPJCON addr. added ffor 2440
ConfigSleepGPIO();
ConfigMiscIO();
//Uart_Printf("S3C2440 will wake up by EINT0 (Falling Edge Triggered).\n");
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //GPF0=EINT0
rEXTINT0=rEXTINT0&~(7<<0)|(0x2<<0); //EINT0=falling edge triggered
//Uart_Printf("S3C2440 will wake up by EINT11 (Falling Edge Triggered).\n");
rGPGCON=rGPGCON & ~(3<<6)|(2<<6); //GPG3=EINT11
rEXTINT1=rEXTINT1&~(7<<12)|(2<<12); //EINT11=falling edge triggered
//Uart_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;
rEINTPEND = (1<<11); // clear EINT11 pending bit in rEINTPEND
rSRCPND = BIT_EINT0 | BIT_RTC | BIT_EINT8_23;
rINTPND = BIT_EINT0 | BIT_RTC | BIT_EINT8_23;
rINTMSK = BIT_ALLMSK;
//rINTMSK = ~BIT_EINT0;
// NOTE: Any interrupt can't be used in Sleep mode
// because SDRAM is in self-refresh mode and ISR code will access SDRAM.
rRTCCON=0x0; // R/W disable, 1/32768, Normal(merge), No reset
rADCCON|=(1<<2); // ADC stanby.
rMISCCR|=(1<<12); //USB port0 = suspend
rMISCCR|=(1<<13); //USB port1 = suspend
//rMISCCR|=(1<<2); //Previous state at Sleep mode.
rMISCCR &= ~(1<<2); //Previous state at STOP(?) mode (???)
//For SDRAM self-refresh mode, rMISCCR[2] should be 1.
rMISCCR=rMISCCR|(3<<0);
Lcd_EnvidOnOff(0); //Before entering Sleep mode, LCD must be off
Delay(1);
Led_Display(0x5);
//rCLKSLOW=0x34; //csh (???)debug
//=================================================================
// 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.
rREFRESH; //To fill TLB for the special register used in EnterPWDN
rCLKCON;
rMISCCR;
rGPFDAT;
//=================================================================
rGPGDAT=rGPGDAT&~(1<<11)|(0<<11); //GPG11(EINT19)=L
EnterPWDN(0xffff1); //Sleep mode added for 2440 bit[19] camera.
rCLKCON=0xffff0; //Clear STOP_BIT & IDLE_BIT just after exiting Sleep mode.
//rCLKSLOW=0x4; //csh (???) debug
Uart_Printf("wake-up\n");
// Restore I/O drive strength
rDSC0 = (1<<31)|(0<<8)|(0<<0);
rDSC1 = (0<<28)|(0<<26)|(0<24)|(0<<22)|(0<<20)|(0<<18);
//Restore the port configurations
for(i=0;i<33;i++){
*( (volatile U32 *)0x56000000 + i)=portStatus[i];
}
for(i=0;i<3;i++) // GPJ port
*( (volatile U32 *)0x560000d0 + i)=portStatus[i+33];
Led_Display(0xa);
Lcd_EnvidOnOff(1);
Uart_Printf("SRCPND=%x,INTPND=%x\n",rSRCPND,rINTPND);
rINTMSK =~(BIT_EINT0|BIT_RTC|BIT_EINT8_23);
for(i=0;i<10;i++);
//The Wake-up source is indicated by rSRCPND.
//The corresponding interrupt wiil be occurred here.
rINTMSK =BIT_ALLMSK;
Uart_Printf("Return to Normal Mode.\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -