📄 clihnd.c
字号:
/*
Copyright (c) 2002-2006 Vitesse Semiconductor Corporation "Vitesse".
All Rights Reserved. Unpublished rights reserved under the copyright laws
of the United States of America, other countries and international treaties.
The software is provided without a fee. Permission to use, copy, store and
modify, the software and its source code is granted. Permission to integrate
into other products, disclose, transmit and distribute the software in an
absolute machine readable format (e.g. HEX file) is also granted.
The source code of the software may not be disclosed, transmitted or
distributed without the written permission of Vitesse. The software and its
source code may only be used in products utilizing a Vitesse VSC73xx product.
This copyright notice must appear in any copy, modification, disclosure,
transmission or distribution of the software. Vitesse retains all ownership,
copyright, trade secret and proprietary rights in the software.
THIS SOFTWARE HAS BEEN PROVIDED "AS IS," WITHOUT EXPRESS OR IMPLIED WARRANTY
INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR USE AND NON-INFRINGEMENT.
*/
#include <ctype.h>
#include <string.h>
#include "common.h"
#include "hwconf.h"
#include "hwport.h"
#include "h2reg.h"
#include "txt.h"
#include "h2io.h"
#include "uartdrv.h"
#include "main.h"
#include "print.h"
#include "h2.h"
#include "h2mactab.h"
#include "timer.h"
#include "phydrv.h"
#include "phymap.h"
#include "txrxtst.h"
#include "misc1.h"
#include "clihnd.h"
#include "version.h"
#include "hwport.h"
#include "eep.h"
#ifndef NO_DEBUG_IF
/* ************************************************************************ **
*
*
* Defines
*
*
*
* ************************************************************************ */
#define MAX_NO_OF_PARMS 4
#define MAX_CMD_LEN 30
#define FORMAT_OK 0
#define FORMAT_ERROR 1
/* ************************************************************************ **
*
*
* Typedefs and enums
*
*
*
* ************************************************************************ */
/* ************************************************************************ **
*
*
* Prototypes for local functions
*
*
*
* ************************************************************************ */
static uchar handle_command (void);
static void handle_v_command (void);
static uchar retrieve_parms (void);
static void skip_spaces (void);
static uchar cmd_cmp (char *s1, char *s2);
/* ************************************************************************ **
*
*
* Local data
*
*
*
* ************************************************************************ */
static ulong idata parms [MAX_NO_OF_PARMS];
static uchar parms_no;
static uchar xdata cmd_buf [MAX_CMD_LEN];
static uchar xdata *cmd_ptr;
static uchar cmd_len = 0;
/* ************************************************************************ */
void cli_tsk (void)
/* ------------------------------------------------------------------------ --
* Purpose : Handle command line interface.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar error_status;
if (cmd_ready()) {
cmd_ptr = &cmd_buf[0];
skip_spaces();
#if LUTON_UNMANAGED_SWUP
if (cmd_cmp(cmd_ptr, "ERASE") == 0) {
error_status = 0;
}
else if (cmd_cmp(cmd_ptr, "PROGRAM") == 0) {
cmd_ptr += (sizeof("PROGRAM") - 1);
if (retrieve_parms() != FORMAT_OK) {
error_status = FORMAT_ERROR;
}
else if (parms_no != 2) {
error_status = FORMAT_ERROR;
}
else {
eep_download((ushort) parms[0], (ushort) parms[1]);
h2_reset();
}
error_status = 0;
}
else
#endif
error_status = handle_command();
if (error_status) {
/* empty queue */
while (uart_byte_ready()) {
(void) uart_get_byte();
}
print_str(txt_01); /* error message */
}
cmd_len = 0;
}
}
/* ************************************************************************ */
bool cmd_ready (void)
/* ------------------------------------------------------------------------ --
* Purpose : Collect bytes received by uart driver and check if a command
* is ready (i.e. <CR> received).
* Remarks : Returns TRUE, if command is ready, otherwise FALSE.
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar ch;
if (uart_byte_ready()) {
ch = uart_get_byte();
if (ch != 0x0a) { /* discard LF chars */
if (ch == 0x08) { /* handle backspace char */
if (cmd_len > 0) {
cmd_len--;
}
}
else {
if (cmd_len < MAX_CMD_LEN) {
cmd_buf[cmd_len++] = ch;
}
if (ch == 0x0d) {
/* error handling: ensure that CR is present in buffer in case of buffer overflow */
if (cmd_len == MAX_CMD_LEN) {
cmd_buf[MAX_CMD_LEN - 1] = 0x0d;
}
return TRUE;
}
}
}
}
return FALSE;
}
/* ************************************************************************ */
static uchar handle_command (void)
/* ------------------------------------------------------------------------ --
* Purpose : Interpret and handle command (apart from config commands).
* Remarks : Module variable cmd_ptr must have been set to point to first
* non-space char in command string, when this function is called.
* Returns 0, if successful, otherwise <> 0.
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar cmd;
cmd = *cmd_ptr;
cmd_ptr++;
if (retrieve_parms() != FORMAT_OK) {
return FORMAT_ERROR;
}
switch (conv_to_upper_case(cmd)) {
case 'V': /* Get version info */
handle_v_command();
break;
case 'R': /* Read from chip register */
print_hex_prefix();
print_hex_dw(h2_read(parms[0] << 5, parms[1], parms[2]));
print_cr_lf();
break;
case 'W': /* Write to chip register */
if (parms_no >= 4) {
h2_write(parms[0] << 5, parms[1], parms[2], parms[3]);
}
break;
case 'I': /* Read (input) from PHY register */
print_hex_prefix();
print_hex_w(phy_read(parms[0], parms[1]));
print_cr_lf();
break;
case 'O': /* write (output) to PHY register */
if (parms_no >= 3) {
phy_write_masked(parms[0], parms[1], parms[2], parms[3]);
}
break;
#ifndef UNMANAGED_REDUCED_DEBUG_IF
case 'T': /* Tests */
switch ((uchar) parms[0]) {
#if LOOPBACK_TEST
case 1:
perform_tx_rx_test(parms[1], parms[2], 0);
break;
case 2:
perform_tx_rx_test(parms[1], parms[2], 1);
break;
#endif
default:
return FORMAT_ERROR;
//break;
}
break;
#endif
default:
return FORMAT_ERROR;
//break;
}
return FORMAT_OK;
}
/* ************************************************************************ */
static uchar retrieve_parms (void)
/* ------------------------------------------------------------------------ --
* Purpose : Retrieve parameters from command string.
* Remarks : Module variable cmd_ptr must have been set to point to first
* char after the command in the command string, when this function
* is called.
* The module variables parms_no and parms are updated with
* actual number of parameters and the actual parameter values.
* Returns 0, if successful, otherwise <> 0.
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar ch;
uchar base;
uchar j;
uchar no_of_digits;
uchar digits [10];
ulong parm_bin;
ch = *cmd_ptr;
if ((ch != ' ') && (ch != 0x0d)) {
return FORMAT_ERROR;
}
parms_no = 0;
/* Preset parms to ff's, which may be used as default indication */
memset(parms, 0xff, sizeof(parms));
/*
** Retrieve parameters one by one.
*/
for (;;) {
skip_spaces();
base = 10; /* default parameter is specified in decimal */
no_of_digits = 0;
/*
** Check if any hex prefix
*/
if (*cmd_ptr == '0' && (conv_to_upper_case(*(cmd_ptr + 1)) == 'X')) {
base = 16; /* parameter is specified in hex */
cmd_ptr += 2;
if (*cmd_ptr == ' ') {
return FORMAT_ERROR;
}
}
/*
** Retrieve digits until delimiter (space or CR) and then convert
** parameter to binary
*/
for (;;) {
ch = *cmd_ptr;
if ((ch == ' ') || (ch == 0x0d)) {
if (no_of_digits > 0) {
parm_bin = 0;
for (j = 0; j < no_of_digits; j++) {
parm_bin = (parm_bin * base) + digits[j];
}
if (parms_no < MAX_NO_OF_PARMS) {
parms[parms_no++] = parm_bin;
}
}
/* End processing at end of command string */
if (ch == 0x0d) {
return FORMAT_OK;
}
break; /* go get new parameter */
}
else {
ch = ascii_to_hex_nib(ch);
if (ch != 0xff) {
if (no_of_digits < 10) {
digits[no_of_digits++] = ch;
if (ch > 9) {
base = 16; /* parameter is specified in hex */
}
}
}
else {
return FORMAT_ERROR;
}
}
cmd_ptr++;
}
}
}
/* ************************************************************************ */
static void skip_spaces (void)
/* ------------------------------------------------------------------------ --
* Purpose : Adjust cmd_ptr to point to next char different from space.
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
while (*cmd_ptr == ' ') {
cmd_ptr++;
}
}
#if LUTON_UNMANAGED_SWUP
/* ************************************************************************ */
static uchar cmd_cmp (char *s1, char *s2) small
/* ------------------------------------------------------------------------ --
* Purpose : Compare a string in RAM with a 0-terminated string in flash memory.
* Remarks : s1 points to string in RAM, s2 points to string in flash.
* Returns 0 if RAM string is equal to the flash string up till, but
* not including the 0-terminator. Otherwise 1 is returned.
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
uchar ch1;
uchar ch2;
for (;;) {
ch2 = *s2;
if (ch2 == 0) {
return 0;
}
s2++;
ch1 = conv_to_upper_case(*s1++);
if (ch1 != ch2) {
return 1;
}
}
}
#endif
#endif /* NO_DEBUG_IF */
#ifndef NO_DEBUG_IF
/* ************************************************************************ */
static void handle_v_command (void)
/* ------------------------------------------------------------------------ --
* Purpose :
* Remarks :
* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
#ifndef UNMANAGED_REDUCED_DEBUG_IF
uchar port_no;
#endif
/* software version */
print_str(sw_version);
#if JUMBO
print_str(" Jumbo");
#ifndef UNMANAGED_REDUCED_DEBUG_IF
print_spaces(1);
print_dec(JUMBO_SIZE);
#endif
#endif
print_cr_lf();
#ifndef UNMANAGED_REDUCED_DEBUG_IF
/* chip id */
print_str(txt_02);
print_hex_dw(h2_read(SYSTEM, 0, SYS_CHIPID));
print_cr_lf();
/* Info about ports */
print_str(txt_03);
for (port_no = MIN_PORT; port_no < MAX_PORT; port_no++) {
print_dec_8_right_2(port_no);
print_spaces(3);
/* mac address, to be modified */
print_port_mac_addr(port_no);
print_spaces(2);
/* miim and phy number */
print_spaces(1);
print_dec(phy_map_miim_no(port_no));
print_spaces(3);
print_dec_8_right_2(phy_map_phy_no(port_no));
print_cr_lf();
}
#endif
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -