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

📄 timer_test.c

📁 s3c6400 ADS下官方测试程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************************
* 
*	Project Name : S3C6400 Validation
*
*	Copyright 2006 by Samsung Electronics, Inc.
*	All rights reserved.
*
*	Project Description :
*		This software is only for validating functions of the S3C6400.
*		Anybody can use this software without our permission.
*  
*--------------------------------------------------------------------------------------
* 
*	File Name : Timer_test.c
*  
*	File Description : This file implements the API functons for Timer (PWM, WDT) test.
*
*	Author : Woojin.Kim
*	Dept. : AP Development Team
*	Created Date : 2006/12/27
*	Version : 0.1 
* 
*	History
*	- Created(Woojin.Kim 2006/12/27)
*     - Added more test function ( Prescaler,MUX234) (Woojin.Kim 2007/02/12)
*  
**************************************************************************************/


/* Include Files */

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "timer.h"
#include "def.h"
#include "option.h"
#include "library.h"
#include "sfr6400.h"
#include "system.h"
#include "sysc.h"
#include "intc.h"
#include "gpio.h"
#include "dma.h"


	extern volatile u32 g_uIntCounter0;
	extern volatile u32 g_uIntCounter1;
	extern volatile u32 g_uIntCounter2;
	extern volatile u32 g_uIntCounter3;
	extern volatile u32 g_uIntCounter4;
	extern volatile u32 g_uIntCounterWT;
	extern volatile u32 g_PWMDmaDone;
	static DMAC oPWMDmac;
	
void DelayfrTimer_Test(void);
void Timer_Test(void);
void TIMER_UserSelect(void);
void TIMER_Setting(void);
void TIMER_Int(void);
void TIMER_Prescaler1(void);
void TIMER_MUX234(void);
void TIMER_Dma(void);
void WDT_IntReq(void);
void WDT_Reset(void);
void StartandStopTimer_Test(void);


const testFuncMenu g_aTIMERTestFunc[] =
{	

	TIMER_UserSelect,				"Timer User's Configure",
	TIMER_Setting,				"Timer Normal    ",
	TIMER_Int,					"Timer Interrupt ",
	TIMER_Prescaler1,				"Prescaler 1 test",
	TIMER_MUX234,				"MUX 2,3,4 test",
	TIMER_Dma,				"Timer DMA       ",
	WDT_IntReq,					"WDT Interrupt   ",
	WDT_Reset,					"WDT Reset       ",
	DelayfrTimer_Test,			"Delay Function ",
	StartandStopTimer_Test,		"StartandStop test",
	0,0
};


void Timer_Test(void)
{
	u32 uCountFunc=0;
	s32 iSel=0;




	
	while(1)
	{

	printf("\n\n================== Timer Function Test =====================\n\n");

		for (uCountFunc=0; (u32)(g_aTIMERTestFunc[uCountFunc].desc)!=0; uCountFunc++)
			printf("%2d: %s\n", uCountFunc, g_aTIMERTestFunc[uCountFunc].desc);

		printf("\nSelect the function to test : ");
		iSel =GetIntNum();
		printf("\n");
		if(iSel == -1) 
			break;

		if (iSel>=0 && iSel<(sizeof(g_aTIMERTestFunc)/8-1))
			(g_aTIMERTestFunc[iSel].func) ();
	}
}	


////////////
// File Name : TIMER_UserSelect
// File Description : Check Timer setting individually
// Input : user select
// Output : pulse through TOUT[0],[1] pin on B'd
// Version : 
void TIMER_UserSelect(void)
{


	PWM_UserSelect();
	
}

////////////
// File Name : TIMER_Setting
// File Description : Check Timer function which is 'Prescaler' 'Divider' 'TCNTB&TCMPB' 'Inverter' 'Deadzone'
// Input : user select
// Output : pulse through TOUT[0],[1] pin on B'd
// Version : 
void TIMER_Setting(void)
{
	float fTimerclk;
	float fTimerfreq;
	s32 sTimer;
	u32 uSelect;
	u32 uCount;
	u32 uTCNTB;
	u32 uTCMPB;
	u32 uTemp;

while(1)
{

	printf("[ Timer Test Setting ]\n");	
	printf(" Select Timer [0~4] :");
	sTimer = GetIntNum();
	if ( sTimer ==-1)
		{
			printf("\n");
			break;
		}
	else

		GPIO_SetFunctionEach(eGPIO_F,eGPIO_13,2);		//PWM Ext
		GPIO_SetFunctionEach(eGPIO_F,eGPIO_14,2);		//PWM Tout0
		GPIO_SetFunctionEach(eGPIO_F,eGPIO_15,2);		//PWM Tout1
	
		printf("\n");

	while(1)
		{
		printf("What do you want to check?\n");
		printf("0.Prescaler Value	1. Divider Value	2. TCNTB & TCMPB\n");
		printf("3.Inverter		4. Deadzone		5. Clear all timers\n");
		printf("[0~4] :");
		uSelect = GetIntNum();

		switch(uSelect)
			{
				case 0:
					uCount = 1;
					while(uCount<256)
						{
						PWM_Select(sTimer,uCount,0,2000,1000,0,0,0,1,0,0);					

						printf("Timer = %d\n",sTimer);
						printf("nPCLK = %d , uPrescaler = %d, uDivider = %d dd= %d\n",g_PCLK,uCount,0,(1<<(0)));
						fTimerclk = (1/(float)((float)g_PCLK/((float)uCount)/(1<<(0))))*2000*1000;
						fTimerfreq = 1/fTimerclk;
						printf("Timer Clock = %f msec , Timer Frequency = %f Khz\n\n",fTimerclk,fTimerfreq);

						
						uCount = uCount +1;
						printf("Check PWM out (by Pinout)!\n");

						
						UART_Getc();
						}

					break;

				case 1:
					uCount = 0;
					while(uCount <5)
						{

						PWM_Select(sTimer,1,uCount,2000,1000,0,0,0,1,0,0);		

						printf("Timer = %d\n",sTimer);
						printf("nPCLK = %d , uPrescaler = %d, uDivider = %d \n",g_PCLK,1,(1<<(uCount)));

						fTimerclk = (1/(float)((float)g_PCLK/((float)1)/(1<<(uCount))))*2000*1000;
						fTimerfreq = 1/fTimerclk;
						printf("Timer Clock = %f msec , Timer Frequency = %f Khz\n\n",fTimerclk,fTimerfreq);
						
						uCount = uCount + 1;
						printf("Check PWM out (by Pinout)! \n");

						UART_Getc();
						}
					break;

				case 2:
					printf("Select TCNTB value set mode \n");
					printf("1. Lower than half of 2^31         2.above half of 2^31      : ");
					uTemp = GetIntNum();
					printf("\n");

					if (uTemp == 2)
						{
						printf("Select TCNTB \n");
						printf("1. 2^31(max)     2. 3/4 of Max   3.half of Max           :");
						uTemp = GetIntNum();
						if( uTemp == 2)
							{
							uTCNTB = 0xffffffff;
							uTCNTB =(u32)((u32)(uTCNTB/4)*3);
							}
						else if (uTemp == 3)
							{
							uTCNTB = 0xffffffff;
							uTCNTB = (u32)(uTCNTB/2);
							}
						else
							uTCNTB = 0xffffffff;

						printf("nTCMPB: ");
						uTCMPB = GetIntNum();

						PWM_Select(sTimer,1,0,uTCNTB,uTCMPB,0,0,0,1,0,0);					

						printf("Timer = %d, TCNTB=%ul, nTCMPB=%ul\n",sTimer,(unsigned)uTCNTB,(unsigned)uTCMPB);
						printf("nPCLK = %d , uPrescaler = %d, uDivider = %d\n",g_PCLK,1,(1<<(0)));
						fTimerclk = (1/(float)((float)g_PCLK/((float)1)/(1<<(0))))*uTCNTB;
						fTimerfreq = 1/fTimerclk;
						printf("Timer Clock = %d sec , Timer Frequency = %d hz\n\n",(unsigned)fTimerclk,(unsigned)fTimerfreq);

						printf("\nCheck PWM out (by Pinout)! \n");

						UART_Getc();
						PWM_stopAll();
						UART_Getc();						
						break;

						

						}
					else
						{
						printf("TCNTB : ");
						uTCNTB=GetIntNum();
						printf("\nTCMPB : ");
						uTCMPB=GetIntNum();
						PWM_Select(sTimer,1,0,uTCNTB,uTCMPB,0,0,0,1,0,0);					

						printf("Timer = %d\n",sTimer);
						printf("nPCLK = %d , uPrescaler = %d, uDivider = %d\n",g_PCLK,1,(1<<(0)));
						fTimerclk = (1/(float)((float)g_PCLK/((float)1)/(1<<(0))))*uTCNTB*1000;
						fTimerfreq = 1/fTimerclk;
						printf("Timer Clock = %f msec , Timer Frequency = %f Khz\n\n",fTimerclk,fTimerfreq);

						printf("\nCheck PWM out (by Pinout)! \n");
						UART_Getc();
						PWM_stopAll();
						UART_Getc();			
						break;
						}
				case 3:
					PWM_Select(sTimer,1,0,2000,1500,0,0,0,1,0,0);					
					printf("## Inverter off mode ##\n");
					printf("\nCheck PWM out (by Pinout)! \n");

					printf("Timer = %d\n",sTimer);
					printf("nPCLK = %d , uPrescaler = %d, uDivider = %d\n",g_PCLK,1,(1<<(0)));
					fTimerclk = (1/(float)((float)g_PCLK/((float)1)/(1<<(0))))*2000*1000;
					fTimerfreq = 1/fTimerclk;
					printf("Timer Clock = %f msec , Timer Frequency = %f Khz\n\n",fTimerclk,fTimerfreq);
					
					UART_Getc();
					
					PWM_Select(sTimer,1,0,2000,1500,0,0,0,1,1,0);					

					printf("## Inverter ON mode ##\n");
					printf("\nCheck PWM out (by Pinout)! \n");

					printf("Timer = %d\n",sTimer);
					printf("nPCLK = %d , uPrescaler = %d, uDivider = %d\n",g_PCLK,1,(1<<(0)));
					fTimerclk = (1/(float)((float)g_PCLK/((float)1)/(1<<(0))))*2000*1000;
					fTimerfreq = 1/fTimerclk;
					printf("Timer Clock = %f msec , Timer Frequency = %f Khz\n\n",fTimerclk,fTimerfreq);
					
					UART_Getc();
					break;
					
				case 4:
					printf("Deadzone length? [0~255] :");
					uCount = GetIntNum();
					PWM_Select(sTimer,1,0,2000,1000,1,uCount,0,1,0,0);										

					printf("Timer = %d\n",sTimer);
					printf("nPCLK = %d , uPrescaler = %d, uDivider = %d\n",g_PCLK,1,(1<<(0)));
					fTimerclk = (1/(float)((float)g_PCLK/((float)1)/(1<<(0))))*2000*1000;
					fTimerfreq = 1/fTimerclk;
					printf("Timer Clock = %f msec , Timer Frequency = %f Khz\n\n",fTimerclk,fTimerfreq);
					
					printf("\nCheck PWM out (by Pinout)! \n");
					UART_Getc();
					break;

				case 5:
					PWM_stopAll();
					break;
				default:
					break;
			}

			break;
		}

	}
	GPIO_SetFunctionEach(eGPIO_F,eGPIO_14,0);
	GPIO_SetFunctionEach(eGPIO_F,eGPIO_15,0);	
}



////////////
// File Name : TIMER_Int
// File Description : Check Timer Autoreload & oneshot Interrupt
// Input : NONE
// Output : NONE
// Version : 

void TIMER_Int(void)
{
   g_uIntCounter0 =0;   
   g_uIntCounter1 =0;   
   g_uIntCounter2 =0;   
   g_uIntCounter3 =0;   
   g_uIntCounter4 =0;		

	PWM_stopAll();	// stop timers
	
	INTC_SetVectAddr(NUM_TIMER0,Isr_TIMER0);
	INTC_SetVectAddr(NUM_TIMER1,Isr_TIMER1);
	INTC_SetVectAddr(NUM_TIMER2,Isr_TIMER2);
	INTC_SetVectAddr(NUM_TIMER3,Isr_TIMER3);	
	INTC_SetVectAddr(NUM_TIMER4,Isr_TIMER4);	
	INTC_Enable(NUM_TIMER0);
	INTC_Enable(NUM_TIMER1);
	INTC_Enable(NUM_TIMER2);
	INTC_Enable(NUM_TIMER3);
	INTC_Enable(NUM_TIMER4);
	
	
    printf("\n[Timer 0,1,2,3,4 Interrupt Test]\n\n");

    //Dead zone=0,Prescaler1=255(0x0f),Prescaler0=255(0x0f)
    //All interrupt,Mux4=1/2,Mux3=1/4,Mux2=1/8,Mux1=1/16,Mux0=1/16

	PWM_Select(0,255,4,30000,15000,0,0,0,1,0,1);
	PWM_Select(1,255,3,30000,15000,0,0,0,1,0,1);
	PWM_Select(2,255,2,30000,15000,0,0,0,1,0,1);
	PWM_Select(3,255,1,30000,15000,0,0,0,1,0,1);	
	PWM_Select(4,255,0,30000,15000,0,0,0,1,0,1);	




    while(1)
    {
	if(g_uIntCounter4 == 16)
	break;
    }
	PWM_stopAll();	 //Stop Timers
   
    if(g_uIntCounter4==16 && g_uIntCounter3==8 && g_uIntCounter2==4 
		&& g_uIntCounter1==2 && g_uIntCounter0==1)
	    {
      		  printf("Timer 0,1,2,3,4 Auto-reload Interrupt Test => OK!\n");
	    }        
    else
	    {
	        printf("Timer 0,1,2,3,4 Auto-reload Interrupt Test => Fail............\n");
	    }    
    	printf("Timer0: %d (=1)\nTimer1: %d (=2)\nTimer2: %d (=4)\nTimer3: %d (=8)\nTimer4: %d (=16)\n",
        g_uIntCounter0,g_uIntCounter1,g_uIntCounter2,g_uIntCounter3,g_uIntCounter4);        
	


// OneShot Test //
  	g_uIntCounter0 = 0;g_uIntCounter1 = 0;g_uIntCounter2 = 0;g_uIntCounter3 = 0;g_uIntCounter4 = 0;

    //T0,1,2,3,4= One-shot,Inverter off,No operation,Dead zone disable,Start
	PWM_Select(4,255,0,30000,15000,0,0,0,0,0,1);	  	
	PWM_Select(3,255,1,30000,15000,0,0,0,0,0,1);
	PWM_Select(2,255,2,30000,15000,0,0,0,0,0,1);
	PWM_Select(1,255,3,30000,15000,0,0,0,0,0,1);
	PWM_Select(0,255,4,30000,15000,0,0,0,0,0,1);


	while(g_uIntCounter0 == 0);     

	PWM_stopAll(); //One-shot, Inverter off, No operation, Dead zone disable, Stop
   
    if(g_uIntCounter4==1 && g_uIntCounter3==1 && g_uIntCounter2==1 
		&& g_uIntCounter1==1 && g_uIntCounter0==1)
   	 {
    		printf("Timer 0,1,2,3,4 One-shot Interrupt Test => OK!\n");
	 }        
    else
	 {
       	 printf("Timer 0,1,2,3,4 One-shot Interrupt Test => Fail............\n");
	 }    

	printf("Timer0: %d (=1)\nTimer1: %d (=1)\nTimer2: %d (=1)\nTimer3: %d (=1)\nTimer4: %d (=1)\n", g_uIntCounter0,g_uIntCounter1,g_uIntCounter2,g_uIntCounter3,g_uIntCounter4);        


	// Timer0,1,2,3,4 Interrupt Service is masked //
	INTC_Disable(NUM_TIMER4);
	INTC_Disable(NUM_TIMER3);
	INTC_Disable(NUM_TIMER2);
	INTC_Disable(NUM_TIMER1);
	INTC_Disable(NUM_TIMER0);
	
	printf("Press any key\n");      
	while(!UART_Getc());       //Key board press check      

}



////////////
// File Name : TIMER_Prescaler1
// File Description : Check Prescaler1 values by Comparing Timer0 & Timer2's Interrupt 
//			(SMDK6400 doesn't have TOUT[2],[3],[4] pin out therefore used Interrupt check)
// Input : NONE
// Output : NONE
// Version : 

void TIMER_Prescaler1(void)
{
	u32 uPrescaler;
	u32 uCnt;

	PWM_stopAll();	// stop timers
	INTC_SetVectAddr(NUM_TIMER0,Isr_TIMER0);
	INTC_SetVectAddr(NUM_TIMER2,Isr_TIMER2);	
	INTC_Enable(NUM_TIMER0);
	INTC_Enable(NUM_TIMER2);

	printf("Prescaler1 test start\n\n");
	uCnt = 0;
	uPrescaler = 0;
	
	while(uPrescaler<255)
		{

		printf("test Prescaler value = %d   ",uPrescaler);
		
		PWM_Select(2,uPrescaler,4,10000,5000,0,0,0,1,0,1);	
		PWM_Select(0,uPrescaler,4,10000,5000,0,0,0,1,0,1);	  	

		while (g_uIntCounter0 == 20);
		PWM_stopAll();
		
		if (g_uIntCounter0 == g_uIntCounter2)
 			printf("Prescaler 1 test ==> OK!\n");
		else
			{
			printf("Prescaler 1 test ==> Fail........\n");
			uCnt++;
			}
		uPrescaler = uPrescaler + 50;
		
		}

		uPrescaler = 255;
		printf("test Prescaler value = %d   ",uPrescaler);
		
		PWM_Select(2,uPrescaler,4,10000,5000,0,0,0,1,0,1);	
		PWM_Select(0,uPrescaler,4,10000,5000,0,0,0,1,0,1);	  	

		while (g_uIntCounter0 == 20);

⌨️ 快捷键说明

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