📄 test.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-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: test.cpp
//
// This file contains test code for the GPT driver
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include "gpt.h"
//#include "mxarm11.h"
#include "csp.h"
#include "main.h"
#include "globals.h"
//-----------------------------------------------------------------------------
// External Functions
//-----------------------------------------------------------------------------
// External Variables
extern HANDLE hGpt;
extern PCSP_GPT_REGS g_pGPT;
//-----------------------------------------------------------------------------
// Defines
#define GPT_ZONE_INFO 0
#define GPT_ZONE_ERROR 0
#define GPT_ZONE_FUNCTION 0
#define GPT_TEST_FUNCTION_ENTRY() \
g_pKato->Log(GPT_ZONE_FUNCTION, (TEXT("++%s\r\n"), __WFUNCTION__))
#define GPT_TEST_FUNCTION_EXIT() \
g_pKato->Log(GPT_ZONE_FUNCTION, (TEXT("--%s\r\n"), __WFUNCTION__))
#define GPT_EVENT_NAME L"GptTest1"
#define THREAD_PRIORITY 250
//-----------------------------------------------------------------------------
// Types
//-----------------------------------------------------------------------------
// Global Variables
#ifdef DEBUG
DBGPARAM dpCurSettings =
{
_T("GPTTEST"),
{
_T(""), _T(""), _T(""), _T(""),
_T(""), _T(""), _T(""), _T(""),
_T(""),_T(""),_T(""),_T(""),
_T("Info"),_T("Function"),_T("Warnings"),_T("Errors")
},
0x0
};
#endif
//-----------------------------------------------------------------------------
// Local Variables
static HANDLE hGptIntr;
static UINT8 int_count = 0;
//-----------------------------------------------------------------------------
// Local Functions
void GptIST(void);
static BOOL GptISR(UINT32 timeout);
//------------------------------------------------------------------------------
//
// Function: GptTest1
//
// This function attempts to start the GPT
// timer without setting the timer period.
//
// Parameters:
// uiMsg
// [in] Ignored.
//
// tpParam
// [in] Ignored.
//
// lpFTE
// [in] Ignored.
//
// Returns:
// Specifies if the test passed (TPR_PASS), failed (TPR_FAIL), or was
// skipped (TPR_SKIP).
//
//------------------------------------------------------------------------------
TESTPROCAPI GptTest1(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
// Validate that the shell wants the test to run
if (uMsg != TPM_EXECUTE)
{
return TPR_NOT_HANDLED;
}
if (!GptStart(hGpt))
{
g_pKato->Log(GPT_ZONE_ERROR,
(TEXT("GptTest1: GptStart could not run. This is the expected behavior.\r\n")));
return TPR_PASS;
}
else
{
g_pKato->Log(GPT_ZONE_ERROR,
(TEXT("GptTest1: GptStart ran without setting the timer. This is incorrect.\r\n")));
return TPR_FAIL;
}
}
//------------------------------------------------------------------------------
//
// Function: GptTest2
//
// This function tests the GPT timer.
//
// Parameters:
// uiMsg
// [in] Ignored.
//
// tpParam
// [in] Ignored.
//
// lpFTE
// [in] Ignored.
//
// Returns:
// Specifies if the test passed (TPR_PASS), failed (TPR_FAIL), or was
// skipped (TPR_SKIP).
//
//------------------------------------------------------------------------------
TESTPROCAPI GptTest2(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
GPT_TIMER_SET_PKT gptTimerDelayPkt;
//GPT_TEST_FUNCTION_ENTRY();
// Validate that the shell wants the test to run
if (uMsg != TPM_EXECUTE)
{
return TPR_NOT_HANDLED;
}
// reset the interrupt count each time this test is run
int_count = 0;
// create an event for the timer interrupt
hGptIntr = GptCreateTimerEvent(hGpt, GPT_EVENT_NAME);
if (hGptIntr == NULL)
{
g_pKato->Log(GPT_ZONE_ERROR,
(TEXT("GptTest2: GptGetInterrupt failed!\r\n")));
return TPR_FAIL;
}
gptTimerDelayPkt.timerMode = timerModePeriodic;
gptTimerDelayPkt.period = 1000;
gptTimerDelayPkt.periodType = MILLISEC;
if (!GptSetTimer(hGpt, &gptTimerDelayPkt))
{
g_pKato->Log(GPT_ZONE_ERROR,
(TEXT("GptTest2: GptSetTimer failed!\r\n")));
return TPR_FAIL;
}
if (!GptStart(hGpt))
{
g_pKato->Log(GPT_ZONE_ERROR,
(TEXT("GptTest2: GptStart failed!\r\n")));
return TPR_FAIL;
}
// Enter ISR loop
if (!GptISR(INFINITE))
{
GPT_TEST_FUNCTION_EXIT();
return TPR_FAIL;
}
else
{
GPT_TEST_FUNCTION_EXIT();
return TPR_PASS;
}
}
//------------------------------------------------------------------------------
//
// Function: GptISR
//
// This function is the interrupt handler for the GPT.
//
// Parameters:
// timeout
// [in] Timeout period while waiting for an interrupt
//
// Returns:
// TRUE if success, FALSE if failure.
//
//------------------------------------------------------------------------------
static BOOL GptISR(UINT32 timeout)
{
GPT_TIMER_SET_PKT gptTimerDelayPkt;
GPT_TEST_FUNCTION_ENTRY();
// loop here
while(TRUE)
{
g_pKato->Log (GPT_ZONE_INFO, (TEXT("GptISR: In the loop\r\n")));
if (WaitForSingleObject(hGptIntr, timeout) == WAIT_OBJECT_0)
{
g_pKato->Log (GPT_ZONE_INFO, (TEXT("GptISR: Interrupt received\r\n")));
// Increment count of interrupts that have occurred
int_count++;
// At 12th interrupt, change the timer period
if (int_count == 12)
{
gptTimerDelayPkt.timerMode = timerModePeriodic;
gptTimerDelayPkt.period = 3000;
gptTimerDelayPkt.periodType = MILLISEC;
// issue the command to set GPT timer delay
if (!GptSetTimer(hGpt, &gptTimerDelayPkt))
{
g_pKato->Log(GPT_ZONE_ERROR,
(TEXT("GptISR: GptSetTimer failed!\r\n")));
return FALSE;
}
if (!GptStart(hGpt))
{
g_pKato->Log(GPT_ZONE_ERROR,
(TEXT("GptTest2: GptStart failed!\r\n")));
return TPR_FAIL;
}
}
// At 16th interrupt, stop the timer
if (int_count > 14)
{
// stop the timer
if (!GptStop(hGpt))
{
g_pKato->Log(GPT_ZONE_ERROR,
(TEXT("GptISR: GptStop failed!\r\n")));
}
return TRUE;
}
}
else
{
// Timeout as requested
g_pKato->Log (GPT_ZONE_INFO, (TEXT("GptISR-: Time out\r\n")));
}
}
GPT_TEST_FUNCTION_EXIT();
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -