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

📄 pwmtest.cpp

📁 mx27 f14v2 源代码。包括ADS板上诸多驱动的源码。
💻 CPP
字号:
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//-----------------------------------------------------------------------------
//
//  Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
//  Copyright (C) 2004-2006, Freescale Semiconductor, Inc. All Rights Reserved.
//  THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
//  AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//
//  File:  pwmtest.cpp
//
//  This file contains test code for the PWM driver
//
//-----------------------------------------------------------------------------

#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include "pwmdefs.h"
#include "main.h"
#include "globals.h"

//-----------------------------------------------------------------------------
// External Functions
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// External Variables
//-----------------------------------------------------------------------------
extern HANDLE g_hDriver;

//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
#define PWM_ZONE_INFO                TRUE
#define PWM_ZONE_ERROR             TRUE
#define TEST_LOOP                           3
//-----------------------------------------------------------------------------
// Local Functions
//-----------------------------------------------------------------------------



//-----------------------------------------------------------------------------
// Local Variables
//-----------------------------------------------------------------------------
static UINT32 PwmReadRegs[6] = {0,0,0,0,0,0};		// array to read registers in PWM in following format
								// PwmReadRegs[0] is Control Register
								// PwmReadRegs[1] is Status Register
								// PwmReadRegs[2] is Interrupt Register
								// PwmReadRegs[3] is Sample Register
								// PwmReadRegs[4] is Period Register
								// PwmReadRegs[5] is Counter Register
static UINT32 bytesWritten=0, bytesRead=0;
static PwmSample_t SampleForRegister[]=
{
	{1,1,500}, {4,20,1500},{6,30,8700}
};

static PwmSample_t SampleForWaveform[]=
{
	{1,14,500}, {1,7,1000},{1,1,5000}
};

static unsigned short Waveform_Frequency[3][60]=
{
	_T("Is the frequency of waveform equal to 2KHz?"),
	_T("Is the frequency of waveform equal to 3.55KHz?"),
	_T("Is the frequency of waveform equal to 10.67KHz?")
};

//------------------------------------------------------------------------------
//
// Function: PWMResetTest
//
// This function tests the PWM software reset.
//
// Parameters:
//      uiMsg
//           [in] to determine if the shell wants to execute the test.
//
//      tpParam
//           [in] Ignored.
//
//      lpFTE
//           [in] Ignored.
//
// Returns:
//      Specifies if the test passed (TPR_PASS), failed (TPR_FAIL)
//
//------------------------------------------------------------------------------
TESTPROCAPI PWMResetTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
	// The shell doesn't necessarily want us to execute the test. Make sure
	// first.
	if(uMsg != TPM_EXECUTE)
	{
		return TPR_NOT_HANDLED;
	}
	
	g_pKato->Log(LOG_COMMENT, TEXT("PWMTest.cpp:PWMResetTest() +\r\n"));
	
	// Issue the IOCTL to reset PWM
	if (!DeviceIoControl(g_hDriver, PWM_IOCTL_RESET, NULL, 0, NULL, 0, 0, NULL))
	{
		g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMResetTest(): PWM_IOCTL_RESET failed!\r\n"));
		return TPR_FAIL;
	}
	
	g_pKato->Log(LOG_COMMENT, TEXT("PWMTest.cpp:PWMResetTest() -\r\n"));
	
	return TPR_PASS;
}


//------------------------------------------------------------------------------
//
// Function: PWMRegisterTest
//
// This function attempts to perform a series of Registers write and read tests
//
// Parameters:
//      uiMsg
//           [in] Ito determine if the shell wants to execute the test.
//
//      tpParam
//           [in] Ignored.
//
//      lpFTE
//           [in] Ignored.
//
// Returns:
//      Specifies if the test passed (TPR_PASS), failed (TPR_FAIL)
//
//------------------------------------------------------------------------------
TESTPROCAPI PWMRegisterTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
	int i;
	// The shell doesn't necessarily want us to execute the test. Make sure
	// first.
	if(uMsg != TPM_EXECUTE)
	{
		return TPR_NOT_HANDLED;
	}
	
	g_pKato->Log(LOG_COMMENT, TEXT("PWMTest.cpp:PWMRegisterTest() +\r\n"));
	
	// Issue the IOCTL to reset PWM
	if (!DeviceIoControl(g_hDriver, PWM_IOCTL_RESET, NULL, 0, NULL, 0, 0, NULL))
	{
		g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMRegisterTest(): PWM_IOCTL_RESET failed!\r\n"));
		return TPR_FAIL;
	}
	
	for(i=0; i<TEST_LOOP;i++)
	{
		Debug(TEXT("sample value in %d is %d \r\n"), i, SampleForRegister[i].sample);
		Debug(TEXT("period value in %d is %d \r\n"), i, SampleForRegister[i].period);
		Debug(TEXT("duration value in %d is %d \r\n"), i, SampleForRegister[i].duration);
	}
	for(i=0; i<TEST_LOOP; i++)
	{
		if(!WriteFile(g_hDriver, &SampleForRegister[i], sizeof(PwmSample_t), (LPDWORD) &bytesWritten, NULL))
		{
			g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMRegisterTest(): WriteFile failed!\r\n"));
			Debug(TEXT("PWMTest.cpp:PWMRegisterTest(): WriteFile failed!\r\n"));
			return TPR_FAIL;
		}
		if(!ReadFile(g_hDriver, PwmReadRegs, sizeof(PwmReadRegs), (LPDWORD) &bytesRead, NULL))
		{
			g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMRegisterTest(): ReadFile failed!\r\n"));
			Debug(TEXT("PWMTest.cpp:PWMRegisterTest(): ReadFile failed!\r\n"));
			return TPR_FAIL;
		}
		// check sample value in sample register
		if(SampleForRegister[i].sample != PwmReadRegs[3])
		{
			g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMRegisterTest(): Sample Register failed!\r\n"));
			Debug(TEXT("PWMTest.cpp:PWMRegisterTest(): Sample Register failed!\r\n"));
			Debug(TEXT("Value [3] is %d \r\n"), PwmReadRegs[3]);
			Debug(TEXT("actual value in  is %d \r\n"), SampleForRegister[i].sample);
			return TPR_FAIL;
		}
		// check period value in period register
		if(SampleForRegister[i].period != PwmReadRegs[4])
		{
	    	g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMRegisterTest(): Period Register failed!\r\n"));
	    	Debug(TEXT("PWMTest.cpp:PWMRegisterTest(): Period Register failed!\r\n"));
	    	Debug(TEXT("Value [4] is %d \r\n"), PwmReadRegs[4]);
	    	Debug(TEXT("actual value is %d \r\n"), SampleForRegister[i].period);
	    	return TPR_FAIL;
		}
	}
	
	g_pKato->Log(LOG_COMMENT, TEXT("PWMTest.cpp:PWMRegisterTest() -\r\n"));
	
	return TPR_PASS;
}


//------------------------------------------------------------------------------
//
// Function: PWMWaveformTest 
//
// This function generate a series of PWM waveform. The user will need to capture 
// the PWMO waveform on Logic Analyzer or Digital Oscilloscope. The frequency of the 
// captured waveform is calculated by using the equation:
//	PCLK/(period+2) where PCLK = ipg_clk/[Prescalar_Register_value+1]
//
// Parameters:
//      uiMsg
//           [in] to determine if the shell wants to execute the test.
//
//      tpParam
//           [in] Ignored.
//
//      lpFTE
//           [in] Ignored.
//
// Returns:
//      Specifies if the test passed (TPR_PASS), failed (TPR_FAIL)
//
//------------------------------------------------------------------------------
TESTPROCAPI PWMWaveformTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
	int i, returnvalue;
	// The shell doesn't necessarily want us to execute the test. Make sure
	// first.
	if(uMsg != TPM_EXECUTE)
	{
		return TPR_NOT_HANDLED;
	}
	
	g_pKato->Log(LOG_COMMENT, TEXT("PWMTest.cpp:PWMWaveformTest() +\r\n"));
	if (!DeviceIoControl(g_hDriver, PWM_IOCTL_RESET, NULL, 0, NULL, 0, 0, NULL))
	{
		g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMWaveformTest(): PWM_IOCTL_RESET failed!\r\n"));
		return TPR_FAIL;
	}
	returnvalue = MessageBox(NULL, _T("Please connect a Digital Oscilloscope for this test"),_T( "Waveform Test"), MB_ICONINFORMATION|MB_OKCANCEL);

	if(returnvalue != IDOK)
	{
		g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMWaveformTest(): Waveform test failed!\r\n"));
		Debug(TEXT("PWMTest.cpp:PWMWaveformTest(): User abort test.\r\n"));
		return TPR_FAIL;  
	}

	for(i=0; i<TEST_LOOP; i++)
	{
		if(!WriteFile(g_hDriver, &SampleForWaveform[i], sizeof(PwmSample_t), (LPDWORD) &bytesWritten, NULL))
		{
			g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMWaveformTest(): Waveform test failed!\r\n"));
			Debug(TEXT("PWMTest.cpp:PWMWaveformTest(): Waveform %d test failed!\r\n"), i);
			return TPR_FAIL;
		}
		returnvalue = MessageBox(NULL, &Waveform_Frequency[i][0],_T( "Waveform Test"), MB_ICONQUESTION|MB_YESNO);
	
		if(returnvalue == IDNO)
		{
			g_pKato->Log(PWM_ZONE_ERROR, TEXT("PWMTest.cpp:PWMWaveformTest(): Waveform test failed!\r\n"));
			Debug(TEXT("PWMTest.cpp:PWMWaveformTest(): Waveform %d test failed!\r\n"), i);
			return TPR_FAIL;
		}	
	}
	
	g_pKato->Log(LOG_COMMENT, TEXT("PWMTest.cpp:PWMWaveformTest() -\r\n"));
	
	return TPR_PASS;
}

⌨️ 快捷键说明

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