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

📄 power.c

📁 支持三星原产的S3C24A0开发板
💻 C
字号:
/*****************************************
 NAME: POWER.C
 DESC: Dialogue, slow, hold mode test
 HISTORY:
 2004.01.15 : ver 0.0
******************************************/

#include "def.h"
#include "option.h"
#include "24a0addr.h"
#include "24a0lib.h"
#include "24a0slib.h"
#include "lcdlib.h"

#include "power.h"
#include "idle.h"
#include "pll.h"
#include "stop.h"
#include "sleep.h" 
#include "pwr_c.h"

void __irq SlowEint0Int(void);

volatile int slowExit;

void * func_power_test[][2]=
{	
    //        				"123456789012345678"
    //Clock test
    (void *)Test_PLL,			"PLL change test   ",
    (void *)ChangePLL,			"PLL change(manual)",
    (void *)Test_PllOnOff,		"PLL On/Off test   ",	

    //Power mode test
    (void *)Test_SlowMode,		"Slow mode test    ",
    (void *)Test_HoldMode,		"Hold mode test    ",
    (void *)Test_IdleMode,		"Idle mode test    ",
    (void *)Test_MMUIdleMode,		"Idle mode(MMU)    ",
    (void *)Test_IdleModeHard,		"Idle hard test    ",
    (void *)Test_StopMode,		"Stop mode test    ",
    (void *)Test_SleepMode,		"Sleep mode test   ",
    (void *)MeasurePowerConsumption,	"Power consumption ",

    //Various reset test
    (void *)Test_SoftReset,		"Soft Reset        ",
    (void *)Test_WarmReset,		"Warm Reset        ",
    (void *)Test_WDTReset,		"Watch-dog Reset   ",
    (void *)Test_BattFault,	   	"Batt_FLT          ",
    (void *)Test_BattFaultInterrupt,    "Batt_FLT_Interrupt",
    0,0
};

void Ch33_Power_Test(void)
{
    int i;
	    
    Uart_Printf("\nPower mode test.\n");

    while(1)
    {
	i=0;
	Uart_Printf("\n\n");
	while(1)
	{   //display menu
	    Uart_Printf("%2d:%s",i,func_power_test[i][1]);
	    i++;
	    if((int)(func_power_test[i][0])==0)
	    {
		Uart_Printf("\n");
		break;
	    }
	    if((i%3)==0)
	    Uart_Printf("\n");
	}

	Uart_Printf("\nSelect (\"-1\" to exit) : ");
	i = Uart_GetIntNum();
	if(i==-1) 
	    break;		// return.
	if(i>=0 && (i<((sizeof(func_power_test)-1)/8)) )	// select and execute...
	    ( (void (*)(void)) (func_power_test[i][0]) )();
    }
    Uart_Printf("\nPower_Test program end.\n");
}

void Test_SlowMode(void)
{
    int i;
    unsigned int saveLCD;
    unsigned int saveREFRESH;

    slowExit=0;
    saveREFRESH=rSDRAM_REFRESH;
    saveLCD=rLCDCON1;

    rGPCON_L=( rGPCON_L & ~(3<<0) ) |(2<<0);	//GP0=EINT0
    rEXTINTC0=( rEXTINTC0 & ~(7<<0) ) |(2<<0);	//EINT0=falling edge triggered

    pISR_EINT0_2=(U32)SlowEint0Int;
    ClearPending(BIT_EINT0_2);
    rEINTPEND=BIT_EINTPEND_EINT0;
    rEINTMASK=~BIT_EINTPEND_EINT0;
    rINTMSK=~BIT_EINT0_2;

    Uart_Printf("[SLOW MODE TEST]\n");
    Uart_Printf("  1. LEDs are flickered by 200ms period at %dMhz 20 times.\n",FCLK/1000000);
    Uart_Printf("  2. Entering SLOW mode.\n");
    Uart_Printf("  3. LEDs are flickered by %fms period at %dMhz until......\n",(float)(200*FCLK/FIN), FCLK/1000000);
    Uart_Printf("  4. Press EINT0 key to exit SLOW mode\n");
    Uart_TxEmpty(0);	//To avoid being crushed the character

    for(i=0;i<20;i++)
    {
	Led_Display(0x0);
	Delay(1000);
	Led_Display(0xf);
	Delay(1000);
    }

    rCLKSRC=(0<<8)|(0<<7)|(1<<5)|(1<<4)|(0); // OnOSC_EN disable,U_PLL on,M_PLL off,External clk,Divider=0

    rSDRAM_REFRESH=7.8*(FIN/1000000); // Period= 7.8us
    //The other memory control register should be optimized for SLOW mode.

    rLCDCON1&=0xffffffe; // Disable Video output and control signal
    rLCDCON1=(rLCDCON1 & ~(0x3ff<<8) ) |(1<<0); //Change CLKVAL & Enable ENVID bit

    while(!slowExit)
    {
	Led_Display(0x0);
	Delay(1000);
	Led_Display(0xf);
	Delay(1000);
    }
	
    rCLKSRC=(0<<8)|(0<<7)|(0<<5)|(1<<4)|(0); // OnOSC_EN disable,U_PLL on,M_PLL on,External clk,Divider=0
    for(i=0;i<2048;i++); //S/W MPLL lock-time
    rLCDCON1=saveLCD;
    rSDRAM_REFRESH=saveREFRESH;
    rCLKSRC=(0<<8)|(0<<7)|(0<<5)|(0<<4)|(0); // OnOSC_EN disable,U_PLL on,M_PLL on,MPLL_clk,Divider=0
}

void __irq SlowEint0Int(void)
{
    rINTMSK=BIT_ALLMSK;
    rEINTMASK=BIT_EINTPEND_ALLMSK;
    rEINTPEND=BIT_EINTPEND_EINT0;
    ClearPending(BIT_EINT0_2);
    slowExit=1;
}


void Test_HoldMode(void)
{
  
    Uart_Printf("[Power Saving Mode by Stopping Each Block]\n");
    Uart_Printf("LCD ENVID is turned off.\n");
    LcdEnvidOnOff(0);
    Uart_Printf("Check the current cunsumption. Type any key to proceed.\n");	
    //Except GPIO,UART0
    rCLKCON=0x3fffff0;
    Uart_Getch();

    Uart_Printf("IrDA off.\n");
    rCLKCON&=~(1<<4);
    Uart_Getch();

    Uart_Printf("External AHB off.\n");
    rCLKCON&=~(1<<5);
    Uart_Getch();

    Uart_Printf("AC97 off.\n");
    rCLKCON&=~(1<<6);
    Uart_Getch();

    Uart_Printf("USB host off(DP0/DN0 is suspended).\n");
    rCLKCON&=~(1<<7);
    //rMISCCR|=(1<<12); //USB port0 = suspend
    Uart_Getch();
    
    Uart_Printf("PWM Timer off.\n");
    rCLKCON&=~(1<<8);
    Uart_Getch();

    /* UART0 is a message port */
    
    Uart_Printf("UART1 off.\n");
    rCLKCON&=~(1<<10);
    Uart_Getch();

    Uart_Printf("SPI off.\n");
    rCLKCON&=~(1<<11);
    Uart_Getch();
    
    Uart_Printf("IIC off.\n");
    rCLKCON&=~(1<<12);
    Uart_Getch();
    
    Uart_Printf("IIS off.\n");
    rCLKCON&=~(1<<13);
    Uart_Getch();
    
    Uart_Printf("USB device off(DP1/DN1 is also suspended).\n");
    rCLKCON&=~(1<<15);
    //rMISCCR|=(1<<13); //USB port1 = suspend
    Uart_Getch();

    Uart_Printf("MemoryStick off.\n");
    rCLKCON&=~(1<<16);
    Uart_Getch();
    
    Uart_Printf("SD off.\n");
    rCLKCON&=~(1<<17);
    Uart_Getch();

    Uart_Printf("ADC off.\n");
    rADCCON|=(1<<2);
    rCLKCON&=~(1<<18);
    Uart_Getch();
    
    Uart_Printf("Keypad off.\n");
    rCLKCON&=~(1<<19);
    Uart_Getch();

    Uart_Printf("MPEG4 off.\n");
    rCLKCON&=~(1<<20);
    Uart_Getch();

    Uart_Printf("Camera I/F off.\n");
    rCLKCON&=~(1<<21);
    Uart_Getch();

    Uart_Printf("LCD off.\n");
    rCLKCON&=~(1<<22);
    Uart_Getch();
    
    Uart_Printf("Camera off.\n");
    rCLKCON&=~(1<<23);
    Uart_Getch();

    Uart_Printf("MPEG4 I/F off.\n");
    rCLKCON&=~(1<<24);
    Uart_Getch();

    Uart_Printf("VPost off.\n");
    rCLKCON&=~(1<<25);
    Uart_Getch();
    
    Uart_Printf("Return to Normal Mode.\n");	    
    rCLKCON=0x3fffff0;
    rADCCON&=(1<<2);
    //rMISCCR&=~((1<<12)|(1<<13)); //USB port0,1 = normal
    LcdEnvidOnOff(1);
}

⌨️ 快捷键说明

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