📄 leds.c
字号:
/******************************************************************************
**
** COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
** This software as well as the software described in it is furnished under
** license and may only be used or copied in accordance with the terms of the
** license. The information in this file is furnished for informational use
** only, is subject to change without notice, and should not be construed as
** a commitment by Intel Corporation. Intel Corporation assumes no
** responsibility or liability for any errors or inaccuracies that may appear
** in this document or any software that may be provided in association with
** this document.
** Except as permitted by such license, no part of this document may be
** reproduced, stored in a retrieval system, or transmitted in any form or by
** any means without the express written consent of Intel Corporation.
**
** FILENAME: LEDs.c
**
** PURPOSE: This file implements the LED specific test routines.
**
** $LAST MODIFIED: 02/16/2001
******************************************************************************/
/*
*******************************************************************************
* HEADER FILES
*******************************************************************************
*/
#include <stdio.h>
#include "systypes.h"
#include "timedelays.h"
#include "boardControl.h"
#include "xsuart.h"
#include "DM_SerialInOut.h"
#include "dm_errors.h"
#include "DM_Debug.h"
#include "LEDsAPI.h"
static
void DisplayLeftHexSwSetings(void)
{
UINT32 value;
value = (ReadUserSwitches() & LEFT_HEX_SW_MASK) >> 4;
// Write to the LEDs
BlankHexLeds(HEX_LED0_ON);
WriteHexLeds(value);
}
static
void DisplayRightHexSwSetings(void)
{
UINT32 value;
value = ReadUserSwitches() & RIGHT_HEX_SW_MASK;
// Write to the LEDs
BlankHexLeds(HEX_LED0_ON);
WriteHexLeds(value);
}
/*
*******************************************************************************
*
* FUNCTION:
* PostHexSwitchesTest
*
* DESCRIPTION:
* Display a hex value on the LEDs.
* SW5 hex switch is used to select hex leds U19-U24 (LED 0-7),
* SW9 hex switch to is used to select a value that will be displayed
*
* INPUT PARAMETERS:
* None.
*
* RETURNS:
* UINT32 errors
*
* GLOBAL EFFECTS:
* The LEDs are cleared at the end of the test.
*
* ASSUMPTIONS:
* None.
*
* CALLS:
* None.
*
* CALLED BY:
* None.
*
* PROTOTYPE:
* UINT32 PostHexSwitchesTest(VOID);
*
*******************************************************************************
*/
UINT32 PostHexSwitchesTest(VOID)
{
BOOL testFlag;
UINT32 status = 0, errorCount = 0, currValue;
INT timeout = HEX_SW_TIMEOUT, i;
INT leftHexSw, rightHexSw;
UINT32 savedHexSw;
HexSwitchesT readSwTable[16] = {0x0,0,0x1,0,0x2,0,0x3,0,
0x4,0,0x5,0,0x6,0,0x7,0,
0x8,0,0x9,0,0xA,0,0xB,0,
0xC,0,0xD,0,0xE,0,0xF,0};
printf(" Testing HEX Switches\r\n");
// Blank the hex LEDs
BlankHexLeds(BLANK_ALL_HEX_LEDS);
DM_WaitMs(200);
// Save the current HEX switches settings
savedHexSw = ReadUserSwitches() & 0xFF;
// Ask user to rotate left hex switch SW5 one full revolution
printf (" User! Rotate left HEX switch one full revolution after you continue\r\n");
GetUserResponse(YES);
// Wait for the user to set HEX switches
while (--timeout > 0)
{
leftHexSw = ReadUserSwitches() & LEFT_HEX_SW_MASK;
DM_WaitMs(100);
currValue = leftHexSw >> 4;
// Mark as seen value in the readSwTable table
readSwTable[currValue].flag = TRUE;
// Write to the LED 0
BlankHexLeds(HEX_LED0_ON);
WriteHexLeds(currValue);
// UartKeepAlive();
// Check if we have seen all values in the table
testFlag = TRUE;
for (i = 0; i < 16; ++i)
{
testFlag &= readSwTable[i].flag;
}
if (testFlag)
break;
}
if (timeout <= 0)
{
// Output error
status = ERRORCODEX(ERR_L_HEXSW,
1, 1,
ERR_T_WRONG_VALUE);
XllpUtilityOutputError(status);
++errorCount;
}
// Prompt user to restore an original switch settings
printf (" User! Please set left HEX Switch back to %X\r\n",
((savedHexSw & LEFT_HEX_SW_MASK) >> 4));
GetUserResponseCallAction(YES, DisplayLeftHexSwSetings);
// Check if the switches settings were restored
currValue = ReadUserSwitches() & LEFT_HEX_SW_MASK;
if ((savedHexSw & LEFT_HEX_SW_MASK) != currValue)
{
// Output error
status = ERRORCODEX(ERR_L_HEXSW,
1, 2,
ERR_T_WRONG_VALUE);
XllpUtilityOutputError(status);
++errorCount;
}
// Test right hex switch SW9
if (!status)
{
// Blank the hex LEDs
BlankHexLeds(BLANK_ALL_HEX_LEDS);
// Ask user to rotate right hex switch SW9 one full revolution
printf (" User! Rotate right HEX switch one full revolution after you continue\r\n");
GetUserResponse(YES);
// Clear all of the flags in the table
for (i = 0; i < 16; ++i)
{
readSwTable[i].flag = 0;
}
// Wait for the user to set HEX switches
timeout = HEX_SW_TIMEOUT;
while (--timeout > 0)
{
rightHexSw = ReadUserSwitches() & RIGHT_HEX_SW_MASK;
DM_WaitMs(100);
currValue = rightHexSw;
// Mark as seen value in the readSwTable table
readSwTable[currValue].flag = TRUE;
// Write to the LED 0
BlankHexLeds(HEX_LED0_ON);
WriteHexLeds(currValue);
// UartKeepAlive();
// Check if we have seen all values in the table
testFlag = TRUE;
for (i = 0; i < 16; ++i)
{
testFlag &= readSwTable[i].flag;
}
if (testFlag)
break;
}
if (timeout <= 0)
{
// Output error
status = ERRORCODEX(ERR_L_HEXSW,
1, 3,
ERR_T_WRONG_VALUE);
XllpUtilityOutputError(status);
++errorCount;
}
// Prompt user to restore an original switch settings
printf (" User! Please set right HEX Switch back to %X\r\n",
(savedHexSw & RIGHT_HEX_SW_MASK));
GetUserResponseCallAction(YES, DisplayRightHexSwSetings);
// Check if the switches settings were restored
currValue = ReadUserSwitches() & RIGHT_HEX_SW_MASK;
if ((savedHexSw & RIGHT_HEX_SW_MASK) != currValue)
{
// Output error
status = ERRORCODEX(ERR_L_HEXSW,
1, 4,
ERR_T_WRONG_VALUE);
XllpUtilityOutputError(status);
++errorCount;
}
}
// Report result of the test
if (!status)
{
printf (" Success!\r\n");
}
// Blank the hex LEDs
BlankHexLeds(BLANK_ALL_HEX_LEDS);
// Write zeros to the hex LEDs before leaving the test
BlankHexLeds(ALL_HEX_LEDS_ON);
WriteHexLeds(0x0);
return errorCount;
}
VOID PostHexSwitchesTestCmd (PVOID ctxp, PCHAR param)
{
PostHexSwitchesTest();
}
/*
*******************************************************************************
*
* FUNCTION:
* PostHexLEDsTest
*
* DESCRIPTION:
* Display a hex value on the LEDs.
* SW5 hex switch is used to select hex leds U19-U24 (LED 0-7),
* SW9 hex switch to is used to select a value that will be displayed
*
* INPUT PARAMETERS:
* None.
*
* RETURNS:
* UINT32 errors
*
* GLOBAL EFFECTS:
* The LEDs are cleared at the end of the test.
*
* ASSUMPTIONS:
* None.
*
* CALLS:
* None.
*
* CALLED BY:
* None.
*
* PROTOTYPE:
* UINT32 PostHexLEDsTest(VOID);
*
*******************************************************************************
*/
UINT32 PostHexLEDsTest(VOID)
{
BOOL responce;
UINT32 status = 0, errorCount = 0;
INT i;
const UINT mask[16] = { 0x00000000, 0x11111111, 0x22222222, 0x33333333,
0x44444444, 0x55555555, 0x66666666, 0x77777777,
0x88888888, 0x99999999, 0xAAAAAAAA, 0xBBBBBBBB,
0xCCCCCCCC, 0xDDDDDDDD, 0xEEEEEEEE, 0xFFFFFFFF };
printf(" Testing HEX LEDs\r\n");
// Prompt user to watch HEX LEDs
printf (" User! Please watch HEX LEDs\r\n");
responce = GetUserResponse(YES);
for (i = 0; i < 16; i++)
{
// Write to the LEDs
WriteHexLeds(mask[i]);
DM_WaitMs(1000);
}
// Write zeros to the hex LEDs
BlankHexLeds(ALL_HEX_LEDS_ON);
WriteHexLeds(0x0);
printf (" User! Have all digits been displayed on HEX LEDs\r\n");
responce = GetUserResponse(YESNO);
if (!responce)
{
// Output error
status = ERRORCODEX(ERR_L_HEXLEDS,
1, 1,
ERR_T_WRONG_VALUE);
XllpUtilityOutputError(status);
++errorCount;
}
if (responce)
{
// Prompt user to watch walking '8' on HEX LEDs
printf (" User! Please watch for walking '8' on HEX LEDs\r\n");
responce = GetUserResponse(YES);
// Display walking '8'
for (i = 0; i < 8; i++)
{
UINT value = 8;
// Write to the LEDs
BlankHexLeds(~(1u << i));
WriteHexLeds(value << (i << 2));
DM_WaitMs(800);
}
// Write zeros to the hex LEDs
BlankHexLeds(ALL_HEX_LEDS_ON);
WriteHexLeds(0x0);
printf (" User! Have walking '8' been displayed on all HEX LEDs\r\n");
responce = GetUserResponse(YESNO);
if (!responce)
{
// Output error
status = ERRORCODEX(ERR_L_HEXLEDS,
1, 2,
ERR_T_WRONG_VALUE);
XllpUtilityOutputError(status);
++errorCount;
}
}
// Write zeros to the hex LEDs before leaving the test
BlankHexLeds(ALL_HEX_LEDS_ON);
WriteHexLeds(0x0);
// Report result of the test
if (status)
{
return errorCount;
}
else
{
printf (" Success!\r\n");
return errorCount;
}
}
VOID PostHexLEDsTestCmd (PVOID ctxp, PCHAR param)
{
PostHexLEDsTest();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -