📄 command.c
字号:
/*-------------------------------------------------------------------
FILE NAME:
command.c
DESCRIPTION:
this file includes command parse functions.
AUTHOR:
WYF
VERSION:
2005.1122.00
COMPANY:
DATANG MICROELECTRONICS TECHNOLOGY CO,.LTD
HISTORY:
2005.1122 Creat this file
...
--------------------------------------------------------------------*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "nucleus.h"
#include "ADSmx21_defs.h"
#include "drv_defs.h"
#include "drv_extr.h"
#include "console.h"
extern int processing;
#define CMD_TBL_TEST MK_CMD_TBL_ENTRY( \
"test", 4, 6, 1, do_test, \
" test - test function\n", \
" [:)] \n" \
)
#define CMD_TBL_HELP MK_CMD_TBL_ENTRY( \
"help", 4, CFG_MAXARGS, 1, do_help, \
" help - print online help\n", \
"[command ...]\n" \
" - show help information (for 'command')\n" \
"'help' prints online help for the monitor commands.\n\n" \
"Without arguments, it prints a short usage message for all commands.\n\n" \
"To get detailed help information for specific commands you can type\n" \
"'help' with one or more command names as arguments.\n" \
)
#define CMD_TBL_QUES MK_CMD_TBL_ENTRY( \
"?", 1, CFG_MAXARGS, 1, do_help, \
" ? - alias for 'help'\n", \
NULL \
)
#define CMD_TBL_VERS MK_CMD_TBL_ENTRY( \
"ver", 3, 1, 1, do_version, \
" ver - print monitor version\n", \
NULL \
)
#define CMD_TBL_BOOT MK_CMD_TBL_ENTRY( \
"boot", 4, 2, 1, do_boot, \
" boot - boot system from address\n", \
" [address]\n" \
" - default boot from 0xc0800000\n" \
)
#define CMD_TBL_PARAM MK_CMD_TBL_ENTRY( \
"param", 5, 6, 1, do_param, \
" param - show and set system boot parameters \n", \
" [set|show] [parameters] \n" \
)
#define CMD_TBL_TFTPR MK_CMD_TBL_ENTRY( \
"tftpr", 5, 2, 1, do_tftpr, \
" tftpr - start tftp receive process at address \n", \
" [address] \n" \
" - default to 0xc2200000\n" \
)
#define CMD_TBL_FLASH MK_CMD_TBL_ENTRY( \
"flash", 5, 4, 1, do_flash, \
" flash - program or erase flash memory \n", \
" [op] [addr] [length]\n" \
" op - [p|e] program/erase\n" \
" address - destination address\n" \
" length - data length (number of bytes) \n" \
)
#define CMD_TBL_NONE MK_CMD_TBL_ENTRY( \
NULL, 0, 0, 0, NULL, NULL, NULL )
int do_test (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
short *src, *des;
char *addr;
unsigned int num;
if (argc < 3){
goto error;
}
addr = argv[2];
if ((*addr == '0')&&((*(addr+1) == 'x')||(*(addr+1) == 'X'))){
num = strtoul(addr+2, &addr, 16);
}
else{
goto error;
}
addr = argv[1];
if (*addr == 'd'){
console_deactive();
src = (short *)num;
des = (short *)LCDC_ROTATION_BUF;
memcpy(des,src,320*240*2);
RGB_320x240_to_240x320(LCDC_ROTATION_BUF,LCDC_MAINWINDOW);
while(processing){
NU_Sleep(50);
}
}
return 0;
error:
mputs (cmdtp->name);
mputc (' ');
mputs (cmdtp->help);
return -1;
}
int do_version (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
extern char version_string[];
printf ("\n%s\n", version_string);
return 0;
}
/*
* Use puts() instead of printf() to avoid printf buffer overflow
* for long help messages
*/
int do_help (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int i;
if (argc == 1) { /* print short help (usage) */
for (cmdtp=&cmd_tbl[0]; cmdtp->name; cmdtp++) {
if (cmdtp->usage == NULL)
continue;
mputs (cmdtp->usage);
}
return 0;
}
/*
* command help (long version)
*/
for (i=1; i<argc; ++i) {
if ((cmdtp = find_cmd(argv[i])) != NULL) {
/* found - print (long) help info */
mputs (cmdtp->name);
mputc (' ');
if (cmdtp->help) {
mputs (cmdtp->help);
} else {
mputs ("- No help available.\n");
}
mputc ('\n');
}
else {
printf ("Unknown command '%s' - try 'help'"
" without arguments for list of all"
" known commands\n\n",
argv[i]
);
}
}
return 0;
}
int do_boot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
typedef void func(void);
func *bootf;
char *addr;
int des;
if (argc < 2){
des = 0xc0800000;
}
else{
addr = argv[1];
if ((*addr == '0')&&((*(addr+1) == 'x')||(*(addr+1) == 'X'))){
des = strtoul(addr+2, &addr, 16);
}
else{
printf("\n%s\n",cmdtp->usage);
return -1;
}
}
bootf = (func *)des;
(*bootf)();
return 0;
}
int do_param (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
extern TPARAM bootparam;
if ((argc < 2)){
printf("\n%s\n",cmdtp->usage);
return -1;
}
if (strcmp(argv[1],"show") == 0){
if (argc == 2){
printf("[0] boot delay : %d seconds\n", bootparam.bootdelay);
printf("[1] Phicsial address : %s\n", bootparam.macaddr);
printf("[2] IP address : %s\n", bootparam.ipaddr);
printf("[3] Subnet mask : %s\n", bootparam.netmask);
}
else if (*(argv[2]) == '0'){
printf("[0] boot delay : %d seconds\n", bootparam.bootdelay);
}
else if (*(argv[2]) == '1'){
printf("[1] Phisical address : %s\n", bootparam.macaddr);
}
else if (*(argv[2]) == '2'){
printf("[2] IP address : %s\n", bootparam.ipaddr);
}
else if (*(argv[2]) == '3'){
printf("[3] Subnet mask : %s\n", bootparam.netmask);
}
else{
printf("\n%s\n",cmdtp->usage);
return -1;
}
}
else if (strcmp(argv[1],"set") == 0){
if (argc < 4){
printf("\n%s\n",cmdtp->usage);
return -1;
}
else if (*(argv[2]) == '0'){
bootparam.bootdelay = atoi(argv[3]);
}
else if (*(argv[2]) == '1'){
strncpy(bootparam.macaddr,argv[3],18);
}
else if (*(argv[2]) == '2'){
strncpy(bootparam.ipaddr,argv[3],16);
}
else if (*(argv[2]) == '3'){
strncpy(bootparam.netmask,argv[3],16);
}
else{
printf("\n%s\n",cmdtp->usage);
return -1;
}
}
return 0;
}
int do_tftpr (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
extern int tftpserver;
extern int tftprecvaddr;
char *addr;
int des;
if (argc < 2){
des = TFTP_DATA_BASE;
}
else{
addr = argv[1];
if ((*addr == '0')&&((*(addr+1) == 'x')||(*(addr+1) == 'X'))){
des = strtoul(addr+2, &addr, 16);
}
else{
printf("\n%s\n",cmdtp->usage);
return -1;
}
}
printf("Receiving at 0x%08x\n", des);
tftprecvaddr = des;
tftpserver = 1;
while(processing){
NU_Sleep(50);
}
tftpserver = 0;
return 0;
}
int do_flash (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
char *addr;
unsigned int des, len;
int i;
if (argc != 4){
goto error;
}
addr = argv[2];
if ((*addr == '0')&&((*(addr+1) == 'x')||(*(addr+1) == 'X'))){
des = strtoul(addr+2, &addr, 16);
}
else{
goto error;
}
addr = argv[3];
if ((*addr == '0')&&((*(addr+1) == 'x')||(*(addr+1) == 'X'))){
len = strtoul(addr+2, &addr, 16);
}
else{
goto error;
}
if ((des < FLASH_BASE)||((des+len) > FLASH_BASE+FLASH_LENGTH)){
mputs("Invalid address or length\n");
return -1;
}
addr = argv[1];
if (*addr == 'e'){
mputs("Begin to erase flash...");
i = 100;
while((processing == 1)&&(i>0)){
NU_Sleep(50);
mputs(".");
i --;
}
printf("\nFrom 0x%08x to 0x%08x are erased\n", des, des+len-1);
}
else if (*addr == 'p'){
int err;
mputs("Begin to program flash...");
err = FlashProgram(des, (unsigned int *)TFTP_DATA_BASE, (len/4));
// err = FlashProgram(des, (unsigned int *)TFTP_DATA_BASE, 0x8000);
if (err == 0)
printf("\nFrom 0x%08x to 0x%08x are programed\n", des, des+len-1);
else
printf("\n %d errors.\n", err);
}
else{
goto error;
}
return 0;
error:
mputs (cmdtp->name);
mputc (' ');
mputs (cmdtp->help);
return -1;
}
cmd_tbl_t cmd_tbl[] = {
CMD_TBL_TFTPR,
CMD_TBL_FLASH,
CMD_TBL_BOOT,
CMD_TBL_PARAM,
CMD_TBL_VERS,
CMD_TBL_HELP,
CMD_TBL_QUES,
CMD_TBL_TEST,
/* the following entry terminates this table */
CMD_TBL_NONE
};
/***************************************************************************
* find command table entry for a command
*/
cmd_tbl_t *find_cmd(const char *cmd)
{
cmd_tbl_t *cmdtp;
/* Search command table - Use linear search - it's a small table */
for (cmdtp = &cmd_tbl[0]; cmdtp->name; cmdtp++) {
if (strncmp (cmd, cmdtp->name, cmdtp->lmin) == 0)
return cmdtp;
}
return NULL; /* not found */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -