?? 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 "def.h"
#include "option.h"
#include "2413addr.h"
#include "Console.h"
#include "System.h"
#include "MMUCache.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+0x5;
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)
{
rPWRMODECON &=~(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;
static void __irq Timer0Int(void)
//Timer0 interrupt will be used to test the IDLE mode hard
{
ClearPending(BIT_TIMER0);
t0cnt++;
}
static void __irq Timer1Int(void)
//Timer1 interrupt will be used to test the IDLE mode hard
{
ClearPending(BIT_TIMER1);
t1cnt++;
}
void Eint_test(void)
{
eint = 0;
printf("S3C2413 EINT0 or EINT11. test\n");
rGPFDN |= (1<<0);
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //PF0=EINT0
rEXTINT0=rEXTINT0&(7<<0)|(0x2<<0); //EINT0=falling edge triggered
rGPGDN |= (1<<3);
rGPGCON=rGPGCON & ~(3<<6)|(2<<6); //PG3=EINT11
rEXTINT1=rEXTINT1&(7<<12)|(0x6<<12); //EINT11=falling edge triggered
pISR_EINT0=(U32)Eint0Int;
pISR_EINT8_23=(U32)Eint11Int;
// clear pending interrupt1
rEINTPEND |= ((1<<3)|(1<<0));
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)|(1<<0));
rINTMSK &=~(BIT_EINT0|BIT_RTC|BIT_EINT8_23);
while(eint !=1);
}
/**********************
* IDLE mode test *
**********************/
void Test_IdleMode(void)
{
int i;
int extintMode;
printf("[IDLE Mode Test]\n");
printf("After 10 seconds, S3C2413 will wake up by RTC alarm interrupt.\n");
printf("S3C2413 will also wake up by EINT0 or EINT11.\n");
rGPFDN |= (1<<0);
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //PF0=EINT0
rEXTINT0=rEXTINT0&(7<<0)|(0x2<<0); //EINT0=falling edge triggered
rGPGDN |= (1<<3);
rGPGCON=rGPGCON & ~(3<<6)|(2<<6); //PG3=EINT11
rEXTINT1=rEXTINT1&(7<<12)|(0x6<<12); //EINT11=falling edge triggered
pISR_EINT0=(U32)Eint0Int;
pISR_EINT8_23=(U32)Eint11Int;
pISR_RTC=(U32)AlarmInt;
// clear pending interrupt
rEINTPEND |= ((1<<3)|(1<<0));
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)|(1<<0));
rINTMSK &=~(BIT_EINT0|BIT_RTC|BIT_EINT8_23);
SetAlarmWakeUp();
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();
rPWRMODECON |=(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
rPWRMODECON &=~(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;
}
void Test_IdleModeHard(void)
{
int i,j;
printf("[IDLE Mode Hard Test with Timer0]\n");
printf("S3C2413 will also wake up by EINT0 falling edge.\n");
Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //PF0=EINT0
rEXTINT0=rEXTINT0&(7<<0)|(0x2<<0); //EINT0=falling edge triggered
rSRCPND = BIT_EINT0;
rINTPND = BIT_EINT0;
t0cnt=0;t1cnt=0;
pISR_TIMER0=(U32)Timer0Int;
pISR_TIMER1=(U32)Timer1Int;
pISR_EINT0=(U32)Eint0Int;
rTCFG0=0x24; //PRESC01=1,PRESC234=1
rTCFG1=0x0; //TIMER0,1,2,3,4,5= 1/2
rTCNTB0=1000;
rTCNTB1=2570;
rTCON=0xa0a; //T0,T1=manualUpdate,interval mode
rTCON=0x909; //Start T0,T1.
//rTCON=0x00a;
//rTCON=0x009;
rINTMSK=~(BIT_EINT0|BIT_TIMER0|BIT_TIMER1);
for(i=0;i<100000;i++)
{
//***Enter Idle mode ***//
//rPWRCFG |=(1<<6); //STADNBYWFI : 00:ignore, 01:idle, 10:stop, 11:sleep mode
//MMU_WaitForInterrupt();
rPWRMODECON |=(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
rPWRMODECON &=~(1<<17);
//turn-off IDLE bit. IDLE bit should be turned off after wake-up.
if(i%100==0)printf("#");
}
rTCON=0x0; //turn the timer off
rINTMSK=BIT_ALLMSK;
printf("\nt0cnt=%d,t1cnt=%d(t0cnt+t1cnt>=10000)\n",t0cnt,t1cnt);
printf("Return to Normal Mode.\n");
}
/*********************
* MMU IDLE mode test *
*********************/
void Test_MMUIdleMode(void)
{
int i;
int extintMode;
//MMU_SetAsyncBusMode(); //ARM920T should be in the async. Bus mode.
printf("[MMU IDLE Mode Test]\n");
printf("This routine tests MMU registser7:Wait for interrupt function.\n");
printf("After 10 seconds, S3C2413 will wake up by RTC alarm interrupt.\n");
printf("S3C2413 will also wake up by EINT0.\n");
//Uart_TxEmpty(1); //Wait until UART0 Tx buffer empty.
rGPFCON=rGPFCON & ~(3<<0)|(2<<0); //PF0=EINT0
rEXTINT0=rEXTINT0&(7<<0)|(0x1<<0); //EINT0=falling edge triggered
pISR_EINT0=(U32)Eint0Int;
pISR_RTC=(U32)AlarmInt;
rSRCPND = BIT_EINT0|BIT_RTC; //to clear the previous pending states
rINTPND = BIT_EINT0|BIT_RTC;
rINTMSK=~(BIT_EINT0|BIT_RTC);
rINTMSK=~(BIT_RTC);
rINTMSK=BIT_ALLMSK;
SetAlarmWakeUp();
rRTCCON = 0x0; // R/W disable, but interrupt will be generated.
rPWRCFG |=(1<<6); //STADNBYWFI : 00:ignore, 01:idle, 10:stop, 11:sleep mode
MMU_WaitForInterrupt();
//wait until S3C2400X enters IDLE mode.
//wait EINT0 interrupt or RTC alarm interrupt
for(i=0;i<10;i++);
printf("Return to Normal Mode.\n");
rINTMSK=BIT_ALLMSK;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -