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

📄 pwr_c.c

📁 2410开发测试程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************
	NAME: pwr_c.c
	DESC: 2410 power consumption measurement code
	HISTORY:
	04.09.2002:purnnamu: first release for 2410
 **********************************************/
 
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"

#include "mmu.h"

#include "lcdlib.h"

//Options for current measurement
#define QUICK_SORT		(1)
#define DHRYSTONE21		(2)
#define CPU_WORK		QUICK_SORT //DHRYSTONE21 //QUICK_SORT

#define DMA2_ON			(1)
#define UNUSED_BLCOK_ON	(1)

void PWR_Lcd_Tft_16Bit_240320_On(void);
static void Lcd_Port_Init(void);
void dhrystone21(void);
void PWR_StartTimer(void);
void StartDmaMem2Mem(void);
void PWR_StartIIS(void);
int compare1(const void *a,const void *b);
int compare2(const void *a,const void *b);

//static int dim[0x4000];	//64KB,which is bigger than D-Cache(16KB)

#define NUM_SORT_DATA	0x10000
static int dim2[NUM_SORT_DATA];	//128KB,which is bigger than D-Cache(16KB)

//#define TMP_FCLK	(237000000)
//#define TMP_FCLK	(226000000)
//#define TMP_FCLK	(214500000)
#define TMP_FCLK	(202800000)
//#define TMP_FCLK	(180000000)
//#define TMP_FCLK	(152000000)
//#define TMP_FCLK	(135000000)
//#define TMP_FCLK	(101250000)
//#define TMP_FCLK	( 50700000)

void MeasurePowerConsumption(void)
{
	int i;

	Uart_Printf("[Measure the power consumption of S3C2410]\n");
	Uart_Printf("FCLK is changed to %5.1lfMhz.\n",TMP_FCLK/1000000.);
	
	MMU_Init();
	ChangeClockDivider(1,1);		// 1:2:4	
#if TMP_FCLK==237000000
	ChangeMPllValue(150,2,1); // TMP_FCLK=237000000Hz	
	Uart_Init(237000000/4,115200);
#endif
#if TMP_FCLK==226000000
	ChangeMPllValue(105,1,1); // TMP_FCLK=226000000Hz	
	Uart_Init(226000000/4,115200);
#endif
#if TMP_FCLK==214500000
	ChangeMPllValue(135,2,1); // TMP_FCLK=214500000Hz	
	Uart_Init(214500000/4,115200);
#endif
#if TMP_FCLK==202800000	
	ChangeMPllValue(161,3,1); // TMP_FCLK=202800000Hz	
	Uart_Init(202800000/4,115200);
#endif	
#if TMP_FCLK==180000000	
	ChangeMPllValue(82,1,1);	// TMP_FCLK=180000000Hz	
	Uart_Init(180000000/4,115200);
#endif	
#if TMP_FCLK==152000000
	ChangeMPllValue(68,1,1);	// TMP_FCLK=152000000Hz	
	Uart_Init(152000000/4,115200);
#endif
#if TMP_FCLK==135000000
	ChangeMPllValue(82,2,1);	// FCLK=135000000Hz 
	Uart_Init(135000000/4,115200);
#endif
#if TMP_FCLK==101250000
	ChangeMPllValue(127,2,2);	// TMP_FCLK=101250000Hz	
	Uart_Init(101250000/4,115200);
#endif
#if TMP_FCLK==50700000
	ChangeMPllValue(161,3,3);	// TMP_FCLK=50700000Hz	
	Uart_Init(50700000/4,115200);
#endif

	rGPHCON = rGPHCON&~(3<<18|3<<20)|(1<<18|1<<20);	//GPH9:CLKOUT0->OUT,GPH10:CLKOUT1->OUT

	#if 0
	rGPHCON = rGPHCON&~(3<<18)|(2<<18); //CLKOUT0
	rMISCCR = rMISCCR&~(7<<4)|(4<<4);	//PCLK=45Mhz @FCLK=180Mhz
	#endif

	#if UNUSED_BLCOK_ON==0
	rCLKCON=rCLKCON&~(1<<18|1<<16|1<<12|1<<11|1<<9|1<<4); //SPI,IIC,UART1,2,SDI,NFC
	#endif

	#if DMA2_ON==1
	StartDmaMem2Mem();
	#endif 

	PWR_StartTimer();

	Uart_Printf("TFT-LCD 240x320 16bit is running.\n");
	Lcd_PowerEnable(0,1);
	PWR_Lcd_Tft_16Bit_240320_On();
	
	PWR_StartIIS();
	
#if CPU_WORK==QUICK_SORT
	Uart_Printf("CPU JOB:quick sort of 65536 intteger data.\n");
	//qsort;
	for(i=0;i<NUM_SORT_DATA;i++)dim2[i]=i;
	i=0;	
	while(1)
	{
		qsort(dim2,NUM_SORT_DATA,sizeof(int),compare1);
		qsort(dim2,NUM_SORT_DATA,sizeof(int),compare2);
		Uart_Printf(",");
	}
#else
	Uart_Printf("CPU JOB:Dhrystone 2.1 code.\n");
	while(1)
	{
		dhrystone21();
		Uart_Printf(".");
	}
#endif
	Uart_Printf("End of the Measurement\n");	
}

int compare1(const void *a,const void *b)
{
	if(*(int *)a>*(int *)b)
		return 1;
	else if(*(int *)a==*(int *)b)
		return 0;
	else 
		return -1;
}

int compare2(const void *a,const void *b)
{
	
	if(*(int *)a>*(int *)b)
		return -1;
	else if(*(int *)a==*(int *)b)
		return 0;
	else 
		return 1;
}

void DoQsort(void) //function for SLOW mode current current consumption
{
	qsort(dim2,NUM_SORT_DATA,sizeof(int),compare1);
	qsort(dim2,NUM_SORT_DATA,sizeof(int),compare2);
}

static unsigned save_rGPCUP,save_rGPCDAT,save_rGPCCON;
static unsigned save_rGPDUP,save_rGPDDAT,save_rGPDCON; 

static void Lcd_Port_Init(void)
{
	save_rGPCCON=rGPCCON;
	save_rGPCDAT=rGPCDAT;
	save_rGPCUP=rGPCUP;
	save_rGPDCON=rGPDCON;
	save_rGPDDAT=rGPDDAT;
	save_rGPDUP=rGPDUP;
	rGPCUP=0xffffffff;	// Disable Pull-up register
	rGPCCON=0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND 
	rGPDUP=0xffffffff;	// Disable Pull-up register
	rGPDCON=0xaaaaaaaa; //Initialize VD[23:8]
}

void PWR_Lcd_Tft_16Bit_240320_On(void)
{
	Lcd_Port_Init();
	//Lcd_Lpc3600Enable(); // Enable LPC3600
	Lcd_Init(MODE_TFT_16BIT_240320);
	Glib_Init(MODE_TFT_16BIT_240320);
	Lcd_EnvidOnOff(1);

	Glib_ClearScr(0, MODE_TFT_16BIT_240320);
	Glib_Rectangle(0,0,239,319,0x07e0);	
	Glib_FilledRectangle(0,0,20,20,65535);	
	Glib_Rectangle(220,300,239,319,65535);	
	Glib_Line(0,0,239,319,0x1f);		
	Glib_Line(239,0,0,319,0xf800);
	Uart_Printf("TFT 64K color mode test 2!\n");
}

void PWR_StartTimer(void)
{
	Uart_Printf("All 5 timers are running.\n");
	
	rTCFG0=0x8080;	//Prescaler=128; 
	rTCFG1=0x11111;	//Devider=1/4;
	rTCNTB0=0x8000;
	rTCMPB0=0x4000;
	rTCNTB1=0x8000;
	rTCMPB1=0x4000;
	rTCNTB2=0x8000;
	rTCMPB2=0x4000;
	rTCNTB3=0x8000;
	rTCMPB3=0x4000;
	rTCNTB4=0x8000;
	rTCON=0x6aaa0a; //manual update
	rTCON=0x599909; //run
}

static int buf1[1024],buf2[1024];

void __irq PWR_IsrDma0(void)
{
	ClearPending(BIT_DMA0);
	rDMASKTRIG0=0x3;	
	//Uart_Printf("$");
}

void StartDmaMem2Mem(void)
{
	Uart_Printf("seamless DMA0 SDRAM->SDRAM transfer is running.\n");
	
	pISR_DMA0=(unsigned int)PWR_IsrDma0;	
	rINTMSK=rINTMSK&~(BIT_DMA0);
 
	rDISRC0=(U32)buf1;
	rDISRCC0=(0<<1)|(0<<0); //src=AHB,increment
	rDIDST0=(U32)buf2;
	rDIDSTC0=(0<<1)|(0<<0); //dst=AHB,increment
	rDCON0=((U32)1<<31)|(1<<29)|(1<<27)|(2<<20)|(1024);
		//handshake,done int. enable,whole mode,DSZ=word,TC=1024
	rDMASKTRIG0=0x3;			
}	

static U16 buf3[4096];

void __irq PWR_IsrDma2(void)
{
	ClearPending(BIT_DMA2);
	//Uart_Printf("#");
}

void PWR_StartIIS(void)
{
	Uart_Printf("IIS(DMA2) is running(CDCLK=16.9Mhz,LRCK=44.1Khz).\n");

	pISR_DMA2=(unsigned int)PWR_IsrDma2;	
	rINTMSK=rINTMSK&~(BIT_DMA2);

	rGPECON=rGPECON&~(3<<8|3<<4|3<<2|3<<0)|(2<<8|2<<4|2<<2|2<<0); //I2SSDO,CDCLK,I2SSCLK,I2SLRCK
		
	rDISRC2=(U32)buf3; 
	rDISRCC2=(0<<1)+(0<<0);//src=AHB,increment
	rDIDST2=((U32) IISFIFO );
	rDIDSTC2=(1<<1)+(1<<0); //APB,fix
	rDCON2=((U32)1<<31)|(0<<30)|(1<<29)|(0<<28)|(0<<27)|(0<<24)|(1<<23)|(0<<22)|(1<<20)|(4096);
	//handshake, sync PCLK, TC int, single tx, single service, I2SSDO, I2S request, 
	//auto-reload, half-word,
	rDMASKTRIG2=(1<<1)+0;	//DMA2 channel on, no-sw trigger 

	rIISPSR=(2<<5)|(2<<0);	//IIS_LRCK=44.1Khz @384fs,PCLK=50Mhz.
	
	rIISCON=(1<<5)+(1<<2)+(1<<1);
	//Tx DMA enable,Rx idle,prescaler enable
	rIISMOD=(2<<6)|(1<<3)|(1<<2)|(1<<0);
	//Master,Tx,L-ch=low,iis,16bit ch.,CDCLK=384fs,IISCLK=32fs

	rIISFCON=(1<<15)+(1<<13);	//Tx DMA,Tx FIFO enable

	rIISCON |=0x1;
}

/***************************************************************************
 *
 *					"DHRYSTONE" Benchmark Program
 *					-----------------------------
 *																			
 *	Version:	C, Version 2.1
 *																			
 *	File:		dhry.h (part 1 of 3)
 *
 *	Date:		May 25, 1988
 *
 *	Author:	Reinhold P. Weicker
 *						Siemens AG, E STE 35
 *						Postfach 3240
 *						8520 Erlangen
 *						Germany (West)
 *								Phone:	[xxx-49]-9131-7-20330
 *										(8-17 Central European Time)
 *								Usenet: ..!mcvax!unido!estevax!weicker
 *
 *				Original Version (in Ada) published in
 *				"Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
 *				pp. 1013 - 1030, together with the statistics
 *				on which the distribution of statements etc. is based.
 *
 *				In this C version, the following C library functions are used:
 *				- strcpy, strcmp (inside the measurement loop)
 *				- printf, scanf (outside the measurement loop)
 *				In addition, Berkeley UNIX system calls "times ()" or "time ()"
 *				are used for execution time measurement. For measurements
 *				on other systems, these calls have to be changed.
 *
 *	Collection of Results:
 *				Reinhold Weicker (address see above) and
 *				
 *				Rick Richardson
 *				PC Research. Inc.
 *				94 Apple Orchard Drive
 *				Tinton Falls, NJ 07724
 *						Phone:	(201) 389-8963 (9-17 EST)				
 *						Usenet: ...!uunet!pcrat!rick
 *
 *		Please send results to Rick Richardson and/or Reinhold Weicker.
 *		Complete information should be given on hardware and software used.
 *		Hardware information includes: Machine type, CPU, type and size
 *		of caches; for microprocessors: clock frequency, memory speed
 *		(number of wait states).
 *		Software information includes: Compiler (and runtime library)
 *		manufacturer and version, compilation switches, OS version.
 *		The Operating System version may give an indication about the
 *		compiler; Dhrystone itself performs no OS calls in the measurement loop.
 *
 *		The complete output generated by the program should be mailed
 *		such that at least some checks for correctness can be made.
 *
 **************************************************************************/

/* Compiler and system dependent definitions: */

#define Mic_secs_Per_Second	1000000.0
				/* Berkeley UNIX C returns process times in seconds/HZ */

#ifdef	NOSTRUCTASSIGN
#define structassign(d, s)		memcpy(&(d), &(s), sizeof(d))
#else
#define structassign(d, s)		d = s
#endif

#ifdef	NOENUM
#define Ident_1 0
#define Ident_2 1
#define Ident_3 2
#define Ident_4 3
#define Ident_5 4
	typedef int	Enumeration;
#else
	typedef		enum	{Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
				Enumeration;
#endif
/* for boolean and enumeration types in Ada, Pascal */

/* General definitions: */

#include <stdio.h>
/* for strcpy, strcmp */

#define Null	0 

#define true	1
#define false	0

typedef int		One_Thirty;
typedef int		One_Fifty;

⌨️ 快捷键说明

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