⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stop.c

📁 支持三星原产的S3C24A0开发板
💻 C
字号:
/*****************************************
 NAME: STOP.C
 DESC: STOP mode test code
 HISTORY:
 2003.04.21 : ver 0.0
******************************************/
 
#include "def.h"
#include "option.h"
#include "24a0addr.h"
#include "24a0lib.h"
#include "24a0slib.h" 

#include "lcdlib.h"
#include "stop.h"
#include "idle.h"

static int  p_cnt;

static void __irq EintInt(void)	//EINT0,1
{
    rEINTMASK |= ( (BIT_EINTPEND_EINT1)|(BIT_EINTPEND_EINT0) );
    rINTMSK |= (BIT_EINT0_2);

    if(rEINTPEND&(1<<0))
    {
	rEINTPEND=BIT_EINTPEND_EINT0;
	Uart_Printf("EINT0 for STOP wake-up.\n");
    }
    else if(rEINTPEND&(1<<1))
    {
	rEINTPEND=BIT_EINTPEND_EINT1;
	Uart_Printf("EINT1 for STOP wake-up.\n");
    }
    else 
	Uart_Printf("EINT Error!!\n");

    ClearPending(BIT_EINT0_2);
}

static void __irq Eint9Int(void) //EINT9
{
    rEINTMASK |=(BIT_EINTPEND_EINT9);
    rINTMSK |= (BIT_EINT7_10);

    rEINTPEND=BIT_EINTPEND_EINT9;
    ClearPending(BIT_EINT7_10);
    Uart_Printf("EINT9 for STOP wake-up.\n");
}

static void __irq Eint11Int(void) //EINT11
{
    //Must not be occured......;-)
    rEINTMASK |=(BIT_EINTPEND_EINT11);
    rINTMSK |= (BIT_EINT11_14);

    rEINTPEND=BIT_EINTPEND_EINT11;
    ClearPending(BIT_EINT11_14);

    Uart_Printf("???EINT11 for STOP wake-up.\n");
}

static void __irq EintInt_Hard(void)
{
    //EINT9
    //This test needs External Function Generator to generate INT request 

    rEINTPEND=BIT_EINTPEND_EINT9;
    ClearPending(BIT_EINT7_10);
    p_cnt++;
    if(p_cnt%100==0)
	WrUTXH0('#');
}

static void __irq AlarmInt(void)
{
    rINTMSK=rINTMSK|(BIT_RTC);
    ClearPending(BIT_RTC);
    Uart_Printf("ALARM for STOP wake-up.\n");
}

static void __irq ModemInt(void)
{
    rINTMSK=rINTMSK|(BIT_MODEM);
    ClearPending(BIT_MODEM);
    Uart_Printf("Modem int. for STOP wake-up.\n");
}

static void __irq PenDownInt(void)
{
    rINTSUBMSK |= BIT_SUB_PENDN;
    rINTMSK |= BIT_ADC_PENUP_DOWN;

    ClearPending(BIT_ADC_PENUP_DOWN);
    rSUBSRCPND=BIT_SUB_PENDN;
    Uart_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;

    Uart_Printf("[SDRAM Initialization]\n");
    Uart_Printf("Fill SDRAM for self-refresh test.\n");

    for(i=check_start;i<(check_start+check_size);i+=4)
    	*((U32 *)i)=i^0x55555555;
    
    Uart_Printf("Filling SDRAM is completed.\n");
}

void Test_CheckSDRAM(int check_start, int check_size)
{
    int i;
    int error=0;

    Uart_Printf("Check SDRAM for self-refresh test\n");
    for(i=check_start;i<(check_start+check_size);i+=4)
    {
    	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");	
}

void ConfigStopGPIO(void)
{
    // Check point
    // 1) NC pin: input pull-up on 
    // 2) If input is drived externally: input pull-up off
    // 3) If a connected component draws some current: output low.
    // 4) If a connected component draws no current: output high.
    // 5) UART Tx: Output(H) and enable pull-up
    //    UART Rx: Input and disable pull-up

    //CAUTION:Follow the configuration order for setting the ports. 
    // 1) setting value(GPnDAT) 
    // 2) setting control register  (GPnCON)
    // 3) configure pull-up resistor(GPnUP)  

    //32bit data bus configuration  
    rGPDAT =(1<<30)|(1<<29);
    
    //Ports	:GP31	    GP30	GP29	    GP28	GP27	    GP26	GP25    
    //Signal	:XuRXD1	    XuTXD1	XuRTSn1	    XuCTSn1	XkpCOL4	    XkpCOL3	XkpCOL2
    //Setting	:IN	    OUT(H)	OUT(H)	    IN		IN	    IN		IN
    //PU_OFF	:off(UART)  on(UART)    on(UART)    off(UART)   off(extPD)  off(extPD)  off(extPD)
    //---------------------------------------------------------------------------------------------
    //Ports	:GP24	    GP23	GP22	    GP21	GP20,	    GP19
    //Signal	:XkpCOL1    XkpCOL0	XkpROW4     XkpROW3	XkpROW2     XkpROW1
    //Setting	:IN	    IN		IN	    IN		IN	    IN
    //PU_OFF	:off(extPD) off(extPD)  off(extPU)  off(extPU)  off(extPU)  off(extPU)
    rGPCON_U = 0x500000; 
    
    //Ports	:GP18	    GP17    GP16	GP15	GP14	    GP13	GP12	    GP11		    
    //Signal	:XkpROW0    L3_MODE L3_CLOCK    L3_DATA	SMC_INT	    ETHER_INT	MODEM_INT   SD_INT	    
    //Setting	:IN	    IN	    IN		IN	IN	    IN		IN	    IN
    //PU_OFF	:off(extPU) on	    on	    	on	off(extPU)  on		off(extPU)  off(extPU)    
    rGPCON_M = 0x0; //ETHER_INT=Hi-Z before initialaize

    //Ports	:GP10	GP9	    GP8 	GP7 		GP6		GP5		 		    
    //Signal	:YMON	EINT9	    nSS_KBD	KEYBOARD(LED3)	LCD_CS(LED2)	LCD_SCLK(LED1)	    
    //Setting	:IN	EINT9(wk)   IN		IN		IN		IN		
    //PU_OFF	:on	off(extPU)  on		off(extPU)	off(extPU)	off(extPU)    		
    //--------------------------------------------------------------------------------------------
    //Ports	:GP4		GP3	GP2	GP1	    GP0
    //Signal	:LCD_SDI(LED0)  nDTR    nDSR    SMC_WP	    SD_WP
    //Setting	:IN		IN	IN	EINT1(wk)   EINT0(wk)
    //PU_OFF	:off(extPU)	on	on	off(extPU)  off(extPU)
    rGPCON_L = 0x8000a;

    //Configure pull-up function
    rGPPU = 0x9ffc5af3;

    //External interrupt will be falling edge triggered.
    rEXTINTC0 = 0x222; 	    //EINT2~0
    rEXTINTC1 = 0x2222222;  //EINT9~3

    //Peri. port pull-up control
    //PERIPU	:PERIPU[26] PERIPU[24]	PERIPU[14]	PERIPU[13]	PERIPU[12]	PERIPU[11]	
    //Signal	:XmsSDIO    XsdDAT[3:0]	XrADR[25:18]	XciCDATA[7:0]	XmiADR[10:0]	XmiDATA[7:0]	
    //PU_OFF    :off(extPU) off(extPU)	on		on		on		on
    //--------------------------------------------------------------------------------------------------
    //PERIPU    :PERIPU[10] PERIPU[9]	PERIPU[8]   PERIPU[4]	    PERIPU[2]
    //Signal    :XspiCLK    X2sLRCK	XspiMISO    XrDATA[15:0]    XpDATA[31:0]
    //PU_OFF    :on	    on		on	    on		    on
    //rENPU = 0x50f0200; //Xr, Xd, XpDATA pull-up on. The data bus will not be float by pull-up resister. 
    rPERIPU=(1<<26)|(1<<24);
}

#define XTAL_SETTLEDOWN_TIME	(0xf000) //2500 times
//#define XTAL_SETTLEDOWN_TIME	(0xffff) // 486 times
//#define XTAL_SETTLEDOWN_TIME	(0x5000) //2231 times
//#define XTAL_SETTLEDOWN_TIME	(0x0000)
#define CHECK_SDRAM_SELFREFRESH	(TRUE)
#define CHOOSE_EINT0_TYPE	(FALSE)
#define USE_RTC_ALARM		(TRUE)
#define GPIO_RESTORE		(TRUE)
#define XTAL_ENABLE_STOPMODE	(FALSE)

void Test_StopMode(void)
{
    int i, j;
    U32 portStatus[26];
    Uart_Printf("[STOP Mode Test]\n");
    Uart_Printf("nBATT_FLT pin should be tested.\n");
    Uart_Printf("S3C24A0 will wake up by EINT0/1/9, Stylus down, Modem or Alarm(10 sec).\n");

    //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 U32 *)(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 S3C24A0 is in the STOP mode
#else 
    rALIVECON|=(1<<0);
    rXTALWSET=(XTAL_SETTLEDOWN_TIME<<16)|(XTAL_SETTLEDOWN_TIME<<0);
#endif

    //Wake-up(EINT0)
    rGPCON_L= (rGPCON_L & ~(3<<0) ) | (2<<0);      //GP0=EINT0
#if CHOOSE_EINT0_TYPE	   
    SelectEintType();
#else
    rEXTINTC0=( rEXTINTC0 & ~(7<<0) ) | (2<<0);	//EINT0= falling edge triggered
#endif

    //Wake-up(EINT1)     
    rGPCON_L= ( rGPCON_L & ~(3<<2) ) | (2<<2); //GP1=EINT1
    rEXTINTC0=( rEXTINTC0 & ~(7<<4) ) | (0<<0); //EINT0=low level triggered

    //Wake-up(EINT9) 
    rGPCON_L= ( rGPCON_L&~(3<<18) ) | (2<<18);     //GP9=EINT9
    rEXTINTC1= ( rEXTINTC1 & ~(7<<24) ) | (2<<24); //EINT9=rising edge triggered
    
    //To test not available wake-up EINT(EINT11) 
    rGPCON_M=rGPCON_M&~(3<<0)|(2<<0);    //GP11=EINT11
    rEXTINTC2=rEXTINTC2&~(7<<0)|(2<<0);  //EINT11=falling edge triggered

    //Interrupt service routine
    pISR_EINT0_2=(U32)EintInt;	    //for EINT0/1
    pISR_EINT7_10=(U32)Eint9Int;    //for EINT9
    pISR_EINT11_14=(U32)Eint11Int;  //for EINT11    
    pISR_RTC=(U32)AlarmInt;
    pISR_ADC_PENUP_DOWN=(U32)PenDownInt;
    pISR_MODEM=(U32)ModemInt;
    
    //Clear all sub pending
    rEINTPEND=rEINTPEND;
    rSUBSRCPND=(BIT_SUB_PENDN|BIT_SUB_PENUP);

    //Clear interrupt pending
    ClearPending(BIT_EINT11_14);
    ClearPending(BIT_EINT7_10);
    ClearPending(BIT_EINT0_2);
    ClearPending(BIT_RTC);
    ClearPending(BIT_MODEM);
    ClearPending(BIT_ADC_PENUP_DOWN);

#if 1
    //Unmask interrupt
    rINTMSK=rINTMSK&~(BIT_EINT11_14);
    rINTMSK=rINTMSK&~(BIT_EINT7_10);
    rINTMSK=rINTMSK&~(BIT_EINT0_2);
    rINTMSK=rINTMSK&~(BIT_RTC);
    rINTMSK=rINTMSK&~(BIT_MODEM); 
    rINTMSK=rINTMSK&~(BIT_ADC_PENUP_DOWN);
    
    //Unmask sub interrupt 
    //rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT0);
    rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT1);
    rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT9);
    rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT11);
    rINTSUBMSK&=~(BIT_SUB_PENDN);
    rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT0);
    //for(i=0;i<100;i++);
#endif	     
 
#if CHECK_SDRAM_SELFREFRESH
    Test_InitSDRAM(_NONCACHE_STARTADDRESS,0x400000);
#endif

    //rPWRMAN|=(1<<8);
    
#if USE_RTC_ALARM   
    SetAlarmWakeUp(10);
#endif
    SetTouchWakeUp();
    SetModemWakeUp();

    Uart_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);

    rADCCON|=(1<<2);
    //There is no USB port control bit in S3C24A0x. Well.....

    LcdEnvidOnOff(0); //Before entering STOP mode, LCD must be off    
    Uart_Printf("\nNow, SMDK24A0 is entering STOP mode.\n");
    Uart_TxEmpty(0);	//Wait until UART0 Tx buffer empty.

    MMU_DisableICache();
    MMU_InvalidateICache();

    //***Enter STOP mode
    //rPWRMAN |= (1<<12);
    rPWRMAN = 0x0;
    rCLKCON= ( rCLKCON&~(1<<0) ) | (1<<0);  //Transition to STOP mode 
   // MMU_WaitForInterrupt();
    //EnterStopMode();
/*    
    __asm
    	{
		nop
		nop
		nop
		nop
		nop
		nop
		nop
    	}
*/  
    //***Exit STOP mode
    for(i=0;i<100;i++);

    rCLKCON&=~(1<<0);  //Clear STOP_BIT just after exiting STOP mode.
    
    MMU_EnableICache();

    Uart_Printf("AC97Codec is going to Normal mode, now.\n");
    AC97_Init();
    AC97_Codec_Init(22050);

#if GPIO_RESTORE
    //Restore the port configurations
    for(i=0;i<26;i++)
	*((U32 *)(0x44800000 +i*4))=portStatus[i];
#endif

    Led_Display(0xa);
    LcdEnvidOnOff(1); 
    
#if 0
    //Unmask interrupt
    rINTMSK=rINTMSK&~(BIT_EINT11_14);
    rINTMSK=rINTMSK&~(BIT_EINT7_10);
    rINTMSK=rINTMSK&~(BIT_EINT0_2);
    rINTMSK=rINTMSK&~(BIT_RTC);
    rINTMSK=rINTMSK&~(BIT_MODEM); 
    rINTMSK=rINTMSK&~(BIT_ADC_PENUP_DOWN);
    
    //Unmask sub interrupt 
    //rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT0);
    rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT1);
    rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT10);
    rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT11);
    rINTSUBMSK&=~(BIT_SUB_PENDN);
    rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT0);
    for(i=0;i<100;i++);
#endif	     
	
    //The Wake-up source is indicated by rSRCPND.

    Uart_Printf("Return to Normal Mode.\n");    
    
#if CHECK_SDRAM_SELFREFRESH	
    Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000);
#endif
}

void Test_StopModeHard(void)
{
    int i, j;
    U32 portStatus[26];
    Uart_Printf("[STOP Mode Test]\n");
    Uart_Printf("nBATT_FLT pin should be tested.\n");
    Uart_Printf("S3C24A0 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 U32 *)(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 S3C24A0 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

    //Wake-up(EINT9) 
    rGPCON_L= ( rGPCON_L&~(3<<18) ) | (2<<18);     //GP9=EINT9
    rEXTINTC1= ( rEXTINTC1 & ~(7<<24) ) | (2<<24); //EINT9=falling edge

    //Interrupt service routine
    pISR_EINT7_10=(U32)EintInt_Hard;

    //Clear sub interrupt pending
    rEINTPEND=BIT_EINTPEND_EINT9;
    //Clear interrupt pending
    ClearPending(BIT_EINT7_10);
    
    rADCCON|=(1<<2);
    LcdEnvidOnOff(0); //Before entering STOP mode, LCD must be off    
    Uart_Printf("\nNow, SMDK24A0 is entering STOP mode.\n");
    Uart_TxEmpty(0);	//Wait until UART0 Tx buffer empty.

    //Unmask interrupt
    rINTMSK=rINTMSK&~(BIT_EINT7_10);
    //Unmask sub interrupt 
    rEINTMASK=rEINTMASK&~(BIT_EINTPEND_EINT9);
    
    /* 
    __asm
    	{
	    nop
	    nop
	    nop
	    nop
	    nop
	    nop
	    nop
	    nop// 0x10005d70
    	}
    */
    
    for(i=0;i<10;i++)
    {
	MMU_DisableICache();
	MMU_InvalidateICache();
	
	//***Enter STOP mode
	Uart_Printf("%d\n",i);
	Uart_TxEmpty(0);
	rCLKCON=rCLKCON&~(1<<0)|(1<<0);  //Transition to STOP mode 
	for(j=0;j<100;j++);

	//***Exit STOP mode
	rCLKCON&=~(1<<0);  //Clear STOP_BIT just after exiting STOP mode.
	MMU_EnableICache();
    }
    
    rINTMSK =BIT_ALLMSK;
#if GPIO_RESTORE
    //Restore the port configurations
    for(i=0;i<26;i++)
	*((U32 *)(0x44800000 +i*4))=portStatus[i];
#endif

#if CHECK_SDRAM_SELFREFRESH 
    Test_CheckSDRAM(_NONCACHE_STARTADDRESS,0x400000);
#endif
    
    LcdEnvidOnOff(1); 
    Uart_Printf("STOP Hard Test is over.\n");       
}

static void __irq BattFaultInt(void)
{
    rSUBSRCPND=BIT_SUB_BATFLT;
    ClearPending(BIT_WDT_BATFLT);

    Uart_Printf("nBATT_FAULT interrupt is requested.\n");
}

void Test_BattFaultInterrupt(void)
{
    int i;

    Uart_Printf("[nBATT_FAULT interrupt Test]\n");
    Uart_Printf("Push any key to exit!\n");
    
    pISR_WDT_BATFLT=(unsigned)BattFaultInt;
    
    //Clear interrupt pending
    ClearPending(BIT_WDT_BATFLT);
    rSUBSRCPND=BIT_SUB_BATFLT;
    
    //Unmask
    rINTMSK=rINTMSK&~(BIT_WDT_BATFLT);
    rINTSUBMSK=rINTSUBMSK&~(BIT_SUB_BATFLT);
    
    while(!Uart_GetKey());    
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -