?? flashcli.c
字號:
// FlashCLI.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 Flash sub-menu.
//// These routines reset the flash, erase the flash or a single page of
//// flash, and copy flash contents to/from files.
//// The low-level dirty work is done by the DM642 Library.
////
//////////////////////////////////////////////////////////////////////////////
//############################################################################
// Includes
#include <stdio.h>
#include "dm642_lib.h"
#include "Dm642Cli.h"
//############################################################################
// Function Prototypes
//############################################################################
static void eraseFlashPage ( DM642_HANDLE hDM642 );
static void readFlashPagesToFile ( DM642_HANDLE hDM642 );
static void readFlashPagesToBinFile( DM642_HANDLE hDM642 );
static void writeFlashPagesFromFile( DM642_HANDLE hDM642, BOOL fUseBinaryFile );
//############################################################################
// Start of Functions
//############################################################################
//////////////////////////////////////////////////////////////////////////////
////
//// Name: PrintFlashSubMenu
////
//// Purpose: Displays the Flash Sub-Menu to the screen.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
void PrintFlashSubMenu(DM642_HANDLE hDM642)
{
extern DWORD g_dwBoardNum;
printf ("\n");
printf ("********************* Flash Menu *******************\n");
printf ("\n");
printf ("Using board #%d (EVM-DM642)\n", g_dwBoardNum);
printf ("\n");
printf ("1: Reset flash \n");
printf ("2: Erase flash Page(s) \n");
printf ("3: Erase flash \n");
printf (" \n");
printf ("4: Read flash pages to ASC file \n");
printf ("5: Read flash pages to BIN file \n");
printf (" \n");
printf ("6: Write flash pages from ASC file \n");
printf ("7: Write flash pages from BIN file \n");
printf (" \n");
printf ("q: Quit \n");
printf (" \n");
printf (">> ");
} // END PrintFlashSubMenu()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: RunFlashSubMenu
////
//// Purpose: Displays the Flash 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 RunFlashSubMenu(DM642_HANDLE hDM642)
{
char sChoice[80];
int nStatus = 0;
while (TRUE)
{
unsigned int nVal1 = 0;
unsigned int nVal2 = 0;
//------------------------
// Print the sub-menu
//------------------------
PrintFlashSubMenu(hDM642);
//--------------------------
// Get the user's choice
//--------------------------
scanf ("%s", sChoice);
printf ("\n");
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Process the user's choice ...
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if (0 == strcmp(sChoice, "1"))
{
printf("Flash reset %s\n",
(kNoError == DM642FlashReset(hDM642)) ? "passed"
: "FAILED!");
}
if (0 == strcmp(sChoice, "2"))
{
eraseFlashPage(hDM642);
}
if (0 == strcmp(sChoice, "3"))
{
DM642FlashErase(hDM642);
}
if (0 == strcmp(sChoice, "4"))
{
readFlashPagesToFile(hDM642);
}
if (0 == strcmp(sChoice, "5"))
{
readFlashPagesToBinFile(hDM642);
}
if (0 == strcmp(sChoice, "6"))
{
writeFlashPagesFromFile(hDM642, TRUE);
}
if (0 == strcmp(sChoice, "7"))
{
writeFlashPagesFromFile(hDM642, FALSE);
}
//----------------------------------------------------
// The QUIT choice. Choosing this exits the submenu
//----------------------------------------------------
if (0 == strcmp (sChoice, "q"))
{
break;
}
}
} // END RunFlashSubMenu()
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: eraseFlashPage
////
//// Purpose: Erases a Page of the EVM-DM642's flash memory. The user is
//// prompted for, and supplies, the number of the page (0-7) to
//// erase.
////
//// A flash page on the EVM-DM642 is 1/8 of the total flash
//// memory. It contains 8 full sectors. And is 512 KB.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
static void eraseFlashPage( DM642_HANDLE hDM642 )
{
int nStatus = kNoError;
unsigned int nPage = 0;
if (kNoError == nStatus)
{
nStatus = getInt("Enter Page # (0-7), or q >> ", "%d",
&nPage);
}
if (kNoError == nStatus)
{
nStatus = DM642FlashErasePage(hDM642, nPage);
}
if (CHOICE_Q != nStatus)
{
printf("Page Erase %s\n",
(kNoError == nStatus) ? "passed" : "FAILED!");
}
} // END eraseFlashPage()
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: readFlashPagesToFile
////
//// Purpose: Reads a page of flash memory and writes it to an ASCII file.
//// The user is prompted for, and provides, the file name and the
//// page number. The user can choose an ALL_PAGES option, which
//// will copy all 8 of the flash page to the file _in order_
//// (ie, it will copy page 0, then page 1, etc).
////
//// A flash page on the EVM-DM642 is 1/8 of the total flash
//// memory. It contains 8 full sectors. And is 512 KB.
//// [Thus, copying ALL pages creates an ~12 MB ASCII file]
////
//// Input Parameters:
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -