📄 stop.c
字号:
/*****************************************
NAME: STOP.C
DESC: S3C2460X STOP mode test code
HISTORY:
2004.06.11 : ver 0.0
******************************************/
#include "def.h"
#include "option.h"
#include "2460addr.h"
#include "2460lib.h"
#include "2460slib.h"
//#include "lcdlib.h"
#include "stop.h"
#include "idle.h"
static int p_cnt;
static void LcdEnvidOnOff(unsigned int onoff)
{
if(onoff==1)
rLCDCON1 = rLCDCON1|(3); // ENVID On using Per Frame method
else
rLCDCON1 &= (~3); // ENVID Off using Per Frame method
}
static void __irq Eint0Int(void) //EINT0
{
//printf("rINTOFFSET=0x%x\n", rINTOFFSET);
rEINTPEND=BIT_EINT_0;
ClearPending(BIT_EXT0_3);
#if USE_WFI // EINT requests IRQ even though the source is masked.
rWKUPSTAT |= (1<<0); //Clear STOP_BIT just after exiting STOP mode.
#endif
printf("EINT0 for STOP wake-up.\n");
}
static void __irq Eint0Int_Hard(void)
{
//EINT0
//This test needs External Function Generator to generate INT request
rEINTPEND=BIT_EINT_0;
ClearPending(BIT_EXT0_3);
//p_cnt++;
//if(p_cnt%100==0)
//WrUTXH0('#');
}
static void __irq AlarmInt(void)
{
ClearPending(BIT_RTC);
printf("ALARM for STOP wake-up.\n");
}
static void __irq ModemInt(void)
{
ClearPending(BIT_MODEM);
printf("Modem int. for STOP wake-up.\n");
}
static void __irq PenDownInt(void)
{
rSUBSRCPND=BIT_SUB_PENDN;
ClearPending(BIT_ADC_PENDN);
printf("Touch screen pen-down for STOP wake-up.\n");
}
//Initialize SDRAM for SDRAM self-refresh test.
void Test_InitSDRAM(int check_start, int check_size)
{
int i;
printf("[SDRAM Initialization]\n");
printf("Fill SDRAM for self-refresh test.\n");
for(i=check_start;i<(check_start+check_size);i+=4)
*((unsigned int *)i)=i^0x55555555;
printf("Filling SDRAM is completed.\n");
}
void Test_CheckSDRAM(int check_start, int check_size)
{
int i;
int error=0;
printf("Check SDRAM for self-refresh test\n");
for(i=check_start;i<(check_start+check_size);i+=4)
{
if(*((unsigned int *)i)!=(i^0x55555555))
{
printf("Mem Error:%x=%x(%x)\n",i,*((unsigned int *)i),i^0x55555555);
error++;
}
if(error>20)
break;
}
if(error)
printf("SDRAM self-refresh test:FAILED\n");
else
printf("SDRAM self-refresh test:O.K.\n");
}
void ConfigStopGPIO(void)
{
// Check point
// *** There must not be input floating pins
}
volatile unsigned int cnt_Stop=0;
void Test_StopMode(void)
{
int i, j;
unsigned int portStatus[26];
printf("[STOP Mode Test]\n");
//printf("nBATT_FLT pin should be tested.\n");
#if USE_RTC_ALARM
printf("S3C2460 will wake up by EINT0, Stylus down, Modem or Alarm(10 sec).\n");
#else
printf("S3C2460 will wake up by EINT0, Stylus down, Modem.\n");
#endif
//rLOCKTIME=(0xfff<<16)|(0xfff<<0); // 3602 is about 300us at 12Mhz
// Save the port configurations
#if GPIO_RESTORE
for(i=0;i<26;i++)
portStatus[i]=*( (volatile unsigned int *)(0x44800000 + i*4));
#endif
ConfigStopGPIO();
#if XTAL_ENABLE_STOPMODE
rPWRCFG |= (1<<2);
#else
rPWRCFG &= ~(1<<2);
rOSCSET=(XTAL_SETTLEDOWN_TIME<<16)|(XTAL_SETTLEDOWN_TIME<<0);
#endif
//Config EINT0
rGPJCON = (rGPJCON & ~(0x3)) | (1<<1);
rEINTCON0=0x2; //falling
//Interrupt service routine
pISR_EXT0_3=(unsigned int)Eint0Int; //for EINT0
pISR_RTC=(unsigned int)AlarmInt;
pISR_ADC_PENDN=(unsigned int)PenDownInt;
pISR_MODEM=(unsigned int)ModemInt;
//Clear all sub pending
rEINTPEND=rEINTPEND;
rSUBSRCPND=BIT_SUB_PENDN;
//Clear interrupt pending
ClearPending(BIT_ALLMSK);
/*
//Unmask interrupt
rINTMSK=rINTMSK&~(BIT_EXT0|BIT_RTC|BIT_MODEM|BIT_ADC_PENDN);
//Unmask sub interrupt
rEINTMASK=rEINTMASK&~(BIT_EINT_0);
rINTSUBMSK&=~(BIT_SUB_PENDN);
*/
#if CHECK_SDRAM_SELFREFRESH
Test_InitSDRAM(_NONCACHE_STARTADDRESS,0x400000);
#endif
#if USE_RTC_ALARM
SetAlarmWakeUp(10);
#endif
SetTouchWakeUp();
rADCDLY |= (1<<16); // for stop wake-up(sync logic)
SetModemWakeUp();
#if AC97_USE
printf("AC97Codec is going to LP mode, now.\n");
AC97_Init();
AC97_Codec_Init(22050);
AC97_Codec_Cmd(0, 0x26, 0x1000); // AC97CODEC is going to LP mode.
rAC_GLBCTRL&=~(1<<2);
#endif
rADCCON|=(1<<2);
//tark ????? USB suspend
rGPJDAT&=~(1<<2);
rGPJCON=rGPJCON&~(3<<4)|(1<<4);//USB off
LcdEnvidOnOff(0); //Before entering STOP mode, LCD must be off
//***Enter STOP mode
#if USE_WFI
if( !( rPWRCFG & (3<<6) ) )
rPWRCFG = ( rPWRCFG & ~(3<<6) ) | (2<<6);
MMU_WaitForInterrupt();// WFI drive the S3C2460 into stop mode
#else
rPWRMODECON |= (1<<16);// Issue stop command
__asm
{
nop;
nop;
nop;
nop;
nop;
nop;
nop;
nop;
nop;
nop;
}
#endif
//***Exit STOP mode
#if !USE_WFI
rPWRMODECON &= ~(1<<16); //Clear STOP_BIT just after exiting STOP mode.
#endif
//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<<2) ) // TS?
{
printf("\n__ Wake-up by TS\n");
rWKUPSTAT |= (1<<2);
}
else if( rWKUPSTAT & (1<<3) ) // KEY Pad?
{
printf("\n__ Wake-up by key pad\n");
printf("\rWKUPSTAT=0x%x\n", rWKUPSTAT);
rWKUPSTAT |= (1<<3);
}
else if( rWKUPSTAT & (1<<4) ) // MSM?
{
printf("\n__ Wake-up by MSM\n");
rWKUPSTAT |= (1<<4);
}
rINTMSK = (BIT_ALLMSK);
rINTSUBMSK = (BIT_SUB_ALLMSK1);
rEINTMASK = (BIT_EINT_ALLMSK);
#if AC97_USE
printf("AC97Codec is going to Normal mode, now.\n");
AC97_Init();
AC97_Codec_Init(22050);
#endif
#if GPIO_RESTORE
//Restore the port configurations
for(i=0;i<26;i++)
*((unsigned int *)(0x44800000 +i*4))=portStatus[i];
#endif
Led_Display(0xa);
LcdEnvidOnOff(1);
//The Wake-up source is indicated by rSRCPND.
#if CHECK_SDRAM_SELFREFRESH
Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000);
#endif
/*
cnt_Stop++;
if(cnt_Stop>100000)
{
cnt_Stop=0;
return;
}
Test_StopMode();
*/
}
/*
void Test_StopModeHard(void)
{
unsigned int i=0, j;
unsigned int portStatus[26];
printf("[STOP Mode Test]\n");
printf("nBATT_FLT pin should be tested.\n");
printf("S3C2460 will wake up by EINT9 at its falling edge.\n");
rLOCKTIME=(3602<<16)|(3602<<0); // 3602 is about 300us at 12Mhz
// Save the port configurations
#if GPIO_RESTORE
for(i=0;i<26;i++)
portStatus[i]=*( (volatile unsigned int *)(0x44800000 + i*4));
#endif
ConfigStopGPIO();
#if XTAL_ENABLE_STOPMODE
rALIVECON&=~(1<<0);
rCLKSRC=rCLKSRC&~(1<<8)|(1<<8); //X-Tal oscillator is always enabled even S3C2460 is in the STOP mode
#else
rALIVECON|=(1<<0);
rXTALWSET=(XTAL_SETTLEDOWN_TIME<<16)|(XTAL_SETTLEDOWN_TIME<<0);
#endif
#if CHECK_SDRAM_SELFREFRESH
Test_InitSDRAM(_NONCACHE_STARTADDRESS,0x400000);
#endif
Eint_Port_0_1_9_11(9, FALLING);//FALLING, LOW_LEVEL, HIHG_LEVEL, RISING, BOTH
//Interrupt service routine
pISR_EINT0_2=(unsigned int)EintInt_Hard;
pISR_EINT7_10=(unsigned int)EintInt_Hard;
//Clear sub interrupt pending
rEINTPEND=BIT_EINTPEND_EINT9|BIT_EINTPEND_EINT9;
//Clear interrupt pending
ClearPending(BIT_EINT0_2|BIT_EINT7_10);
rADCCON|=(1<<2);
LcdEnvidOnOff(0); //Before entering STOP mode, LCD must be off
printf("\nNow, SMDK2460 is entering STOP mode.\n");
Uart_TxEmpty(0); //Wait until UART0 Tx buffer empty.
#if 1
//Unmask interrupt
rINTMSK=rINTMSK&~(BIT_EINT0_2|BIT_EINT7_10);
//Unmask sub interrupt
rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT0|BIT_EINTPEND_EINT9);
#endif
#if USE_WFI
rPWRMAN |= (1<<12); // use WFI
#else
rPWRMAN &= ~(1<<12);// not use WFI
#endif
//for(i=0;i<1;i++)
while(i<100000)
{
//***Enter STOP mode
printf("%d\n",i++);
Uart_TxEmpty(0);
rCLKCON= ( rCLKCON&~(1<<0) ) | (1<<0); //Transition to STOP mode
#if USE_WFI
MMU_WaitForInterrupt();
#endif
//***Exit STOP mode
rCLKCON&=~(1<<0); //Clear STOP_BIT just after exiting STOP mode.
}
printf("%d\n",i);
rEINTMASK = (BIT_EINTPEND_ALLMSK);
rINTMSK = (BIT_ALLMSK);
#if GPIO_RESTORE
//Restore the port configurations
for(i=0;i<26;i++)
*((unsigned int *)(0x44800000 +i*4))=portStatus[i];
#endif
#if CHECK_SDRAM_SELFREFRESH
Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000);
#endif
LcdEnvidOnOff(1);
printf("STOP Hard Test is over.\n");
}
void __irq FIQBattFaultInt(void)
{
printf("nBATT_FAULT FIQ is requested.\n");
}
void __irq IRQBattFaultInt(void)
{
rSUBSRCPND=BIT_SUB_BATFLT;
ClearPending(BIT_WDT_BATFLT);
printf("nBATT_FAULT IRQ is requested.\n");
}
void Test_BattFaultInterrupt(void)
{
printf("[nBATT_FAULT interrupt Test]\n");
printf("Push any key to exit!\n");
pISR_WDT_BATFLT=(unsigned)IRQBattFaultInt;
pISR_FIQ=(unsigned)FIQBattFaultInt;
// Clear interrupt pending--> only for irq
ClearPending(BIT_WDT_BATFLT);
rSUBSRCPND=BIT_SUB_BATFLT;
rPWRMAN = ( rPWRMAN & ~(3<<9) ) | (1<<9); // FIQ
//rPWRMAN = ( rPWRMAN & ~(3<<9) ) | (2<<9); // Ignore
// Unmask--> only for irq
rINTMSK=rINTMSK&~(BIT_WDT_BATFLT);
rINTSUBMSK=rINTSUBMSK&~(BIT_SUB_BATFLT);
while(!Uart_GetKey());
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -