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

📄 adcts.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 : adcts.c
*  
*	File Description : This file implements the driver functions for ADC/TS.
*
*	Author : Sunil,Roe
*	Dept. : AP Development Team
*	Created Date : 2007/1/2
*	Version : 0.1 
* 
*	History
*	- Created(Sunil,Roe 2007/1/2)
*   
**************************************************************************************/

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

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

#include "adcts.h"

#define 	ADCTS			( (volatile oADCTS_REGS *) (g_pADCTSBase))
#define	ADCTS_PRSCVL		10

typedef struct tag_ADCTS_REGS
{
	u32 rADCCON;
	u32 rADCTSC;
	u32 rADCDLY;
	u32 rADCDAT0;
	u32 rADCDAT1;
	u32 rADCUPDN;
	u32 rADCCLRINT;
} 
oADCTS_REGS;

// define global variables
static void *				g_pADCTSBase;
volatile	ADCTS_oInform	g_oADCTSInform;

/*---------------------------------- ISR Routines Definition ---------------------------------*/
void __irq	ADC_NormalISR(void);
void __irq	ADCTS_StylusCheckISR(void);
void __irq	ADCTS_StylusTrackingISR(void);

//////////
// Function Name : ADCTS_Init
// Function Description : This function initializes an ADCTS.
// Input : 	NONE 
// Output : 	TRUE - Memory Device is reset
//			FALSE - Memory Device is not reset because of ERROR
// Version : v0.1
bool	ADCTS_Init(void)
{
	u32 uBaseAddress=0;

	uBaseAddress = ADCTS_BASE;
	
	g_pADCTSBase = (void *)uBaseAddress;

	ADCTS_SetADCClearInt();
	ADCTS_SetADCClearWKInt();
	
	return TRUE;
}

//////////
// Function Name : ADC_ConvertADCNormallyInPolling
// Function Description : This function tests ADC Normal Conversion in Polling mode.
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void ADC_ConvertADCNormallyInPolling(void)
{
	u8	ucADCChannelCnt = 0;

	printf("The ADC_IN are adjusted to the following values.\n");        
	printf("Push any key to exit!!!\n");    
	printf("ADC conv. freq.=%d(Hz)\n",(u32)(g_PCLK/(ADCTS_PRSCVL+1.)));

	ADC_InitADCCON();

	while(GetKey()==0) 
	{
		for(ucADCChannelCnt=0 ; ucADCChannelCnt<8; ucADCChannelCnt++) 
		{
			ADC_SelectADCCh(ucADCChannelCnt);	//	Channel setup
			ADC_EnableStart(ENABLE);

			while (! ADC_IsAfterStartup() ) ;	//	Wait for begin sampling

			while (! (ADC_IsEOCFlag()));			//	Wait for the EOC

			printf("Ain%d: %04d ",ucADCChannelCnt, ADCTS_GetXPData());
		}
		printf("\n");
	}
}

//////////
// Function Name : ADC_ConvertADCNormallyInADCInterrupt
// Function Description : This function tests ADC Normal Conversion in Interrupt mode.
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void ADC_ConvertADCNormallyInADCInterrupt(void)
{

	u8	ucADCChannelCnt = 0;
	    
	printf("The ADC_IN are adjusted to the following values.\n");        
	printf("Push any key to exit!!!\n");    
	printf("ADC conv. freq.=%d(Hz)\n",(u32)(g_PCLK/(ADCTS_PRSCVL+1.)));

	ADC_InitADCCON();

	INTC_SetVectAddr(NUM_ADC, ADC_NormalISR);
	INTC_Enable(NUM_ADC);

	while(GetKey()==0)
	{
    
		for(ucADCChannelCnt = 0 ;ucADCChannelCnt<8; ucADCChannelCnt++) 
		{
			ADC_SelectADCCh(ucADCChannelCnt);	//	Channel setup

			g_oADCTSInform.ucADCflag = 0;
			ADC_EnableStart(ENABLE);
			
			while(g_oADCTSInform.ucADCflag == 0);

			printf("Ain%d: %04d ",ucADCChannelCnt,g_oADCTSInform.uADCSampleData);
		}
//		Getc();
		printf("\n");
	}

	INTC_Disable(NUM_ADC);
}

//////////
// Function Name : ADCTS_ConvertXYPosSeparatelyInPolling
// Function Description : This function tests ADCTS Manual Conversion of X/Y Position in Polling mode.
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void ADCTS_ConvertXYPosSeparatelyInPolling(void)
{
	u32 uXDat = 0;
	u32 uYDat = 0;
	printf("[ Separate X/Y Position measurement mode ]\n");
   
   	while(GetKey()==0) 
	{
		//------- Get X-Position Data -------------
		ADCTS_SetMeasureMode(eADCTS_MEASURE_MANUAL_X);

		ADC_InitADCCON();
		ADC_SelectADCCh(5);		// Channel Setup

		ADC_EnableStart(ENABLE);

		while(! (ADC_IsAfterStartup() )) ;	//	Wait for begin sampling
		while (! (ADC_IsEOCFlag()));		//	Wait for the EOC

		uXDat	= ADCTS_GetXPData();

		//------- Get Y-Position Data -------------
		ADCTS_SetMeasureMode(eADCTS_MEASURE_MANUAL_Y);

		ADC_InitADCCON();
		ADC_SelectADCCh(7);		// Channel Setup

		ADC_EnableStart(ENABLE);

		while(! (ADC_IsAfterStartup() )) ;	//	Wait for begin sampling
		while (! (ADC_IsEOCFlag()));		//	Wait for the EOC

		uYDat	= ADCTS_GetYPData();

		printf("X : %d, Y : %d\n",uXDat,uYDat);
	}

}

//////////
// Function Name : ADCTS_ConvertXYPosSequentiallyInPolling
// Function Description : This function tests ADCTS Auto Sequential Conversion of X/Y Position in Polling mode.
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void ADCTS_ConvertXYPosSequentiallyInPolling(void)
{
	u32 uXDat = 0;
	u32 uYDat = 0;
	printf("[ Auto Sequential X/Y Position measurement mode ]\n");
   
   	while(GetKey()==0) 
	{
		ADCTS_SetMeasureMode(eADCTS_MEASURE_AUTO_SEQ);

		ADC_InitADCCON();

		ADC_EnableStart(ENABLE);

		while(! (ADC_IsAfterStartup() )) ;	//	Wait for begin sampling
		while (! (ADC_IsEOCFlag()));		//	Wait for the EOC

		uXDat	= ADCTS_GetXPData();
		uYDat	= ADCTS_GetYPData();

		printf("X : %d, Y : %d\n",uXDat,uYDat);
   	}
}

//////////
// Function Name : ADCTS_StylusCheckInPENDNInterrupt
// Function Description : This function tests ADCTS Stylus Check Using PenDown Interrupt.
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void ADCTS_StylusCheckInPENDNInterrupt(void)
{
	ADC_InitADCCON();
	ADCTS_SetDelay(50000);		//	Normal conversion mode delay about (1/50M)*50000=1ms

	printf("[ADC touch screen test.]\n");

	ADCTS_SetMeasureMode(eADCTS_MEASURE_FOR_STYLUS);

	Delay(10000);

	INTC_SetVectAddr(NUM_PENDN, ADCTS_StylusCheckISR);
	INTC_Enable(NUM_PENDN);

	printf("Type any key to exit!!!\n");
	printf("Stylus Down, please...... \n");
	Getc();

	INTC_Disable(NUM_PENDN);
	
}

//////////
// Function Name : ADCTS_StylusTrackingUsingAutoConversionInPENDNInterrupt
// Function Description : This function tests ADCTS Auto Sequential Conversion of X/Y Position in Polling mode Using PenDown Interrupt.
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void ADCTS_StylusTrackingUsingAutoConversionInPENDNInterruptADCPolling(void)
{
	u32 uXDat = 0;
	u32 uYDat = 0;

	printf("\n\n[ADCTS touch screen Tracking test.]\n");

	g_oADCTSInform.ucTouchStatus	=	ADCTS_TOUCH_INIT;
	ADC_InitADCCON();
	ADCTS_SetDelay(50000);

	ADCTS_SetMeasureMode(eADCTS_MEASURE_FOR_STYLUS);

	Delay(10000);

	INTC_SetVectAddr(NUM_PENDN, ADCTS_StylusTrackingISR);
	INTC_Enable(NUM_PENDN);

    	printf("\nPress any key to exit!!!\n");
    	printf("\nStylus Down, please...... \n");

	while(!GetKey())
	{
		if (g_oADCTSInform.ucTouchStatus == ADCTS_TOUCH_DOWN)
		{
			while( ADCTS_GetXPStylusIntState() == STYLUS_DOWN )
			{
				ADC_InitADCCON();
				ADCTS_SetMeasureMode(eADCTS_MEASURE_AUTO_SEQ);

				ADC_EnableStart(ENABLE);

				while(! (ADC_IsAfterStartup() )) ;	//	Wait for begin sampling
				while (! (ADC_IsEOCFlag()));		//	Wait for the EOC

				uXDat	= ADCTS_GetXPData();
				uYDat	= ADCTS_GetYPData();

				printf("X : %d, Y : %d\n",uXDat,uYDat);
				ADCTS_SetMeasureMode(eADCTS_MEASURE_FOR_STYLUS);
				ADCTS_SetStylusDetectMode(STYLUS_UP);
				Delay(300);
			}
		}
		else if (g_oADCTSInform.ucTouchStatus == ADCTS_TOUCH_UP)
		{
			if ( ADCTS_GetXPStylusIntState() == STYLUS_UP )
			{
				ADCTS_SetMeasureMode(eADCTS_MEASURE_FOR_STYLUS);
			}
		}
	}

	INTC_Disable(NUM_PENDN);
	printf("\n\n[ADCTS touch screen Tracking test End.]\n");	
}

//////////
// Function Name : ADC_CheckADCLinearity
// Function Description : This function tests ADC Conversion Linearity.
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void ADC_CheckADCLinearity(void)
{
	u8	ucADCChannelCnt 	= 0;
	u8	ucLoopCnt			= 0;
	u32	uTotADCValue			= 0;

	printf("The ADC_IN are adjusted to the following values.\n");        
	printf("Push any key to exit!!!\n");    
	printf("ADC conv. freq.=%d(Hz)\n",(u32)(g_PCLK/(ADCTS_PRSCVL+1.)));

	while(GetKey()==0) 
	{
		ucLoopCnt 	 = 0;
		uTotADCValue	 = 0;

		ADC_InitADCCON();
		
		Disp("\n Input ADC Channel No.(0~7)");
	 	ucADCChannelCnt = GetIntNum(); 

		if ( ucADCChannelCnt > 7 )
			break;

		while(ucLoopCnt < 100)
		{
			ADC_SelectADCCh(ucADCChannelCnt);	//	Channel setup
			ADC_EnableStart(ENABLE);

			while (! ADC_IsAfterStartup() ) ;	//	Wait for begin sampling

			while (! (ADC_IsEOCFlag()));			//	Wait for the EOC

			uTotADCValue += ADCTS_GetXPData();
			ucLoopCnt++;
		}

		printf("ucLoopCnt : %d, Ain%d: %04d \n",ucLoopCnt, ucADCChannelCnt, (u32)(uTotADCValue/ucLoopCnt));
	}
}

/*---------------------------------- ISR Routines ---------------------------------*/
//////////
// Function Name : ADC_NormalISR
// Function Description : This function is a ADC interrupt handler of ADC_ConvertADCNormallyInADCInterrupt().
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void __irq	ADC_NormalISR(void)
{
	g_oADCTSInform.uADCSampleData 	= ADCTS_GetXPData();
	g_oADCTSInform.ucADCflag		= 1;

	ADCTS_SetADCClearInt();
	INTC_ClearVectAddr();
}

//////////
// Function Name : ADCTS_StylusCheckISR
// Function Description : This function is a pen-down interrupt handler of ADCTS_StylusCheckInPENDNInterrupt().
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void __irq	ADCTS_StylusCheckISR(void)
{
//	u32 temp = 0;

//	temp = Inp32(0x71300008);
//	Disp("VIC1RawINTR:0x%x\n", temp);
	Disp("&");

	ADCTS_SetADCClearWKInt();
	INTC_ClearVectAddr();

⌨️ 快捷键说明

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