📄 dbgmenu.c
字号:
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This software is copyrighted by and is the sole property of
* VIA Networking Technologies, Inc. This software may only be used
* in accordance with the corresponding license agreement. Any unauthorized
* use, duplication, transmission, distribution, or disclosure of this
* software is expressly forbidden.
*
* This software is provided by VIA Networking Technologies, Inc. "as is"
* and any express or implied warranties, including, but not limited to, the
* implied warranties of merchantability and fitness for a particular purpose
* are disclaimed. In no event shall VIA Networking Technologies, Inc.
* be liable for any direct, indirect, incidental, special, exemplary, or
* consequential damages.
*
*
* File: dbgmenu.c
*
* Purpose: Debugging menu to support basic hardward accessing
*
* Author: Jenda Jao
*
* Date: Jan 08, 2002
*
* Functions:
*
* Revision History:
*
*/
#if !defined(__ASCII_H__)
#include "ascii.h"
#endif
#if !defined(__KEY_H__)
#include "key.h"
#endif
#if !defined(__STR_H__)
#include "str.h"
#endif
#if !defined(__UART_H__)
#include "uart.h"
#endif
#if !defined(__SWITCH_H__)
#include "switch.h"
#endif
#if !defined(__SWREG_H__)
#include "swreg.h"
#endif
#if !defined(__NVRAM_H__)
#include "nvram.h"
#endif
#if !defined(__SWSRAM_H__)
#include "swsram.h"
#endif
#include "swmii.h"
#include "tty.h"
#if !defined(__SWMODL_H__)
#include "swmodl.h"
#endif
#if !defined(__SWEEP_H__)
#include "sweep.h"
#endif
/*--------------------- Static Definitions -------------------------*/
/*--------------------- Static Macros -----------------------------*/
#define DBGMENU_BAR_CLEAR() do { TTY_vRevChar(); TTY_vDrawLine(21, 2, ' ',78); TTY_vRstChar(); } while (0)
#define DBGMENU_BAR_PRINT(col, str) do { TTY_vPutStrOnPos(21, col, str); } while (0)
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
/*--------------------- Static Functions --------------------------*/
static void s_vSwitchRegMenu(void);
static void s_vPhyRegMenu(void);
static void s_vEepromMenu(void);
static void s_vSramMenu(void);
static void s_vModEEPMenu(void);
static void s_vBoardEEPMenu(void);
static UINT32 s_u32GetHexValue(UINT8 byMaxDigiCnt, PBOOL pbInput);
/*--------------------- Export Variables --------------------------*/
/*--------------------- Export Functions --------------------------*/
void DBGvMainMenu(void)
{
while (1) {
TTY_vRstChar();
TTY_vClearScrn();
TTY_vPutStrOnPos(2,30,"Debug Menu");
TTY_vDrawLine(3,30,'=',10);
TTY_vPutStrOnPos(8,30,"Command < >");
DBGMENU_BAR_CLEAR();
TTY_vPutStrOnPos(22,2,"<1> Switch Reg <2> Phy Reg <3> NVRAM <4> TABLE <5> ModEEP <6> BoardEEP <E> Exit");
TTY_vPutStrOnPos(23,2,"* All inputs should be HEX strings.");
TTY_vSetCurPos(8,39);
switch (TTY_cGetChar()) {
case 'e':
case 'E':
return;
case '1':
s_vSwitchRegMenu();
break;
case '2':
s_vPhyRegMenu();
break;
case '3':
s_vEepromMenu();
break;
case '4':
s_vSramMenu();
break;
case '5':
s_vModEEPMenu();
break;
case '6':
s_vBoardEEPMenu();
break;
}
}
}
static void s_vSwitchRegMenu(void)
{
BOOL bInput;
UINT16 wRegAddr;
UINT8 byOp, byRegData;
while (1) {
// get input
TTY_vPutStrOnPos(8, 30, "Switch Reg Addr [ ]");
TTY_vPutStrOnPos(9, 30, "Switch Reg Data [ ]");
TTY_vPutStrOnPos(10,30, "Operation (R/W/L/E)< >");
TTY_vSetCurPos(8,47);
wRegAddr = s_u32GetHexValue(4, &bInput);
TTY_vSetCurPos(8,47);
TTY_vPutHex(wRegAddr);
TTY_vSetCurPos(9,49);
byRegData = s_u32GetHexValue(2, &bInput);
TTY_vSetCurPos(9,49);
TTY_vPutHex(byRegData);
TTY_vSetCurPos(10,50);
byOp = TTY_cGetChar();
switch (byOp) {
case 'e':
case 'E':
return;
case 'w':
case 'W':
//TTY_vSetCurPos(11,10);
//TTY_vPutHex(wRegAddr);
//TTY_vPutHex(byRegData);
SWREG_vWriteU8(wRegAddr, byRegData);
break;
case 'r':
case 'R':
break;
case 'l':
case 'L': {
UINT8 ui, byData;
for (ui=13; ui<17; ui++)
TTY_vDrawLine(ui,1,' ',80);
TTY_vSetCurPos(13,1);
for (ui=0; ui<byRegData; ui++)
{
SWREG_vReadU8(wRegAddr+ui, &byData);
UART_vPutChar('<');
TTY_vPutHex(wRegAddr+ui);
UART_vPutChar(':');
TTY_vPutHex(byData);
UART_vPutChar('>');
}
} break;
default:
TTY_vDrawLine(12,30,' ',30);
continue;
}
// print result
SWREG_vReadU8(wRegAddr, &byRegData);
//TTY_vSetCurPos(12,10);
//TTY_vPutHex(wRegAddr);
//TTY_vPutHex(byRegData);
TTY_vDrawLine(12,30,' ',30);
TTY_vSetCurPos(12,30);
TTY_vPutStr("Addr (");
TTY_vPutHex(wRegAddr);
TTY_vPutStr(") Data (");
TTY_vPutHex(byRegData);
UART_vPutChar(')');
}
}
static void s_vPhyRegMenu(void)
{
BOOL bInput;
UINT8 byOp, byPortId, byRegAddr;
UINT16 wRegData;
while (1) {
// get input
TTY_vPutStrOnPos(7, 30, "Port Id (0-based)[ ]");
TTY_vPutStrOnPos(8, 30, "Phy Reg Addr [ ]");
TTY_vPutStrOnPos(9, 30, "Phy Reg Data [ ]");
TTY_vPutStrOnPos(10,30, "Operation (R/W/E) < >");
TTY_vSetCurPos(7,49);
byPortId = s_u32GetHexValue(2, &bInput);
TTY_vSetCurPos(7,49);
TTY_vPutHex(byPortId);
TTY_vSetCurPos(8,49);
byRegAddr = s_u32GetHexValue(2, &bInput);
TTY_vSetCurPos(8,49);
TTY_vPutHex(byRegAddr);
TTY_vSetCurPos(9,47);
wRegData = s_u32GetHexValue(4, &bInput);
TTY_vSetCurPos(9,47);
TTY_vPutHex(wRegData);
TTY_vSetCurPos(10,50);
byOp = TTY_cGetChar();
switch (byOp) {
case 'e':
case 'E':
return;
case 'w':
case 'W':
SWMII_bWriteU16(byPortId, byRegAddr, wRegData);
case 'r':
case 'R':
break;
default:
TTY_vDrawLine(12,26,' ',30);
continue;
}
// read current value and print result
SWMII_bReadU16(byPortId, byRegAddr, &wRegData);
TTY_vDrawLine(12,26,' ',30);
TTY_vSetCurPos(12,26);
TTY_vPutStr("Port (");
TTY_vPutHex(byPortId);
TTY_vPutStr(") Addr (");
TTY_vPutHex(byRegAddr);
TTY_vPutStr(") Data (");
TTY_vPutHex(wRegData);
UART_vPutChar(')');
}
}
static void s_vEepromMenu(void)
{
BOOL bInput;
UINT8 byOp, byEepData;
UINT16 wEepAddr;
while (1) {
// get input
TTY_vPutStrOnPos(7, 30, "Eeprom Addr [ ]");
TTY_vPutStrOnPos(8, 30, "Eeprom Data [ ]");
TTY_vPutStrOnPos(9, 30, "Operation(R/W/L/E)< >");
TTY_vSetCurPos(7,46);
wEepAddr = s_u32GetHexValue(4, &bInput);
TTY_vSetCurPos(7,46);
TTY_vPutHex(wEepAddr);
TTY_vSetCurPos(8,48);
byEepData = s_u32GetHexValue(2, &bInput);
TTY_vSetCurPos(8,48);
TTY_vPutHex(byEepData);
TTY_vSetCurPos(9,49);
byOp = TTY_cGetChar();
switch (byOp) {
case 'e':
case 'E':
return;
case 'w':
case 'W':
NVRAM_bWriteU8(wEepAddr, byEepData);
case 'r':
case 'R':
break;
case 'l':
case 'L': {
UINT8 ui, byData;
for (ui=13; ui<17; ui++)
TTY_vDrawLine(ui,1,' ',80);
TTY_vSetCurPos(13,1);
for (ui=0; ui<byEepData; ui++) {
NVRAM_bReadU8(wEepAddr+ui, &byData);
UART_vPutChar('<');
TTY_vPutHex(wEepAddr+ui);
UART_vPutChar(':');
TTY_vPutHex(byData);
UART_vPutChar('>');
}
} break;
default:
TTY_vDrawLine(11,30,' ',30);
continue;
}
// read current value and print result
NVRAM_bReadU8(wEepAddr, &byEepData);
TTY_vDrawLine(11,30,' ',30);
TTY_vPutStrOnPos(11,30,"Addr (");
TTY_vPutHex(wEepAddr);
TTY_vPutStr(") Data (");
TTY_vPutHex(byEepData);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -