📄 shell.c
字号:
#include "vxWorks.h"
#include "usrConfig.h" /* general configuration header */
#include "pingLib.h"
#include "logLib.h"
#include "taskLib.h"
#include "usrLib.h"
#include "wdLib.h"
#include "config.h"
#include "drv/pci/pciConfigShow.h"
#include "drv/timer/m5200SliceTimer.h"
#include "drv/pci/pciConfigLib.h"
LOCAL int argc;
LOCAL char *argv[10];
WDOG_ID wdg_id;
void sysInfo();
void sysIdeInfo();
void usrAuxClock ();
void testWdg ();
IMPORT UINT16 usbTool (void);
IMPORT UINT16 prnTool (void);
IMPORT UINT16 ideTool (void);
void taskLed()
{
*(volatile UINT32 *)(MBAR_VALUE+MBAR_GPIO_STD+GPIO_SEN_OFF) |= 0x10000000; /* as GPIO */
*(volatile UINT32 *)(MBAR_VALUE+MBAR_GPIO_STD+GPIO_SDD_OFF) |= 0x10000000; /* output */
*(volatile UINT32 *)(MBAR_VALUE+MBAR_GPIO_STD+GPIO_SDO_OFF) &= ~0x10000000; /* clear, led on */
while(1)
{
taskDelay(sysClkRateGet()/2);
*(volatile UINT32 *)(MBAR_VALUE+MBAR_GPIO_STD+GPIO_SDO_OFF) ^= 0x10000000; /* on/off */
}
}
static int ascHexToInt(const char *ascHex)
{
int n;
char sBuf[20];
int ii, iRet;
n = strlen(ascHex);
if(n > 10) return(ERROR);
if((ascHex[0] != '0') ||
((ascHex[1] != 'x') && (ascHex[1] != 'X')))
return(ERROR);
strcpy(sBuf, &ascHex[2]);
n = strlen(sBuf);
iRet = 0;
for(ii=0; ii<n; ii++)
{
iRet <<= 4;
if((sBuf[ii] >= 'A') && (sBuf[ii] <='Z'))
{
sBuf[ii] += ('a' - 'A');
}
if((sBuf[ii] >= 'a') && (sBuf[ii] <= 'f'))
{
iRet += sBuf[ii] - 'a' + 10;
}
else if((sBuf[ii] >= '0') && (sBuf[ii] <= '9'))
iRet += sBuf[ii] - '0';
else return(ERROR);
}
return(iRet);
}
void usrAuxClock ()
{
logMsg ("slice timer 1 interrupt: \n",1,2,3,4,5,6);
}
void testWdg ()
{
logMsg ("wdgTimer accept \n",1,2,3,4,5,6);
wdStart (wdg_id, sysClkRateGet(), (FUNCPTR)testWdg, 0);
}
LOCAL void parseCmd(char *pStr, int len)
{
int j;
argc = 0;
for(j=0;j<len;j++)
{
for(; isspace((int)pStr[j]); j++);
if(j == len) return;
argv[argc++] = pStr + j;
for(; !isspace((int)pStr[j]); j++)
if(j == len) return;
pStr[j] = 0;
}
}
void usrShell (void)
{
char string [80];
/*taskSpawn("tLed",200,0,4000,(FUNCPTR)taskLed, 0,0,0,0,0,0,0,0,0,0);*/
FOREVER
{
printf ("[ROOT] $: ");
fioRdString (STD_IN, string, sizeof (string));
parseCmd(string,strlen(string));
if(argc == 0) continue;
if (strcmp (argv[0], "mem") == 0)
{
if(argc == 2) memShow(atoi(argv[1]));
else memShow (1);
}
else if (strcmp(argv[0],"sys") == 0)
{
sysInfo();
}
else if (strcmp(argv[0],"usb") == 0)
{
usbTool();
}
else if (strcmp(argv[0],"prn") == 0)
{
prnTool();
}
else if (strcmp(argv[0],"ata") == 0)
{
ideTool();
}
else if (strcmp(argv[0],"reboot") == 0)
{
reboot(2);
}
else if(strcmp(argv[0], "task") == 0)
{
if(argc == 3)
{
taskShow(taskNameToId(argv[1]),atoi(argv[2]));
}
else taskShow(1,2);
}
else if(strcmp(argv[0], "if") == 0)
{
if(argc == 2) ifShow(argv[1]); /* display the attached network interfaces */
else printf("Usage: if ifName.\n");
}
else if(strcmp(argv[0], "ping") == 0)
{
if(argc == 2) ping(argv[1],3,0);
else ping("127.0.0.1",5,0);
}
else if(strcmp(argv[0],"m") == 0)
{
int maddr, value;
if(argc != 3)
{
printf("Usage: m (0x)addr (0x)value \n");
continue;
}
maddr = ascHexToInt(argv[1]);
value = ascHexToInt(argv[2]);
if (maddr == ERROR)
{
printf("Error param.\n");
continue;
}
*(UINT32 *)(maddr & 0xFFFFFFFC) = value;
}
else if(strcmp(argv[0],"pciHeaderShow") == 0)
{
int bus,devNo,Func;
if(argc != 4)
{
printf("Usage: pciHeaderShow bus devNo Func \n");
continue;
}
bus = ascHexToInt(argv[1]);
devNo = ascHexToInt(argv[2]);
Func = ascHexToInt(argv[3]);
pciHeaderShow(bus,devNo,Func);
}
else if(strcmp(argv[0],"d") == 0)
{
int addr;
if(argc != 2)
{
printf("Usage: d (0x)offset \n");
continue;
}
addr = ascHexToInt(argv[1]);
if (addr == ERROR)
{
printf("Error param.\n");
continue;
}
printf("0x%x:", addr);
printf(" %x", *(UINT32 *)(addr));
}
else if(strcmp(argv[0], "devs") == 0)
{
iosDevShow();
}
else if (strcmp (argv[0], "pci") == 0)
{
if(argc == 2) pciDeviceShow(atoi(argv[1]));
else pciDeviceShow (0);
}
else if (strcmp (argv[0], "ide") == 0)
{
sysIdeInfo();
}
else if (strcmp (argv[0], "auxTimerTest") == 0)
{
int itick;
if(argc != 2)
{
printf("Usage: auxTimerTest ticks/secs \n");
continue;
}
itick = atoi(argv[1]);
if (itick < AUX_CLK_RATE_MIN || itick > AUX_CLK_RATE_MAX)
{
printf("ticks should between AUX_CLK_RATE_MIN and AUX_CLK_RATE_MAX \n");
continue;
}
sysAuxClkConnect ((FUNCPTR) usrAuxClock, 0); /* connect auxclock ISR */
sysAuxClkRateSet (itick); /* set aux clock rate */
sysAuxClkEnable (); /* start it */
}
else if (strcmp(argv[0],"wdgTest") == 0)
{
wdg_id = wdCreate ();
wdStart (wdg_id, sysClkRateGet(), (FUNCPTR)testWdg, 0);
}
else if (strcmp(argv[0],"wdgCancel") == 0)
{
wdCancel(wdg_id);
}
else if (strcmp (argv[0], "auxClkDisable") == 0)
{
sysAuxClkDisable (); /* end it */
}
else if (strcmp (argv[0], "cd") == 0)
{
if(argc == 2) cd(argv[1]);
else pwd();
}
else if (strcmp (argv[0], "pwd") == 0)
{
pwd();
}
else if ((strcmp (argv[0], "ls") == 0) || (strcmp (argv[0], "dir") == 0))
{
if(argc == 2) ll(argv[1]);
else ll(".");
}
else if(strcmp(argv[0], "bootline") == 0)
{
printf("bootline=%s\n", (char *)BOOT_LINE_ADRS);
}
else if(strcmp(argv[0], "sioSend") == 0)
{
int sioFd;
char sndBuf[17] = "hello, send test\n";
char key = 0;
sioFd = open ("/tyCo/1", O_RDWR, 0);
if(sioFd == ERROR)
{
printf("com1 not opened\n");
continue;
}
(void) ioctl (sioFd, FIOBAUDRATE, CONSOLE_BAUD_RATE);
(void) ioctl (sioFd, FIOSETOPTIONS, OPT_ECHO | OPT_CRMOD | OPT_TANDEM | OPT_7_BIT);
printf("com1 send string: hello, send test\n");
if(write(sioFd, sndBuf, 17) ==ERROR)
{
printf("com1 send string error\n");
close(sioFd);
continue;
}
while (key != 27)
{
if(read (sioFd, &key, 1)!= ERROR)
printf("%c",key);
}
close(sioFd);
}
else if(strcmp(argv[0], "help") == 0)
{
printf (" mem: memory allocation information\n");
printf (" sys: system Information\n");
printf (" usb: usb Toolbox\n");
printf (" prn: printer Toolbox\n");
printf (" ata: ide Toolbox\n");
printf (" reboot: reboot system\n");
printf (" task: taskshow. Usage - task taskname level(0-summary 1-details 2-all tasks\n");
printf (" if: ethernet interface show. Usage - if ifname\n");
printf (" ping: ping test. Usage - ping ipaddress\n");
printf (" m: modify memory. Usage- m (0x)addr (0x)value \n");
printf (" pciHeaderShow: show pci device header. Usage- pciHeaderShow (0x)bus (0x)devNo (0x)Func \n");
printf (" d: display contents. Usage: d (0x)offset \n");
printf (" devs: display system devices\n");
printf (" pci: PCI device show\n");
printf (" ide: show system ide information\n");
printf (" bootline: show bootline information\n");
}
else
{
printf("Bad Command.\n");
}
}
}
#include "wdb\wdbLibP.h"
void sysInfo()
{
#if (WDB_COMM_TYPE == WDB_COMM_NETWORK)
#define WDB_COMM_TYPE_STR "WDB_COMM_NETWORK"
#endif /* WDB_COMM_TYPE == WDB_COMM_NETWORK */
#if (WDB_COMM_TYPE == WDB_COMM_SERIAL)
#define WDB_COMM_TYPE_STR "WDB_COMM_SERIAL"
#endif /* WDB_COMM_TYPE == WDB_COMM_SERIAL */
#if (WDB_COMM_TYPE == WDB_COMM_TYCODRV_5_2)
#define WDB_COMM_TYPE_STR "WDB_COMM_TYCODRV_5_2"
#endif /* WDB_COMM_TYPE == WDB_COMM_TYCODRV_5_2 */
#if (WDB_COMM_TYPE == WDB_COMM_NETROM)
#define WDB_COMM_TYPE_STR "WDB_COMM_NETROM"
#endif /* WDB_COMM_TYPE == WDB_COMM_NETROM */
#if (WDB_COMM_TYPE == WDB_COMM_VTMD)
#define WDB_COMM_TYPE_STR "WDB_COMM_VTMD"
#endif /* WDB_COMM_TYPE == WDB_COMM_VTMD */
#if (WDB_COMM_TYPE == WDB_COMM_END)
#define WDB_COMM_TYPE_STR "WDB_COMM_END"
#endif /* WDB_COMM_TYPE == WDB_COMM_END */
#if (WDB_COMM_TYPE == WDB_COMM_CUSTOM)
#define WDB_COMM_TYPE_STR "WDB_COMM_CUSTOM"
#endif /* WDB_COMM_TYPE == WDB_COMM_CUSTOM */
#if (WDB_COMM_TYPE == WDB_COMM_PIPE)
#define WDB_COMM_TYPE_STR "WDB_COMM_PIPE"
#endif /* WDB_COMM_TYPE == WDB_COMM_PIPE */
#ifndef WDB_COMM_TYPE_STR
#define WDB_COMM_TYPE_STR "Unknown"
#endif /* WDB_COMM_TYPE_STR */
printf ("%s (v%s) for MPC5200B\n", runtimeName, runtimeVersion);
printf ("Kernel: %s\n", kernelVersion ());
printf ("BSP: " BSP_VERSION BSP_REV "\n");
printf ("Memory Size: 0x%x\n", (UINT)(sysMemTop () - (char *)LOCAL_MEM_LOCAL_ADRS));
/* printf ("Made on %s.\n", creationDate); */
#if defined(INCLUDE_WDB)
printf ("WDB Comm Type: %s\n", WDB_COMM_TYPE_STR);
printf ("WDB: %s\n", ((wdbRunsExternal () || wdbRunsTasking ()) ? "Ready" : "Agent configuration failed"));
#endif
/*
iosDevShow();
pciDeviceShow(0);
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -