?? ledcli.c
字號(hào):
// LedCLI.c
//////////////////////////////////////////////////////////////////////////////
////
//// Copyright (c) 2003, Valley Technologies, Inc.
//// All rights reserved.
////
//////////////////////////////////////////////////////////////////////////////
////
//// $Header $
////
//// $ReleaseClass: src $
////
//// Original Author : ebersole
//// Most Recent Contributing $Author: ebersole $
////
//////////////////////////////////////////////////////////////////////////////
////
//// This file contains the CLI routines needed for the LED sub-menu.
//// These routine turn the LEDs on & off. They also toggle the LEDs.
//// The low-level dirty work is done by the LED part of the DM642 Library.
////
//////////////////////////////////////////////////////////////////////////////
//############################################################################
// Includes
#include <stdio.h>
#include "dm642_lib.h"
#include "Dm642Cli.h"
//############################################################################
// Function Prototypes
//############################################################################
static void menuReadFpgaLEDReg( DM642_HANDLE hDM642 );
static void menuToggleLEDs( DM642_HANDLE hDM642 );
static void menuTurnOffLEDs( DM642_HANDLE hDM642 );
static void menuTurnOnLEDs( DM642_HANDLE hDM642 );
//############################################################################
// Start of Functions
//############################################################################
//////////////////////////////////////////////////////////////////////////////
////
//// Name: PrintLedSubMenu
////
//// Purpose: Displays the LED Sub-Menu to the screen.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
void PrintLedSubMenu(DM642_HANDLE hDM642)
{
printf ("\n");
printf ("****************** LED Menu ******************\n");
printf ("\n");
printf ("Using board #%d (EVM-DM642)\n", g_dwBoardNum);
printf ("\n");
printf ("1: Read FPGA LED Reg \n");
printf (" \n");
printf ("2: Toggle LEDs \n");
printf ("3: Turn on LEDs \n");
printf ("4: Turn off LEDs \n");
printf (" \n");
printf ("q: Quit \n");
printf (" \n");
printf (">> ");
} // END PrintLedSubMenu()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: RunLedSubMenu
////
//// Purpose: Displays the LED SubMenu. Gets the user's choice
//// from said menu. Processes that choice.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
void RunLedSubMenu(DM642_HANDLE hDM642)
{
char sChoice[80];
int nStatus = 0;
while (TRUE)
{
PrintLedSubMenu(hDM642);
scanf ("%s", sChoice);
printf ("\n");
if (0 == strcmp(sChoice, "1"))
{
menuReadFpgaLEDReg(hDM642);
}
if (0 == strcmp(sChoice, "2"))
{
menuToggleLEDs(hDM642);
}
if (0 == strcmp(sChoice, "3"))
{
menuTurnOnLEDs(hDM642);
}
if (0 == strcmp(sChoice, "4"))
{
menuTurnOffLEDs(hDM642);
}
if (0 == strcmp (sChoice, "q"))
{
break;
}
}
} // END RunLedSubMenu()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: menuReadFpgaLEDReg
////
//// Purpose: Reads the value of the LED Register on the FPGA.
//// Prints/Displays that value.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
static void menuReadFpgaLEDReg( DM642_HANDLE hDM642 )
{
int nStatus = kNoError;
unsigned nVal = 0;
if (kNoError == nStatus)
{
// Read in the current state of LED register
DM642ReadFpgaReg(hDM642, kFamrOffs_LEDR, &nVal);
}
if (kNoError == nStatus)
{
// Display the read-in state of the LED register.
printf("FPGA LED Reg: 0x%02x\n", nVal);
}
} // END menuReadFpgaLEDReg()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: menuToggleLEDs
////
//// Purpose: This routine gets input from the user re. which LED's to toggle
//// The routine then toggles those LEDs.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
static void menuToggleLEDs( DM642_HANDLE hDM642 )
{
int nStatus = kNoError;
unsigned nLedMask = 0;
unsigned nVal = 0;
unsigned nNewVal = 0;
while (kNoError == nStatus)
{
//-----------------------------------------------------
// Get input from the user (which LEDs to toggle) ...
//-----------------------------------------------------
if (kNoError == nStatus)
{
nStatus = getInt("LEDs to toggle (or q) >> ", "%x", &nLedMask);
}
//---------------------------------------------------------
// If no input error, nor QUIT, toggle the indicated LEDs
//---------------------------------------------------------
if (kNoError == nStatus)
{
// Read in the current state of LED register
DM642ReadFpgaReg(hDM642, kFamrOffs_LEDR, &nVal);
// Toggle the indicated LEDs
nNewVal = nVal ^ nLedMask;
printf("FPGA LED Reg: 0x%02x => 0x%02x\n", nVal, nNewVal);
// Write the new state out to the LED register
DM642WriteFpgaReg(hDM642, kFamrOffs_LEDR, nNewVal);
}
}
} // END menuToggleLEDs()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: menuTurnOffLEDs
////
//// Purpose: This routine gets input from the user re. which LED's to
//// turn off. The routine then turns off those LEDs.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
static void menuTurnOffLEDs( DM642_HANDLE hDM642 )
{
int nStatus = kNoError;
unsigned nLedMask = 0;
unsigned nVal = 0;
unsigned nNewVal = 0;
while (kNoError == nStatus)
{
//-----------------------------------------------------
// Get input from the user (which LEDs to turn off)
//-----------------------------------------------------
if (kNoError == nStatus)
{
nStatus = getInt("LEDs to turn off (or q) >> ", "%x", &nLedMask);
}
//-----------------------------------------------------------
// If no input error, nor QUIT, turn off the indicated LEDs
//-----------------------------------------------------------
if (kNoError == nStatus)
{
// Read in the current state of LED register
DM642ReadFpgaReg(hDM642, kFamrOffs_LEDR, &nVal);
// Turn off the indicated LEDs
nNewVal = nVal | nLedMask;
printf("FPGA LED Reg: 0x%02x => 0x%02x\n", nVal, nNewVal);
// Write the new state out to the LED register
DM642WriteFpgaReg(hDM642, kFamrOffs_LEDR, nNewVal);
}
}
} // END menuTurnOffLEDs()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: menuTurnOnLEDs
////
//// Purpose: This routine gets input from the user re. which LED's to
//// turn on. The routine then turns off those LEDs.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
static void menuTurnOnLEDs( DM642_HANDLE hDM642 )
{
int nStatus = kNoError;
unsigned nLedMask = 0;
unsigned nVal = 0;
unsigned nNewVal = 0;
while (kNoError == nStatus)
{
//-----------------------------------------------------
// Get input from the user (which LEDs to turn on)
//-----------------------------------------------------
if (kNoError == nStatus)
{
nStatus = getInt("LEDs to turn on (or q) >> ", "%x", &nLedMask);
}
//-----------------------------------------------------------
// If no input error, nor QUIT, turn off the indicated LEDs
//-----------------------------------------------------------
if (kNoError == nStatus)
{
// Read in the current state of LED register
DM642ReadFpgaReg(hDM642, kFamrOffs_LEDR, &nVal);
// Turn on the indicated LEDs
nNewVal = nVal & (~nLedMask);
printf("FPGA LED Reg: 0x%02x => 0x%02x\n", nVal, nNewVal);
// Write the new state out to the LED register
DM642WriteFpgaReg(hDM642, kFamrOffs_LEDR, nNewVal);
}
}
} // END menuTurnOnLEDs()
//############################################################################
// End of Functions
//############################################################################
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -