📄 sleep.c
字号:
{
// memory data/control signal pin status definition when sleep.
mslcon_bak = rMISCCR;
// In the evaluation board, Even though in sleep mode, the devices are all sDNplied the power.
//rMSLCON = (0<<11)|(0<<10)|(0<<9)|(0<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0);
rMISCCR = (1<<13)|(1<<12);
}
//================================================================================
//=========================================================================
void Test_SleepMode(void)
{
printf("[SLEEP Mode Test]\n");
#ifdef __EVT1
#else
// Save the port configurations
for(i=0;i<32;i++) {
portStatus1[i]=*( (volatile U32 *)0x56000000 + i); // 0x5600_0000:GPACON addr.
}
for(i=0;i<16;i++) {
portStatus2[i]=*( (volatile U32 *)0x560000d0 + i); // 0x5600_00d0:GPJCON addr.
}
#endif
printf("S3C2443 will wake up by EINT0 & EINT11 (Falling Edge Triggered).\n");
#ifdef __EVT1
rEXTINT0 = rdEXTINT0 & (~(1<<3));
rEXTINT0 = (rdEXTINT0 | (1<<3)); //
#else
rGPFUDP &= ~(1<<1); // Pull up down disable
#endif
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //GPF0=EINT0
#ifdef __EVT1
rEXTINT0=rdEXTINT0&~(0x7<<0)|(0x2<<0); //EINT0=falling edge triggered
#else
rEXTINT0=rEXTINT0&~(0x7<<0)|(0x2<<0); //EINT0=falling edge triggered
#endif
rGPGUDP &=~ (1<<7);
rGPGCON=rGPGCON & ~(3<<6)|(2<<6); //GPG3=EINT11
#ifdef __EVT1
rEXTINT1=rdEXTINT1&~(7<<12)|(2<<12); //EINT11=falling edge triggered
rEXTINT1= rdEXTINT1 | (1<<15);
#else
rEXTINT1=rEXTINT1&~(7<<12)|(2<<12); //EINT11=falling edge triggered
#endif
printf("\nNow, I am entering Sleep mode.\n");
Uart_TxEmpty(); //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 | BIT_TICK;
rINTPND = BIT_EINT0 | BIT_RTC | BIT_EINT8_23 | BIT_TICK;
rEINTMASK &= ~(1<<11);
// rINTMSK &=~(BIT_EINT0|BIT_RTC|BIT_EINT8_23);
#if 0
printf("Alarm wake-up (y/n)? ");
if(getchar()=='y')
{
printf("\nS3C2443 will wake up by RTC alarm(10 sec) \n");
SetAlarmWakeUp2();
}
printf("RTC tick interrupt (y/n)? ");
if(getchar()=='y')
{
printf("\nS3C2443 will wake up by RTC tick(4 sec) \n");
RTC_TimeTickSet(); // wake up will be occurred after 4sec!!!
}
#endif
// SetAlarmWakeUp2();
rINFORM1+=1;
/* rINFORM2=0x77777777;
rINFORM3=0x99999999;
rGSTATUS3 = 0x55555555;
rGSTATUS4 = 0xaaaaaaaa;
*/
#if 0 // sdram test
a=0x30000000;
for(i=0x31000000;i<(0x31000000+0x3f0000);i+=4)
{
*((unsigned int *)i)=*((unsigned int *)a);
//*((unsigned int *)i)=0xaaaa5555;
a+=4;
}
a=0x30000000;
for(i=0x31000000;i<(0x31000000+0x3f0000);i+=4)
{
//if(*((unsigned int *)i)!=(0xaaaa5555))
if(*((unsigned int *)i)!=*((unsigned int *)a))
{
printf("Mem Error:%x=%x(%x)\n",i,*((unsigned int *)i),i^0x5555aaaa);
error++;
}
if(error>20)
break;
a+=4;
}
if(error)
printf("SDRAM self-refresh test:FAILED\n");
else
printf("SDRAM self-refresh test:O.K.\n");
printf("write done\n");
Uart_TxEmpty();
#endif
ConfigSleepGPIO();
#ifdef __EVT1
printf("GPFCON=%08x, GPFDAT=%08x \n",rGPFCON, rGPFDAT);
#else
printf("GPFCON=%08x, GPFUDP=%08x, , GPFDAT=%08x \n",rGPFCON, rGPFUDP, rGPFDAT);
#endif
printf("VIDCON0=%08x, LCDCON1=%08x \n",rVIDCON0, rLCDCON1);
rADCCON|=(1<<2);
/* Pin Configuration in Sleep Mode */
rMISCCR|=(1<<12); //USB port0 = suspend
// Lcd_EnvidOnOff(0); // jcs 060610 //LCD must be off before entering Sleep mode.
// set flag sleep wakeup : rINFORM0 = 0x2BED
rINFORM0 = 0x2BED;
// Delay(20000);
// Entering the SLEEP mode
//*************************//
rRSTCON=0x1ff80;
rOSCSET=0x1000;
rPWRCFG=(1<<15)|(1<<9)|(0<<8)|(0<<7)|(0<<4)|(0<<3)|(0<<2)|(1<<0);
printf("rOSCSET: %x\n", rOSCSET);
printf("rRSTCON: %x\n", rRSTCON);
printf("rPWRCFG: %x\n", rPWRCFG);
printf("Sleep count: %x\n", rINFORM1);
#ifdef __EVT1
#else
printf("gstatus3=%08x, gstatus4=%08x \n",rGSTATUS3,rGSTATUS4);
#endif
rPWRMODE=rPWRMODE&~(0xffff<<0)| (0x2BED<<0); // Go To BED
//*************************//
}
#if 0
void Test_SleepMode(void)
{
int i,a,b;
U32 portStatus1[32]; // A ~ H, 8*4=32
U32 portStatus2[16]; // J ~ M, 4*4=16
int error=0;
int mode;
printf("[SLEEP Mode Test]\n");
#ifdef __EVT1
#else
// Save the port configurations
for(i=0;i<32;i++) {
portStatus1[i]=*( (volatile U32 *)0x56000000 + i); // 0x5600_0000:GPACON addr.
}
for(i=0;i<16;i++) {
portStatus2[i]=*( (volatile U32 *)0x560000d0 + i); // 0x5600_00d0:GPJCON addr.
}
#endif
printf("S3C2443 will wake up by EINT0 (Falling Edge Triggered).\n");
#ifdef __EVT1
rEXTINT0 = 0x88888888; //reset value as 0x88888888 to disable pull-down --> EINT0 : pull-up/down disable
#else
rGPFUDP &= ~(1<<1); // Pull up down disable
#endif
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //GPF0=EINT0
#ifdef __EVT1
rEXTINT0 = (0x88888888 | (2<<0)); //reset value as 0x88888888 to disable pull-down, falling edge triggered rEXTINT0
#else
rEXTINT0=rEXTINT0&~(0x7<<0)|(0x2<<0); //EINT0=falling edge triggered
#endif
printf("S3C2443 will wake DN by EINT11 (Falling Edge Triggered).\n");
#ifdef __EVT1
#else
rGPGUDP =~ (1<<7);
#endif
rGPGCON=rGPGCON & ~(3<<6)|(2<<6); //GPG3=EINT11
#ifdef __EVT1
rEXTINT1=(2<<12); //EINT11=falling edge triggered
#else
rEXTINT1=rEXTINT1&~(7<<12)|(2<<12); //EINT11=falling edge triggered
#endif
printf("\nNow, I am entering Sleep mode.\n");
Uart_TxEmpty(); //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 | BIT_TICK;
rINTPND = BIT_EINT0 | BIT_RTC | BIT_EINT8_23 | BIT_TICK;
rEINTMASK &= ~(1<<11);
// rINTMSK &=~(BIT_EINT0|BIT_RTC|BIT_EINT8_23);
#if 0
printf("Alarm wake-up (y/n)? ");
if(getchar()=='y')
{
printf("\nS3C2443 will wake up by RTC alarm(10 sec) \n");
SetAlarmWakeUp2();
}
printf("RTC tick interrupt (y/n)? ");
if(getchar()=='y')
{
printf("\nS3C2443 will wake up by RTC tick(4 sec) \n");
RTC_TimeTickSet(); // wake up will be occurred after 4sec!!!
}
#endif
// SetAlarmWakeUp2();
rINFORM1+=1;
/* rINFORM2=0x77777777;
rINFORM3=0x99999999;
rGSTATUS3 = 0x55555555;
rGSTATUS4 = 0xaaaaaaaa;
*/
#if 0 // sdram test
a=0x30000000;
for(i=0x31000000;i<(0x31000000+0x3f0000);i+=4)
{
*((unsigned int *)i)=*((unsigned int *)a);
//*((unsigned int *)i)=0xaaaa5555;
a+=4;
}
a=0x30000000;
for(i=0x31000000;i<(0x31000000+0x3f0000);i+=4)
{
//if(*((unsigned int *)i)!=(0xaaaa5555))
if(*((unsigned int *)i)!=*((unsigned int *)a))
{
printf("Mem Error:%x=%x(%x)\n",i,*((unsigned int *)i),i^0x5555aaaa);
error++;
}
if(error>20)
break;
a+=4;
}
if(error)
printf("SDRAM self-refresh test:FAILED\n");
else
printf("SDRAM self-refresh test:O.K.\n");
printf("write done\n");
Uart_TxEmpty();
#endif
ConfigSleepGPIO();
#ifdef __EVT1
printf("GPFCON=%08x, GPFDAT=%08x \n",rGPFCON, rGPFDAT);
#else
printf("GPFCON=%08x, GPFUDP=%08x, , GPFDAT=%08x \n",rGPFCON, rGPFUDP, rGPFDAT);
#endif
printf("VIDCON0=%08x, LCDCON1=%08x \n",rVIDCON0, rLCDCON1);
rADCCON|=(1<<2);
/* Pin Configuration in Sleep Mode */
rMISCCR|=(1<<12); //USB port0 = suspend
// Lcd_EnvidOnOff(0); // jcs 060610 //LCD must be off before entering Sleep mode.
// set flag sleep wakeup : rINFORM0 = 0x2BED
rINFORM0 = 0x2BED;
// Delay(20000);
// Entering the SLEEP mode
//*************************//
rRSTCON=0x1ff80;
rOSCSET=0x1000;
rPWRCFG=(1<<15)|(1<<9)|(0<<8)|(0<<7)|(0<<4)|(0<<3)|(0<<2)|(1<<0);
printf("rOSCSET: %x\n", rOSCSET);
printf("rRSTCON: %x\n", rRSTCON);
printf("rPWRCFG: %x\n", rPWRCFG);
printf("Sleep count: %x\n", rINFORM1);
#ifdef __EVT1
#else
printf("gstatus3=%08x, gstatus4=%08x \n",rGSTATUS3,rGSTATUS4);
#endif
rPWRMODE=rPWRMODE&~(0xffff<<0)| (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 interrupt occured\n");
batt_flag=1;
//Batt_Sleep();
}
//================================================================================
void Test_BattFaultInterrupt(void)
{
int i;
printf("Battery fault interrupt test.\n");
printf("Detect low-level.\n");
printf("0, 2 : Ignore.\n");
printf("1 : Generation interrupt.\n");
printf("3 : The system enters into the Sleep mode when nBatt_flt is asserted.\n");
printf("Select battery function : ");
i = GetIntNum() & 0x3;
rPWRCFG = rPWRCFG & ~(0x3<<0) |(i<<0);
printf("%d is selected\n", i);
pISR_BAT_FLT = (U32)BattFaultInt;
rSRCPND = BIT_BAT_FLT;
rINTPND = BIT_BAT_FLT;
if(i==3)
{
printf("S3C2443 will wake up by EINT0 (Falling Edge Triggered).\n");
#ifdef __EVT1
rEXTINT0 = (1<<3); //pull-down disable
#else
rGPFUDP &= ~(1<<1); // Pull up down disable
#endif
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //GPF0=EINT0
#ifdef __EVT1
rEXTINT0=(0x2<<0); //EINT0=falling edge triggered
#else
rEXTINT0=rEXTINT0&~(0x7<<0)|(0x2<<0); //EINT0=falling edge triggered
#endif
rPWRCFG|=(1<<15);
printf(" PWRCFG:0x%x\n", rPWRCFG);
}
rINTMSK = rINTMSK & ~(BIT_BAT_FLT); // unmask.
while(batt_flag==0)
{
if(Uart_GetKey()!=0) break;
}
batt_flag=0;
rPWRCFG = rPWRCFG & ~(0x3<<0);
// Batt_Sleep();
printf("exit.\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -