📄 nleddrvrtest.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) 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: NleddrvrTest.cpp
//
// This file contains test code for the NLeddrvr driver
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include "main.h"
#include "globals.h"
#include <nled.h>
//-----------------------------------------------------------------------------
// External Functions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// External Variables
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
#define NLED_ZONE_ERROR FALSE
#define NLED_MAX_LED_CETK 2
//-----------------------------------------------------------------------------
// Local Functions
//-----------------------------------------------------------------------------
static bool NLeddrvrWorkModeTest(UINT OffOnBlink);
//-----------------------------------------------------------------------------
// Local Variables
//-----------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// Function: NLeddrvrOffTest
//
// Set Notification LED(s) to 'Off' state
//
// 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 NLeddrvrOffTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
UINT OffOnBlink = 0;
if(uMsg != TPM_EXECUTE)
return TPR_NOT_HANDLED;
if(NLeddrvrWorkModeTest(OffOnBlink))
return TPR_PASS;
g_pKato->Log(NLED_ZONE_ERROR, TEXT("NLeddrvrTest.cpp:NLeddrvrOffTest - LED(s) not turned 'Off'\r\n"));
Debug(TEXT("NLeddrvrTest.cpp: -NLeddrvrOffTest LED(s) not turned 'Off'\r\n"));
return TPR_FAIL;
}
//------------------------------------------------------------------------------
//
// Function: NLeddrvrOnTest
//
// Set Notification LED(s) to 'Off' state
//
// 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 NLeddrvrOnTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
UINT OffOnBlink = 1;
if(uMsg != TPM_EXECUTE)
return TPR_NOT_HANDLED;
if(NLeddrvrWorkModeTest(OffOnBlink))
return TPR_PASS;
g_pKato->Log(NLED_ZONE_ERROR, TEXT("NLeddrvrTest.cpp:NLeddrvrOnTest - LED(s) not turned 'On'\r\n"));
Debug(TEXT("NLeddrvrTest.cpp: -NLeddrvrOnTest LED(s) not turned 'On'\r\n"));
return TPR_FAIL;
}
//------------------------------------------------------------------------------
//
// Function: NLeddrvrBlinkTest
//
// Set Notification LED(s) to 'Blink' state with specified 'On' and 'Off' times.
//
// 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 NLeddrvrBlinkTest(UINT uMsg, TPPARAM tpParam, LPFUNCTION_TABLE_ENTRY lpFTE)
{
UINT OffOnBlink = 2;
if(uMsg != TPM_EXECUTE)
return TPR_NOT_HANDLED;
if(NLeddrvrWorkModeTest(OffOnBlink))
return TPR_PASS;
g_pKato->Log(NLED_ZONE_ERROR, TEXT("NLeddrvrTest.cpp:NLeddrvrBlinkTest - LED(s) not turned 'On'\r\n"));
Debug(TEXT("NLeddrvrTest.cpp: -NLeddrvrBlinkTest LED(s) not turned 'On'\r\n"));
return TPR_FAIL;
}
//------------------------------------------------------------------------------
//
// Function: NLeddrvrWorkModeTest
//
// Set Notification LED(s) to 'Blink' state with specified 'On' and 'Off' times.
//
// Parameters:
// OffOnBlink
// [in] to determine if the shell wants to execute the test.
//
// Returns:
// Specifies if the test passed (TRUE), failed (FLASE)
//
//------------------------------------------------------------------------------
static bool NLeddrvrWorkModeTest(UINT OffOnBlink)
{
UINT nId;
UINT cLEds = 0;
HANDLE hNLeddrvr = NULL;
int RetVal = IDNO;
NLED_COUNT_INFO NledCountInfo = {0};
NLED_SUPPORTS_INFO NledSupportsInfo[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
NLED_SETTINGS_INFO NledSettingsInfo[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
Debug((TEXT("+%s()\r\n"), __WFUNCTION__));
//Open NLED Device
hNLeddrvr = CreateFile(TEXT("NLD1:"), // name of device
GENERIC_READ|GENERIC_WRITE, // desired access
FILE_SHARE_READ|FILE_SHARE_WRITE, // sharing mode
NULL, // security attributes (ignored)
OPEN_EXISTING, // creation disposition
FILE_FLAG_RANDOM_ACCESS, // flags/attributes
NULL); // template file (ignored)
if(hNLeddrvr == NULL)
{
Debug(TEXT("NLeddrvrWorkModeTest:CreateFile(NLeddrvr): Unable to open file! \r\n"));
return FALSE;
}
// Get NLED Number
{
nId = NLED_COUNT_INFO_ID;
if(!DeviceIoControl(
hNLeddrvr, // file handle to the driver
IOCTL_NLED_GETDEVICEINFO, // I/O control code
&nId, // in buffer
sizeof(UINT), // in buffer size
&NledCountInfo, // out buffer
sizeof(NLED_COUNT_INFO), // out buffer size
0, // number of bytes returned
NULL
))
{
g_pKato->Log(NLED_ZONE_ERROR, TEXT("NLeddrvrWorkModeTest- Get number of Notification LED(s) Failed\r\n"));
Debug(TEXT("NLeddrvrWorkModeTest- Get number of Notification LED(s) Failed\r\n"));
CloseHandle(hNLeddrvr);
hNLeddrvr = NULL;
return FALSE;
}
if(!NledCountInfo.cLeds)
{
g_pKato->Log(NLED_ZONE_ERROR, TEXT("NLeddrvrWorkModeTest: System does not support Notification LED\r\n"));
Debug(TEXT("NLeddrvrWorkModeTest: System does not support Notification LED\r\n"));
CloseHandle(hNLeddrvr);
hNLeddrvr = NULL;
return FALSE;
}
cLEds = NledCountInfo.cLeds;
g_pKato->Log(NLED_ZONE_ERROR, TEXT("NLeddrvrWorkModeTest: System supports %d Notification LED(s)\r\n"), cLEds);
Debug(TEXT("NLeddrvrWorkModeTest: System supports %d Notification LED(s)\r\n"), cLEds);
}
//Get System Support Info
{
nId = NLED_SUPPORTS_INFO_ID;
for(UINT i = 0; i < cLEds; i++)
{
NledSupportsInfo[i].LedNum = i;
if(!DeviceIoControl(
hNLeddrvr, // file handle to the driver
IOCTL_NLED_GETDEVICEINFO, // I/O control code
&nId, // in buffer
sizeof(UINT), // in buffer size
&NledSupportsInfo[i], // out buffer
sizeof(NLED_SUPPORTS_INFO), // out buffer size
0, // number of bytes returned
NULL
))
{
g_pKato->Log(NLED_ZONE_ERROR, TEXT("NLeddrvrWorkModeTest: - Get Supports Information for LED%d Failed\r\n"), i);
Debug(TEXT("NLeddrvrWorkModeTest: - Get Supports Information for LED%d Failed\r\n"), i);
CloseHandle(hNLeddrvr);
hNLeddrvr = NULL;
return FALSE;
}
Debug(TEXT("NLeddrvrWorkModeTest - LedNum = %d\r\n"), NledSupportsInfo[i].LedNum);
Debug(TEXT("NLeddrvrWorkModeTest - lCycleAdjust = %d\r\n"), NledSupportsInfo[i].lCycleAdjust);
}
}
//Set NLED On/Off/Blink
{
nId = NLED_SETTINGS_INFO_ID;
for(UINT i=0; i<cLEds; i++) // Set LED(s) to 'On'
{
NledSettingsInfo[i].LedNum = i;
NledSettingsInfo[i].OffOnBlink = OffOnBlink;
NledSettingsInfo[i].OnTime = 1000000; //microseconds
NledSettingsInfo[i].OffTime = 2000000;
if(!DeviceIoControl(
hNLeddrvr, // file handle to the driver
IOCTL_NLED_SETDEVICE, // I/O control code
&NledSettingsInfo[i], // in buffer
sizeof(NLED_SETTINGS_INFO), // in buffer size
NULL, // out buffer
0, // out buffer size
0, // number of bytes returned
NULL
))
{
g_pKato->Log(NLED_ZONE_ERROR, TEXT("NLeddrvrTest.cpp: - Set LED(s) 'On' Failed\r\n"));
Debug(TEXT("NLeddrvrTest.cpp:- Set LED(s) 'On' Failed\r\n"));
CloseHandle(hNLeddrvr);
hNLeddrvr = NULL;
return FALSE;
}
}
if(OffOnBlink == 0)
RetVal = MessageBox(NULL, _T("Press 'Yes' button if LED(s) turned 'Off'. If not, Press 'No' button"),_T( "NLeddrvr 'Off' Test"), MB_ICONQUESTION|MB_YESNO);
else if(OffOnBlink == 1)
RetVal = MessageBox(NULL, _T("Press 'Yes' button if LED(s) turned 'On'. If not, Press 'No' button"),_T( "NLeddrvr 'On' Test"), MB_ICONQUESTION|MB_YESNO);
else if(OffOnBlink == 2)
RetVal = MessageBox(NULL, _T("Press 'Yes' button if LED(s) 'Blink' with 1 secs 'On' period and 2 sec 'Off' period. If not, Press 'No' button"),_T( "NLeddrvr 'Blink' Test"), MB_ICONQUESTION|MB_YESNO);
}
//Turn Off NLED
if(OffOnBlink != 0)
{
nId = NLED_SETTINGS_INFO_ID;
NLED_SETTINGS_INFO NledSettingsInfoOff[NLED_MAX_LED_CETK] = {0, 0, 0, 0, 0, 0, 0};
for(UINT i=0; i<cLEds; i++) // Set LED(s) to 'Off'
{
NledSettingsInfoOff[i].LedNum = i;
NledSettingsInfoOff[i].OffOnBlink = 0;
if(!DeviceIoControl(
hNLeddrvr, // file handle to the driver
IOCTL_NLED_SETDEVICE, // I/O control code
&NledSettingsInfoOff[i], // in buffer
sizeof(NLED_SETTINGS_INFO), // in buffer size
NULL, // out buffer
0, // out buffer size
0, // number of bytes returned
NULL
))
{
g_pKato->Log(NLED_ZONE_ERROR, TEXT("NLeddrvrTest.cpp: NLeddrvrOnTest() - Set LED(s) 'On' Failed\r\n"));
Debug(TEXT("NLeddrvrTest.cpp: NLeddrvrOnTest() - Set LED(s) 'On' Failed\r\n"));
CloseHandle(hNLeddrvr);
hNLeddrvr = NULL;
return FALSE;
}
}
}
if(RetVal == IDNO)
{
CloseHandle(hNLeddrvr);
hNLeddrvr = NULL;
return FALSE;
}
//Close NLED Device
CloseHandle(hNLeddrvr);
hNLeddrvr = NULL;
Debug((TEXT("-%s returning TRUE\r\n"), __WFUNCTION__));
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -