📄 idle.c
字号:
/*****************************************
NAME: idle.c
DESC: IDLE mode test
HISTORY:
03.23.2002:purnnamu: first release for 2410
06.02.2003:DonGo: Modified for 2442
*****************************************/
#include "System.h"
#include "idle.h"
#define TESTYEAR (0x00)
#define TESTMONTH (0x12)
#define TESTDATE (0x31)
#define TESTDAY (0x06) // SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
#define TESTHOUR (0x23)
#define TESTMIN (0x59)
#define TESTSEC (0x59)
#define TESTYEAR2 (0x01)
#define TESTMONTH2 (0x01)
#define TESTDATE2 (0x01)
#define TESTDAY2 (0x07) // SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
#define TESTHOUR2 (0x00)
#define TESTMIN2 (0x00)
#define TESTSEC2 (0x00)
unsigned int eint;
void SetAlarmWakeUp(void)
{
rRTCCON = 0x1; // R/W enable, 1/32768, Normal(merge), No reset
rBCDYEAR = TESTYEAR;
rBCDMON = TESTMONTH;
rBCDDAY = TESTDAY; // SUN:1 MON:2 TUE:3 WED:4 THU:5 FRI:6 SAT:7
rBCDDATE = TESTDATE;
rBCDHOUR = TESTHOUR;
rBCDMIN = TESTMIN;
rBCDSEC = TESTSEC;
rALMYEAR=TESTYEAR2 ;
rALMMON =TESTMONTH2;
rALMDATE=TESTDATE2 ;
rALMHOUR=TESTHOUR2 ;
rALMMIN =TESTMIN2 ;
rALMSEC =TESTSEC2+0x10;
rRTCALM=0x7f;
rRTCCON=0x0; // R/W disable, 1/32768, Normal(merge), No reset
}
static void __irq Eint0Int(void)
{
rEINTPEND |= (1<<0);
ClearPending(BIT_EINT0);
printf("EINT0 interrupt is occurred for IDLE wake-up.\n");
}
static void __irq Eint11Int(void)
{
rPWRMODE &=~(1<<17);
rEINTPEND |= (1<<11);
rEINTMASK |= ((1<<11)|(1<<0));
ClearPending(BIT_EINT8_23);
printf("EINT11 interrupt is occurred for IDLE wake-up.\n");
eint =1 ;
}
static void __irq AlarmInt(void)
{
ClearPending(BIT_RTC);
printf("ALARM interrupt is occurred for IDLE wake-up.\n");
SetAlarmWakeUp();
rRTCCON = 0x0; // R/W disable, but interrupt will be generated.
}
static volatile int t0cnt,t1cnt;
#if 0
static void __irq Timer0Int(void)
//Timer0 interrupt will be used to test the IDLE mode hard
{
ClearPending(BIT_TIMER0);
printf("0");
//t0cnt++;
}
static void __irq Timer1Int(void)
//Timer1 interrupt will be used to test the IDLE mode hard
{
ClearPending(BIT_TIMER1);
printf("1");
//t1cnt++;
}
static void __irq Timer2Int(void)
//Timer1 interrupt will be used to test the IDLE mode hard
{
ClearPending(BIT_TIMER2);
printf("2");
}
static void __irq Timer3Int(void)
//Timer1 interrupt will be used to test the IDLE mode hard
{
ClearPending(BIT_TIMER3);
printf("3");
}
static void __irq Timer4Int(void)
//Timer1 interrupt will be used to test the IDLE mode hard
{
ClearPending(BIT_TIMER4);
printf("4");
}
#endif
static void __irq BattFaultInt(void)
{
rINTMSK |= (BIT_BAT_FLT); // mask.
ClearPending(BIT_BAT_FLT)
printf("BATT_FLT interrupt occured\n");
}
/**********************
* IDLE mode test *
**********************/
void Test_IdleMode(void)
{
int i;
printf("[IDLE Mode Test]\n");
printf("After 10 seconds, S3C2443 will wake up by RTC alarm interrupt.\n");
printf("S3C2443 will also wake up by EINT0 or EINT11 or BATT_FLT.\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
#else
rEXTINT0=rEXTINT0&~(0x7<<0)|(0x2<<0); //EINT0=falling edge triggered
#endif
rGPGUDP =~ (1<<7);
rGPGCON=rGPGCON & ~(3<<6)|(2<<6); //GPG3=EINT11
rEXTINT1=rEXTINT1&~(7<<12)|(2<<12); //EINT11=falling edge triggered
pISR_EINT0=(U32)Eint0Int;
pISR_EINT8_23=(U32)Eint11Int;
pISR_RTC=(U32)AlarmInt;
pISR_BAT_FLT = (U32)BattFaultInt;
rSRCPND = BIT_BAT_FLT;
rINTPND = BIT_BAT_FLT;
// clear pending interrupt
rEINTPEND |= (1<<11);
rSRCPND = BIT_EINT0|BIT_RTC|BIT_EINT8_23; //to clear the previous pending states
rINTPND = BIT_EINT0|BIT_RTC|BIT_EINT8_23;
rEINTMASK &= ~(1<<11);
rINTMSK &=~(BIT_EINT0|BIT_RTC|BIT_EINT8_23|BIT_BAT_FLT);
// printf("Alarm wake-up (y/n)? ");
// if(Uart_GetKey()=='y')
// {
// printf("\nS3C2443 will wake up by RTC alarm(10 sec) \n");
// SetAlarmWakeUp();
// }
rHCLKCON = (rHCLKCON & ~(0xfffff)) | (1<<19) | (1<<18) | (1<<9);
printf("\nHCLK Control = %x",rHCLKCON);
rPCLKCON = (rPCLKCON & ~(0xffff)) | (1<<13) | (1<<12) | (1<<11) | (1<<10) | (1<<9) | (1<<7) | (0xf<<0);
printf("\nPCLK Control = %x",rPCLKCON);
rSCLKCON = (rSCLKCON & ~(0x1ffff)) | (1<<15) | (1<<10) | (1<<9) | (1<<8) | (0xf<<0);
printf("\nSCLK Control = %x",rSCLKCON);
rBANKCON1 |= (1<<4);
printf("\nSDRAM Power Down\n");
rRTCCON = 0x0; // R/W disable, but interrupt will be generated.
//***Enter Idle mode *** : select MMU_IDLE or PWRMODECON//
//rPWRCFG |=(1<<6); //STADNBYWFI : 00:ignore, 01:idle, 10:stop, 11:sleep mode
//MMU_WaitForInterrupt();
rPWRCFG=rPWRCFG&~(0x3<<0)|(0x1<<0);
printf(" PWRCFG:0x%x\n", rPWRCFG);
rPWRMODE |=(1<<17); //enter IDLE mode.
//***Exit Idle mode ***//
for(i=0;i<10;i++);
//wait until S3C2400X enters IDLE mode.
//wait EINT0 interrupt or RTC alarm interrupt
rPWRMODE &=~(1<<17);
//turn-off IDLE bit. IDLE bit should be turned off after wake-up.
printf("Return to Normal Mode.\n");
printf("wake-up= %08x\n", rWKUPSTAT);
//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 if( rWKUPSTAT & (1<<5) ) // BATFLT?
{
printf("\n__ Wake-up by nBATFLT\n");
rWKUPSTAT |= (1<<5);
}
rINTMSK=BIT_ALLMSK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -