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

📄 power.c

📁 基于WinCE操作系统、SMDK2410硬件开发平台下的电源管理程序——主要完成系统的 睡眠、唤醒
💻 C
📖 第 1 页 / 共 2 页
字号:
    s2410IOP->rGPEUP =  0xffff;    //s2410IOP->rGPEDAT = 0x0;////////////////////////////////////

    
    
    

    //*** PORT F GROUP
    //Ports  : GPF7   GPF6   GPF5   GPF4   GPF3        GPF2  GPF1   GPF0
    //Signal : nLED_8 nLED_4 nLED_2 nLED_1 nIRQ_PCMCIA EINT2 KBDINT EINT0
    //Setting: Output Output Output Output IN          IN    IN     EINT0
    //Binary : 01     01,    01     01,    00          00,   00     10
    //PU_OFF :  1      1      1      1,     0-ext       1-ext 1-ext  1-ext
    //s2410IOP->rGPFDAT = 0x0  |(0xF<<4);
    //s2410IOP->rGPFCON = 0x5502;
    //s2410IOP->rGPFUP  = 0xf7;   
    s2410IOP->rGPFDAT = 0x90;//&= 0x9f;
    s2410IOP->rGPFCON = 0x5544;//= 0x55aa;  //0x550101
    s2410IOP->rGPFUP  = 0x00;//= 0x6f;     // The pull up function is disabled GPF[7:0]
    
    
                            
    //*** PORT G GROUP
    //Ports  : GPG15 GPG14 GPG13 GPG12 GPG11  GPG10    GPG9     GPG8     GPG7      GPG6    
    //Signal : nYPON YMON  nXPON XMON  EINT19 DMAMODE1 DMAMODE0 DMASTART KBDSPICLK KBDSPIMOSI
    //Setting: OUT   OUT   OUT   OUT   OUT    OUT      OUT      OUT      OUT       OUT
    //Binary : 01    01,   01    01,   01-dbg 01,      01       01,      01        01
    //PU_OFF :  1     1     1     1,    1-ext  1        1        1,       1         1
    //---------------------------------------------------------------------------------------
    //Ports  : GPG5       GPG4      GPG3   GPG2    GPG1    GPG0    
    //Signal : KBDSPIMISO LCD_PWREN EINT11 nSS_SPI IRQ_LAN IRQ_PCMCIA
    //Setting: IN         IN        EINT11 IN      IN      IN
    //Binary : 00         00,       10     00,     00      00
    //PU_OFF :  0-ext      0,        1-ext  0       0       0
   // s2410IOP->rGPGDAT = 0x0 |(1<<11)|(1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<9)|(1<<8)|(1<<7)|(1<<6) ;
   // s2410IOP->rGPGCON = 0x55455080;   //GPG11=OUT  //for debug
   // s2410IOP->rGPGUP  = 0xfbc8;    
    s2410IOP->rGPGDAT = 0x0000;//0x0;
    s2410IOP->rGPGCON = 0x55555550;//0x55455080;
    s2410IOP->rGPGUP  = 0xffff;//0xfbff;

    //*** PORT H GROUP
    //Ports  : GPH10   GPH9    GPH8 GPH7  GPH6  GPH5 GPH4 GPH3 GPH2 GPH1  GPH0 
    //Signal : CLKOUT1 CLKOUT0 UCLK nCTS1 nRTS1 RXD1 TXD1 RXD0 TXD0 nRTS0 nCTS0
    //Setting: IN      IN      IN   IN    IN    IN   OUT  RXD0 TXD0 OUT   IN
    //Binary : 00,     00      00,  00    00,   00   01,  10   10,  01    00
    //PU_OFF :  0       0       0,   1-ext 1-ext 1-ext 1, 1-ext 1    1     1-ext
    s2410IOP->rGPHDAT =0x030;//&=0x600; 
    s2410IOP->rGPHCON =0x155A55;//= 0x155555;//0x16faaa;
    s2410IOP->rGPHUP =0x0; //= 0x600;    // The pull up function is disabled GPH[10:0]

/*
#if 1
    s2410IOP->rGPHDAT = 0x0|(1<<6)|(1<<1)|(1<<4);    
    s2410IOP->rGPHCON = 0x0001a4; 		   //0x0011a4->0x0001a4 reduces 12uA why -> MAX3232C may sink 12uA.
#else
    //rGPHDAT = 0x0|(1<<6)|(1<<1)|(1<<4);  
    //rGPHCON = 0x0011a4; 
    s2410IOP->rGPHDAT = 0x0|(0<<6)|(1<<1)|(1<<4);  //(1<<6)->(0<<6) reduces 12uA (MAX3232C may sink 12uA.)
    s2410IOP->rGPHCON = 0x0011a4; 
#endif    
    s2410IOP->rGPHUP  = 0x0ff;    // The pull up function is disabled GPH[10:0]
*/
    
    //External interrupt will be falling edge triggered. 
    s2410IOP->rEXTINT0 = 0x22222222;    // EINT[7:0]
    s2410IOP->rEXTINT1 = 0x22222222;    // EINT[15:8]
    s2410IOP->rEXTINT2 = 0x22222222;    // EINT[23:16]
}

void ConfigMiscReg(void)
{
    volatile IOPreg *s2410IOP = (IOPreg *)IOP_BASE;
	volatile ADCreg *s2410ADC = (ADCreg *)ADC_BASE;
	volatile RTCreg *s2410RTC = (RTCreg *)RTC_BASE;

    s2410RTC->rRTCCON=0x0;   // R/W disable, 1/32768, Normal(merge), No reset
    s2410ADC->rADCCON|=(1<<2);		// ADC StanbyMode

    s2410IOP->rMISCCR|=(1<<12); //USB port0 = suspend
    s2410IOP->rMISCCR|=(1<<13); //USB port1 = suspend

    s2410IOP->rMISCCR|=(1<<2); //Previous state at STOP(?) mode (???)
    
    //D[31:0] pull-up off. The data bus will not be float by the external bus holder.
    //If the pull-up resitsers are turned on,
    //there will be the leakage current through the pull-up resister
    s2410IOP->rMISCCR=s2410IOP->rMISCCR|(3<<0); 
}


PRIVATE void 
CPULCDOff(void)
{
    volatile IOPreg *s2410IOP = (IOPreg *)IOP_BASE;
    volatile LCDreg *s2410LCD = (LCDreg *)LCD_BASE;    

    s2410IOP->rGPGDAT &= ~(1 << 4);

    s2410LCD->rLCDCON1   = 0;
    s2410LCD->rLCDCON2   = 0;
    s2410LCD->rLCDCON3   = 0;
    s2410LCD->rLCDCON4   = 0;
    s2410LCD->rLCDCON5   = 0;	
    s2410LCD->rLCDSADDR1 = 0;
    s2410LCD->rLCDSADDR2 = 0;
    s2410LCD->rLCDSADDR3 = 0;
    s2410LCD->rLPCSEL    = 0;
    s2410LCD->rTPAL      = 0;
}



PRIVATE void 
CPUClearCS8900(void)
{
    USHORT temp;

//	RETAILMSG(1,(TEXT("CPUClearCS8900 Enter\r\n")));        

    do 
    {
        temp = *((volatile USHORT *)(CS8900DBG_IOBASE + 8));
    } while (temp != 0);

//	RETAILMSG(1,(TEXT("CPUClearCS8900 Out\r\n")));        
}
VOID CFcardReset(void)
{
	volatile IOPreg *s2410IOP = (IOPreg *)IOP_BASE;
	volatile int i;
	s2410IOP->rGPEUP &= (1<<15);// =0xFFFF;//test displayer consume //
	s2410IOP->rGPECON &= ~(3<<30);		// =0x00000;//
	s2410IOP->rGPECON |=(1<<30);
	
/*	s2410IOP->rGPBCON  &= ~(0x3 << 6);
	
	s2410IOP->rEXTINT1 &= ~(0x7 << 12);		// Configure EINT11 as Falling Edge Mode	
   	s2410IOP->rEXTINT1 |=  (0x6 << 12);
	
	s2410IOP->rGPGUP   |=  (1 << 3);		// Disable pull-up.
	s2410IOP->rGPGCON  &= ~(0x3 << 6);		// Set EINT0(GPF0) as EINT0
	s2410IOP->rGPGCON  |=  (0x1 << 6);
	s2410IOP->rGPGDAT  |=0x04;
	
	for(i=0;i<10000;i++);
	s2410IOP->rGPGCON  &= ~(0x3 << 6);		// Set EINT0(GPF0) as EINT0	
	s2410IOP->rGPGCON  |=  (0x2 << 6);*/
	
	(s2410IOP->rGPEDAT) &= ~(1<<15);
	for(i=0;i<10000;i++);
	(s2410IOP->rGPEDAT) |= (1<<15);
}
VOID OEMPowerOff(void)
{
	volatile IOPreg *s2410IOP = (IOPreg *)IOP_BASE;
 	volatile INTreg *s2410INT = (INTreg *)INT_BASE;
	volatile LCDreg *s2410LCD = (LCDreg *)LCD_BASE;    
	int i;
//		LoadDspInfo();

    /* Save Current Important CPU Regs...   */
        CPUSaveRegs(CPUBackupRegs);

    /* LCD Controller Disable               */
        CPULCDOff();

	/* Stop all GPIO */
	ConfigStopGPIO();

	/* Set misc register for power off */
	ConfigMiscReg();

     
    /* Actual Power-Off Mode Entry          */
    
    
    CPUPowerOff();
    //s2410IOP->rGPFDAT |= (0x80) ;
    /* Recover Process, Load CPU Regs       */
    CPULoadRegs(CPUBackupRegs);
    //s2410IOP->rGPFDAT |= (0x80) ;
	/* Clear GSTATUS2 register : Write 1 to clear */
	
	s2410IOP->rGSTATUS2 = s2410IOP->rGSTATUS2;
    
    /* Interrupt Clear                      */
   s2410INT->rSUBSRCPND = s2410INT->rSUBSRCPND;   //061113xutao
   s2410LCD->rLCDSRCPND = s2410LCD->rLCDSRCPND;   //061113xutao
   s2410LCD->rLCDINTPND = s2410LCD->rLCDINTPND;   //061113xutao
   s2410INT->rSRCPND    = s2410INT->rSRCPND;      //061113xutao
   s2410INT->rINTPND    = s2410INT->rINTPND;      //061113xutao
   s2410IOP->rEINTPEND  = s2410IOP->rEINTPEND;    //061113xutao
	
		
    //OEMInitDebugSerial();   ////???????
    //RETAILMSG(1,(TEXT("\r\n OEMInitDebugSerial !!!! ")));  
    //RETAILMSG(1,(TEXT("\r\n cs8900 !!!! ")));
    //CPUClearCS8900();/////////////////////////////////// modify 9.28 13:56
        
	CFcardReset();
	for(i=0;i<1000000;i++);
	for(i=0;i<1000000;i++);
	for(i=0;i<1000000;i++);
	for(i=0;i<1000000;i++);
	for(i=0;i<1000000;i++);
	for(i=0;i<1000000;i++);
	
	//InitLcd();
//	ReDrawDsp();
        
        
	FMD_PowerUp();
	//RETAILMSG(1,(TEXT("s2410INT->rINTMOD = 0x%x \r\n"), s2410INT->rINTMOD));
	//RETAILMSG(1,(TEXT("s2410INT->rINTMSK = 0x%x \r\n"), s2410INT->rINTMSK));
       // s2410IOP->rGPFDAT = 0x00;/////////////////////
}

PUBLIC void 
OEMEmergencyPowerOff(void)
{
    volatile IOPreg *s2410IOP = (IOPreg *)IOP_BASE;
 	volatile INTreg *s2410INT = (INTreg *)INT_BASE;
    volatile LCDreg *s2410LCD = (LCDreg *)LCD_BASE;    
    volatile CLKPWRreg *s2410CLK = (CLKPWRreg *)CLKPWR_BASE;    
	
    /* Save Current Important CPU Regs...   */
//	CPUSaveRegs(CPUBackupRegs);

	s2410IOP->rGPFDAT = ~(0x1 << 4);   /* LED Off */
    /* LCD Controller Disable               */
    CPULCDOff();

	s2410IOP->rGPFDAT = ~(0x2 << 4);   /* LED Off */
	/* Stop all GPIO */
	ConfigStopGPIO();

	s2410IOP->rGPFDAT = ~(0x3 << 4);   /* LED Off */
	/* Set misc register for power off */
	ConfigMiscReg();

	s2410IOP->rGPFDAT = ~(0x4 << 4);   /* LED Off */
    /* Actual Power-Off Mode Entry          */

	EmergencyCPUPowerOff();
//	CPUPowerOff();
}


VOID OEMCPUPowerReset()
{
	volatile WATCHreg *WTimer = (WATCHreg *) WATCH_BASE;

	// Burst refresh with reading all SDRAM area.
	Burst_Refresh();

	// Mask F bit, I bit.
	CLR_IF();
	
	// Set watch dog reset. After this function, watch-dog reset will occure after 500ms.
	Watchdog_Set();

//	WTimer->rWTCON = ((PCLK/1000000-1) << 8) |		/* The prescaler value => 255 + 1	*/
//					 (0x00 << 6) |		/* Reserved							*/
//					 (0x01 << 5) |		/* Timer enable or disable			*/
//					 (0x03 << 3) |		/* The clock division factor => 16	*/
//					 (0x00 << 2) |		/* Disable bit of interrupt			*/
//					 (0x00 << 1) |		/* Reserved							*/
//					 (0x01 << 0);		/* Enable the reset function of timer */
//
//	while(1);

	// Set memory with self refresh and enable watchdog reset.
//	CPUPowerReset();
	CPUPowerWDReset();
}

#define	SDRAM_STARTADDRESS		0x30000000
#define	SDRAM_ENDADDRESS		0x33ffffff

void Burst_Refresh(void)
{
//	int i;

//	for(i=SDRAM_STARTADDRESS; i<SDRAM_ENDADDRESS; i+=8192) 	// Row addr is 13 bit.
//		*(U32 *) i;
}

void CLR_IF()
{
}

//================================================
// Watch-dog timer Interrupt Request Test
//================================================
extern volatile int isWdtInt;
#define	WATCHDOG_TIME	(128)	// [usec], Max=65535*128us.

void Watchdog_Set(void)
{
    volatile INTreg *s2410INT = (INTreg *)INT_BASE;
	volatile WATCHreg *WTimer = (WATCHreg *) WATCH_BASE;

	//t_watchdog = 1 / (PCLK / (Prescaler value + 1 ) / Division_factor)
	s2410INT->rINTMSK &= ~(BIT_WDT);		   //Watch dog Interrupt service is available
		
	WTimer->rWTCON = ((S2410PCLK/1000000-1) << 8) |		/* The prescaler value => 255 + 1	*/
					 (0x00 << 6) |		/* Reserved							*/
					 (0x00 << 5) |		/* Timer enable or disable			*/
					 (0x03 << 3) |		/* The clock division factor => 16	*/
					 (0x00 << 2) |		/* Disable bit of interrupt			*/
					 (0x00 << 1) |		/* Reserved							*/
					 (0x01 << 0);		/* Enable the reset function of timer */
	WTimer->rWTDAT = 0x1;
	WTimer->rWTCNT = 0x1;
	

//	WTimer->rWTCON = ((PCLK/1000000-1)<<8) | (3<<3) | (1);  //Prescaler=0x31(49),Clock division 128,Reset enable
	// 1*128 usec.

//	WTimer->rWTDAT = WATCHDOG_TIME/128;
//	WTimer->rWTCNT = WATCHDOG_TIME/128;		// (xsec/128us)
}

// End of Power Management 
//------------------------------------------------------------------------------


⌨️ 快捷键说明

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