📄 power.c
字号:
/***************************************************************
NAME: Power.c
DESC: Power mode test
HISTORY:
****************************************************************/
#include <stdlib.h>
#include "def.h"
#include "option.h"
#include "System.h"
#include "Console.h"
#include "2413addr.h"
#include "mmucache.h"
#include "power.h"
#include "syscon.h"
void ConfigSleepGPIO(void);
void ConfigStopGPIO(void);
void ConfigMiscIO_stop(void);
void Test_IdleMode(void);
void Test_StopMode(void);
void Test_SleepMode(void);
//void Test_PowerDownAll(void);
void * func_syscon_power[][2]=
{
// "0123456789012345678"
(void *)Test_IdleMode, "Idle Mode Test ",
(void *)Test_StopMode, "Stop Mode Test ",
(void *)Test_SleepMode, "Sleep Mode Test ",
0,0
};
void Test_Power(void)
{
int i;
printf("\nPower Mode Test.\n");
while(1)
{
i=0;
printf("\n\n");
while(1)
{ //display menu
printf("%2d:%s",i,func_syscon_power[i][1]);
i++;
if((int)(func_syscon_power[i][0])==0)
{
printf("\n");
break;
}
if((i%3)==0)
printf("\n");
}
printf("\nSelect (\"-1\" to exit) : ");
i = GetIntNum();
if(i==-1) break; // return.
if(i>=0 && (i<((sizeof(func_syscon_power)-1)/8)) ) // select and execute...
( (void (*)(void)) (func_syscon_power[i][0]) )();
}
printf("\nThe end of Test on Power Mode.\n");
}
//It's not implemented yet fully.
void Test_ExternalClock(void)
{
printf("[IDLE Mode Test]\n");
PreChangeSDRAMParameter();
}
void Test_IdleMode(void)
{
U32 i,j;
printf("\n[IDLE Mode Test]\n");
#ifdef DBGMSG
printf("Test pattern for SDRAM Self-Refresh is filled when CPU goes to Emergency Sleep via IDLE because of Battery Fault!\n");
#endif
for(i=0; i<14; i++)
for(j=0; j<1000; j++)
*(unsigned int *)(_NONCACHE_STARTADDRESS + i*0x100000 + j*4) = (_NONCACHE_STARTADDRESS + i*0x100000 + j*4)^0xa5a55a5a;
#ifdef DBGMSG
printf("Wake-up source is set!\n");
#endif
SetEintWakeup(EINTNUM0, FALLINGEDGE, FILTERENABLE);
//SetEintWakeup(EINTNUM1, FALLINGEDGE, FILTERENABLE);
//SetEintWakeup(EINTNUM2, FALLINGEDGE, FILTERENABLE);
SetEintWakeup(EINTNUM11, FALLINGEDGE, FILTERENABLE);
//SetBatteryFaultEvent(BATINT);
SetAlarmWakeup();
//SetTimeTickWakeup(1, 268);
#ifdef DBGMSG
printf("\nCPU will goes to IDLE Mode!\n\n");
#endif
Uart_TxEmpty(1);
// Entering the IDLE mode
//*************************//
rPWRCFG = (rPWRCFG & ~(0x3<<6))|(1<<6);
MMU_WaitForInterrupt();
rINTMSK=BIT_ALLMSK;
rINFORM0 = 0x0;
#ifdef DBGMSG
printf("Return to Normal Mode.\n");
#endif
}
void Test_StopMode(void)
{
U32 i,j;
U32 portStatus[33+3]; // +3 is for 2412 GPJ port.
int error=0;
int mode;
printf("\n[STOP Mode Test]\n");
#ifdef DBGMSG
printf("ADC is in stanby!\n");
#endif
rADCCON |=(1<<2); // ADC stanby.
rRTCCON = 0; // R/W Disable, 1/32768, Normal, No reset
#ifdef DBGMSG
printf("LCD is turned off!\n");
#endif
Lcd_EnvidOnOff(0); //Before entering Sleep mode, LCD must be off
// Save the port configurations
printf("I/O Port is stored!\n");
for(i=0;i<36;i++) {
portStatus[i]=*( (volatile U32 *)0x56000000 + i); // 0x5600_0000:GPACON addr.
}
#ifdef DBGMSG
printf("I/O Port is set for Stop Mode!\n");
#endif
ConfigStopGPIO();
ConfigMiscIO_stop();
#ifdef DBGMSG
printf("Test pattern for SDRAM Self-Refresh is filled!\n");
#endif
for(i=0; i<14; i++)
for(j=0; j<1000; j++)
*(unsigned int *)(_NONCACHE_STARTADDRESS + i*0x100000 + j*4) = (_NONCACHE_STARTADDRESS + i*0x100000 + j*4)^0xa5a55a5a;
#ifdef DBGMSG
printf("Any unintentional interrupt is cleared!\n");
#endif
rEINTMASK = 0xffffff;
rINTMSK = 0xffffffff;
rEINTPEND = 0xffffff;
rSRCPND = 0xffffffff;
rINTPND = rINTPND;
#ifdef DBGMSG
printf("Oscillator settle-down time is set\n");
#endif
rOSCSET = 0x8000;
#ifdef DBGMSG
printf("Wake-up source is set!\n");
#endif
SetEintWakeup(EINTNUM0, FALLINGEDGE, FILTERENABLE);
//SetEintWakeup(EINTNUM1, FALLINGEDGE, FILTERENABLE);
//SetEintWakeup(EINTNUM2, FALLINGEDGE, FILTERENABLE);
SetEintWakeup(EINTNUM11, FALLINGEDGE, FILTERENABLE);
//SetBatteryFaultEvent(BATINT);
SetAlarmWakeup();
//SetTimeTickWakeup(1, 268);
#ifdef DBGMSG
printf("\nCPU will goes to Stop Mode!\n\n");
#endif
Uart_TxEmpty(1);
// Entering the STOP mode
//*************************//
rPWRCFG = (rPWRCFG & ~(0x3<<6))|(2<<6);
MMU_WaitForInterrupt();
#ifdef DBGMSG
//Restore the port configurations
printf("\nI/O Port is restored!\n");
#endif
for(i=0;i<36;i++){
*( (volatile U32 *)0x56000000 + i)=portStatus[i];
}
error=0;
for(i=0; i<14; i++)
for(j=0; j<1000; j++)
if((*(unsigned int *)(_NONCACHE_STARTADDRESS + i*0x100000 + j*4)) != ((_NONCACHE_STARTADDRESS + i*0x100000 + j*4)^0xa5a55a5a))
error=1;
if(error != 1)
{
;
#ifdef DBGMSG
printf("SDRAM Self-Refresh is OK!\n");
#endif
}
else
{
printf("SDRAM Self-Refresh is Fail!\n");
while(1);
}
rINTMSK =BIT_ALLMSK;
Led_Display(0xa);
Lcd_EnvidOnOff(1);
rINFORM0 = 0x0;
#ifdef DBGMSG
printf("Return to Normal Mode.\n");
#endif
}
void Test_SleepMode(void)
{
U32 i,j;
U32 portStatus[33+3]; // +3 is for 2412 GPJ port.
int error=0;
int mode;
printf("\n[SLEEP Mode Test]\n");
#ifdef DBGMSG
printf("ADC is in stanby!\n");
#endif
rADCCON |=(1<<2); // ADC stanby.
rRTCCON = 0; // R/W Disable, 1/32768, Normal, No reset
#ifdef DBGMSG
printf("LCD is turned off!\n");
#endif
Lcd_EnvidOnOff(0); //Before entering Sleep mode, LCD must be off
// Save the port configurations
#ifdef DBGMSG
printf("I/O Port is stored!\n");
#endif
for(i=0;i<36;i++) {
portStatus[i]=*( (volatile U32 *)0x56000000 + i); // 0x5600_0000:GPACON addr.
}
#ifdef DBGMSG
printf("I/O Port is set for Sleep Mode!\n");
#endif
ConfigSleepGPIO();
#ifdef DBGMSG
printf("Test pattern for SDRAM Self-Refresh is filled!\n");
#endif
for(i=0; i<14; i++)
for(j=0; j<1000; j++)
*(unsigned int *)(_NONCACHE_STARTADDRESS + i*0x100000 + j*4) = (_NONCACHE_STARTADDRESS + i*0x100000 + j*4)^0xa5a55a5a;
#ifdef DBGMSG
printf("Any unintentional interrupt is cleared!\n");
#endif
rEINTMASK = 0xffffff;
rINTMSK = 0xffffffff;
rEINTPEND = 0xffffff;
rSRCPND = 0xffffffff;
rINTPND = rINTPND;
#ifdef DBGMSG
printf("Reset Count Value is set!\n");
#endif
rRSTCON |= (16);
#ifdef DBGMSG
printf("Wake-up source is set!\n");
#endif
SetEintWakeup(EINTNUM0, FALLINGEDGE, FILTERDISABLE);
//SetEintWakeup(EINTNUM1, FALLINGEDGE, FILTERENABLE);
//SetEintWakeup(EINTNUM2, FALLINGEDGE, FILTERENABLE);
SetEintWakeup(EINTNUM11, FALLINGEDGE, FILTERDISABLE);
SetAlarmWakeup();
//SetTimeTickWakeup(1, 268);
#ifdef DBGMSG
printf("Inform register is set!\n");
#endif
rINFORM0 = 0x2BED2BED;
#ifdef DBGMSG
printf("\nCPU will goes to Sleep Mode!\n\n");
#endif
Uart_TxEmpty(1);
// Entering the STOP mode
//*************************//
rPWRCFG = (rPWRCFG & ~(0x3<<6))|(3<<6);
MMU_WaitForInterrupt();
printf("CPU doesn't go to Sleep Mode\n");
}
void Test_SleepModeRepeatEXT(void)
{
rCLKSRC &= ~(1<<4);
rUCON1 = 0xe45;
rUBRDIV1 = 0x5;
rUDIVSLOT1 = 0xff;
rINFORM3 = 0xaeaeaeae;
Test_SleepMode();
}
void Test_PowerDownAll(void)
{
U32 PowerDownRandom;
printf("All Power Down Mode Test\n");
rINFORM3 = 0x5a5a5a5a;
//rGSTATUS5 = rGSTATUS5+1;
//if(rGSTATUS5 == 0xffffffff) rGSTATUS5 = 0;
//printf("Random Seed:%d\n", rGSTATUS5);
//srand(rGSTATUS5);
while(1)
{
PowerDownRandom = (rand()%3);
switch(PowerDownRandom)
{
case 0:
Test_IdleMode();
break;
case 1:
Test_StopMode();
break;
case 2:
Test_SleepMode();
break;
default:
break;
}
}
}
void ConfigSleepGPIO(void)
{
rGPADAT = 0x00000;
rGPACON = 0x7fffff;
//rMSTCON = 0x7c7fd;
//rMSLCON = ((3<<28)|(2<<26)|(2<<24)|(3<<22)|(0<<21)|(3<<16)|(0xf<<14)|(3<<10)|(3<<8)|(3<<6)|(3<<4)|(2<<2)|(2<<0));
//rMSLCON = ((3<<6)); // nGCS goes to HIgh or Hi-Z, oh
rMSLCON = ((0<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(0<<4)|(0<<2)|(0)); //modified by boaz.kim 060124
//printf("\nrGPACON=%x rGPADAT=%x\n", rGPACON, rGPADAT);
rGPBSLPCON = 0x3febfe;
rGPCSLPCON = 0xffffffff;
rGPDSLPCON = 0xffc0fffb;
rGPESLPCON = 0xa02aafbf;
rGPFDAT = 0xfa;
rGPFCON = 0x5502;
rGPFDN = 0xfd;//0xf1;
rGPGSLPCON = 0xfaef03bf;
rGPHSLPCON = 0x02ddd7;
//rGPJSLPCON = 0x3eaaaaa;
rGPJSLPCON = 0x3ffffff; //2411, 2412
}
void ConfigStopGPIO(void)
{
// Check point
// *** There must not be input floating pins
// Check point
// 1) NC pin: input pull-DN on
// 2) If input is driver externally: input pull-DN off
// 3) If a connected component draws some current: output low.
// 4) If a connected component draws no current: output high.
// Follow the configuration order for setting the ports.
// 1) setting value(GPnDAT)
// 2) setting control register (GPnCON)
// 3) configure pull-DN resistor(GPnDN)
//CAUTION: Below configurations are only for SMDK2442 eva. board
//*** PORT A GRODN
// [22:nFCE] [21:nRSTOUT] [20:nFRE] [19:nFWE] [18:ALE] [17:CLE] [16:nGCS5]
// [15:nGCS4] [14:nGCS3] [13:nGCS2] [12:nGCS1] [11:ADR26] [10:ADR25] [9:ADR24] [8:ADR23]
// [7:ADR22] [6:ADR21] [5:ADR20] [4:ADR19] [3:ADR18] [2:ADR17] [1:ADR16] [0:ADR0]
rGPADAT = 0x00000; // original by oh
//rGPACON = 0x5fffff; //original by oh
rGPACON = 0x7fffff; //modified by boaz.kim 060118
//rGPACON = 0x78ffff; //modified by boaz.kim 060124
//rMSTCON = 0x7c7fd; // original by oh
//rMSTCON = 0x0; // modified by boaz.kim 060118, 43uA
//rMSTCON = 0xf; // modified by boaz.kim 060118, 42uA
//rMSTCON = 0xc; // modified by boaz.kim 060118, 43uA
//rMSTCON = (0xf<<14|0x3<<2); // 2uA floating
//rMSTCON = 0x3<<2; // 30~48uA
rMSTCON = (0x3<<2);
//rMSTCON = (0);
// rMSTCON = 0x6;
//printf("\nrGPACON=%x rGPADAT=%x\n", rGPACON, rGPADAT);
//*** PORT B GRODN
// [10:74LV00 Input] [9:nXDACK0] [8:74LVC573_LE]
// [7:74LVC573_d5] [6:nSS_KBD] [5:nDIS_OFF] [4:L3CLOCK] [3:L3DATA] [2:L3MODE] [1:nIrDATXDEN] [0:Keyboard]
// * nXDREQ0/1:ext.pD, nSS_KBD:ext.pU, nDIS_OFF:ext.pD, nIrDATXDEN:ext.pU, Keyboard:ext.pU
rGPBDAT = 0x29f;
rGPBCON = 0x0; //all input
rGPBDN = (1<<0)+(1<<5)+(1<<6);//0x061;
//printf("rGPBCON=%x rGPBDAT=%x rGPBDN=%x\n", rGPBCON, rGPBDAT, rGPBDN);
//*** PORT C GRODN
// [15:VD7] [14:VD6] [13:VD5] [12:VD4] [11:VD3] [10:VD2] [9:VD1] [8:VD0]
// [7:LCD_LPCREVB] [6:LCD_LPCREV] [5:LCD_LPCOE] [4:VM] [3:VFRAME] [2:VLINE] [1:VCLK] [0:LEND]
// * LCD_LPCREV and LCD_LPCREVB are connected the analog circuit in LCD or board. So, this signal should be output L.
//rGPCDAT = 0x0;
rGPCDAT = 0xff3f;
rGPCCON = 0;
rGPCDN = 0;
// printf("rGPCCON=%x rGPCDAT=%x rGPCDN=%x\n", rGPCCON, rGPCDAT, rGPCDN);
//*** PORT D GRODN
// [15:VD23] [14:VD22] [13:VD21] [12:VD20] [11:VD19] [10:VD18] [9:VD17] [8:VD16]
// [7:VD15] [6:VD14] [5:VD13] [4:VD12] [3:VD11] [2:VD10] [1:VD9] [0:VD8]
// * 5V tol. pad(GPD[10:8]) should be output L
// * The input of Maxim IC may have current sink, so the port should have configured output 'H'(GPD0)
// * The output of Maxim IC drives 'H', so disable the pull-DN(GPD1)
//rGPDDAT = (1<<0);//0x1;
rGPDDAT = 0xf8fd;
rGPDCON = (1<<20)+(1<<18)+(1<<16)+(0<<0);//0x150001;
rGPDDN = (1<<10)+(1<<9)+(1<<8)+(1<<1);//0x702;
//printf("rGPDCON=%x rGPDDAT=%x rGPDDN=%x\n", rGPDCON, rGPDDAT, rGPDDN);
//*** PORT E GRODN
// [15:IICSDA] [14:IICSCL] [13:SPICLK] [12:SPIMOSI] [11:SPIMISO] [10:SDATA3] [9:SDDATA2] [8:SDDATA1]
// [7:SDDATA0] [6:SDCMD] [5:SDCLK] [4:I2SSDO] [3:I2SSDI] [2:CDCLK] [1:I2SSCLK] [0:I2SLRCK]
// * 5V tol. pad(GPE[13:11]) should be output L
// * The output of CODEC IC drives 'H', so disable the pull-DN
// * IICSDA/IICSCL:ext pU, SDDAT[3:0]/SDCMD:ext pU
// rGPEDAT = 0x0;
rGPEDAT = 0xc7ff;
rGPECON = 0x5400000;
rGPEDN = 0xffc8;
//printf("rGPECON=%x rGPEDAT=%x rGPEDN=%x\n", rGPECON, rGPEDAT, rGPEDN);
//*** PORT F GRODN
// [7:nLED_8] [6:nLED_4] [5:nLED_2] [4:nLED_1] [3:Onenand rst] [2:usbcon] [1:KBDINT] [0:EINT0]
// * GPF[7:4] are connected to 'H' through LED, so make output 'H'
// * nIRQ_PCMCIA=Hi-Z Before initialize
// * EINT0 is the wake-DN source
// * EINT2/0:ext pU, KBDINT:Keyboard controller drives high
//rGPFDAT = (0xf<<4);//0xf0;
rGPFDAT = 0xfa;
rGPFCON = 0x5502;
rGPFDN = 0xfd;//0xf1;
//printf("rGPFCON=%x rGPFDAT=%x rGPFDN=%x\n", rGPFCON, rGPFDAT, rGPFDN);
// If CPU Board is rev0.19, The EINT20 is used for USB control signal(Changed to output low, pu-disable)
//*** PORT G GRODN
// [15:EINT23] [14:EINT22] [13:EINT21] [12:GPIO out] [11:EINT19] [10:nCD_SD] [9:DMAMODE] [8:DMASTART]
// [7:KBDSPICLK] [6:KBDSPIMOSI] [5:KBDSPIMISO] [4:LCD_PWREN] [3:EINT11] [2:nSS_SPI] [1:IRQ_LAN] [0:IRQ_PCMCIA]
// * 5V tol. pad(GPG[13:11]) should be output L
// * GPG[15:13]:NAND boot config, EINT19:ext pU, nCD_SD:ext pU, EINT11:ext pU
// * The input of Maxim IC may have current sink, so the port should have configured output 'H'(GPG9)
// * The output of Maxim IC drives 'H', so disable the pull-DN(GPG10)
rGPGDAT = 0x0f1f;
rGPGCON = 0x00005400;
rGPGDN = 0x34e8;
//*** PORT H GRODN
// [10:CLKOUT1] [9:CLKOUT0] [8:UCLK]
// [7:nCTS1] [6:nRTS1] [5:RXD1] [4:TXD1] [3:RXD0] [2:TXD0] [1:nRTS0] [0:nCTS0]
// * WP_SP:ext pU
// * The input of Maxim IC may have current sink, so the port should have configured output 'H'(GPH4/2/1)
// * The output of Maxim IC drives 'H', so disable the pull-DN(GPH5/3/0)
rGPHDAT =0x056;
rGPHCON = 0x14aaaa;
rGPHDN =0x756;
//
//*** PORT J GRODN
// [12:CAMRESET] [11:CAMCLKOUT] [10:CAMHREF] [9:CAMVS] [8:CAMPCLKIN]
// [7:CAMD7] [6:CAMD6] [5:CAMD5] [4:CAMD4] [3:CAMD3] [2:CAMD2] [1:CAMD1] [0:CAMD0]
// * The output of buffer IC drives 'H', so disable the pull-DN(GPJ[10:0])
//rGPJDAT = 0x0;
rGPJDAT = 0x1800;
rGPJCON = 0x0; // all input
//rGPJDN = 0x7ff; //2413
rGPJDN = 0x0; //2411, 2412
//printf("rGPJCON=%x rGPJDAT=%x rGPJDN=%x\n\n", rGPJCON, rGPJDAT, rGPJDN);
//External interrDNt will be falling edge triggered.
//rEXTINT0 = 0x22222222; // EINT[7:0] //boaz.kim 060107
rEXTINT1 = 0x22222222; // EINT[15:8]
rEXTINT2 = 0x22222222; // EINT[23:16]
}
volatile unsigned int mslcon_bakup,mslcon_bakup2;
void ConfigMiscIO_stop(void)
{
rMISCCR = (1<<13)|(1<<12);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -