5 #include <sys/robsys.h>
9 #include <lib/string.h>
10 #include <lib/regfunc.h>
12 #include <drivers/led.h>
17 #define WHITESPACE "\t\r\n "
20 int help(int, char**);
24 * info -- shows basic info of system
25 * uptime -- uptime; read from the RTC register
26 * reset -- software reset TODO
27 * show [ADDRESS-ADDRESS] -- shows SRAM range
28 * switchmode -- switch to unprivileged mode
31 static char buf[BUFSIZE];
36 int (*function)(int argc, char ** argsv);
39 struct cmd builtincmds[4];
41 int info(int argc, char ** argsv) {
46 int uptime(int arg, char ** argsv) {
47 cputs("CURRENT UPTIME: ");
48 cputs(regtohex(*RTC_CNTL));
52 int led(int argc, char ** argsv) {
55 if (argsv[1] != NULL) {
56 if (strcmp(argsv[1], "on")) {
60 else if (strcmp(argsv[1], "off")) {
68 int show(int argc, char ** argsv) {
70 if ((argsv[1] != NULL) && (strlen(argsv[1]) == 8)) {
72 uint32_t * check = (uint32_t *) hextoreg(argsv[1]);
76 cputs(regtohex(*check));
85 int exec_cmd(char * buf) {
91 // Parse the command buffer into whitespace-separated arguments
96 while (*buf && strchr(WHITESPACE, *buf))
101 // save and scan past next arg
102 if (argc == MAXARGS-1) {
103 cputs("Too many arguments");
107 while (*buf && !strchr(WHITESPACE, *buf))
112 // Lookup and invoke the command
115 for (i = 0; i < BUILTINCMDS; i++) {
116 if (strcmp(argv[0], builtincmds[i].name))
117 return builtincmds[i].function(argc, argv);
119 cputs("Unknown command");
126 builtincmds[0].name = "info";
127 builtincmds[0].function = info;
129 builtincmds[1].name = "led";
130 builtincmds[1].function = led;
132 builtincmds[2].name = "show";
133 builtincmds[2].function = show;
135 builtincmds[3].name = "uptime";
136 builtincmds[3].function = uptime;
140 cputs("WELCOME TO ROBSYS!\n");
143 buf = readline("root# ");
145 if (exec_cmd(buf) < 0)