5 #include <sys/robsys.h>
9 #include <lib/string.h>
10 #include <lib/regfunc.h>
11 #include <lib/tinyprintf.h>
13 #include <drivers/led.h>
18 #define WHITESPACE "\t\r\n "
21 int help(int, char**);
25 * info -- shows basic info of system
26 * uptime -- uptime; read from the RTC register
27 * reset -- software reset TODO
28 * show [ADDRESS-ADDRESS] -- shows SRAM range
29 * switchmode -- switch to unprivileged mode
32 static char buf[BUFSIZE];
37 int (*function)(int argc, char ** argsv);
40 struct cmd builtincmds[4];
42 int info(int argc, char ** argsv) {
47 int uptime(int arg, char ** argsv) {
48 //cputs("CURRENT UPTIME: ");
49 //cputs(regtohex(*RTC_CNTL));
51 printf("CURRENT UPTIME: %p\n", *RTC_CNTL);
54 int led(int argc, char ** argsv) {
57 if (argsv[1] != NULL) {
58 if (strcmp(argsv[1], "on")) {
62 else if (strcmp(argsv[1], "off")) {
70 int show(int argc, char ** argsv) {
72 if ((argsv[1] != NULL) && (strlen(argsv[1]) == 8)) {
74 uint32_t * check = (uint32_t *) hextoreg(argsv[1]);
78 cputs(regtohex(*check));
87 int exec_cmd(char * buf) {
93 // Parse the command buffer into whitespace-separated arguments
98 while (*buf && strchr(WHITESPACE, *buf))
103 // save and scan past next arg
104 if (argc == MAXARGS-1) {
105 cputs("Too many arguments");
109 while (*buf && !strchr(WHITESPACE, *buf))
114 // Lookup and invoke the command
117 for (i = 0; i < BUILTINCMDS; i++) {
118 if (strcmp(argv[0], builtincmds[i].name))
119 return builtincmds[i].function(argc, argv);
121 cputs("Unknown command");
128 builtincmds[0].name = "info";
129 builtincmds[0].function = info;
131 builtincmds[1].name = "led";
132 builtincmds[1].function = led;
134 builtincmds[2].name = "show";
135 builtincmds[2].function = show;
137 builtincmds[3].name = "uptime";
138 builtincmds[3].function = uptime;
142 cputs("WELCOME TO ROBSYS!\n");
145 buf = readline("root# ");
147 if (exec_cmd(buf) < 0)