1 /* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
4 * 2019/8/14 - ROBIN KRENS
8 * Small terminal with some built-in debug commands
16 #include <sys/robsys.h>
19 #include <lib/stdio.h>
20 #include <lib/string.h>
21 #include <lib/regfunc.h>
22 #include <lib/tinyprintf.h>
24 #include <drivers/led.h>
29 #define WHITESPACE "\t\r\n "
34 * info -- shows basic info of system
35 * uptime -- uptime; read from the RTC register
36 * reset -- software reset TODO
37 * showmem xxxxxxxx -- shows address value
39 * switchmode -- switch to unprivileged mode TODO
42 static char buf[BUFSIZE];
46 int (*function)(int argc, char ** argsv);
49 struct cmd builtincmds[BUILTINCMDS];
51 int info(int argc, char ** argsv) {
52 /* extern mem_pool_t kheap_pool;
53 kheap_info(&kheap_pool); */
58 int uptime(int arg, char ** argsv) {
59 printf("CURRENT UPTIME: %d seconds \n", *RTC_CNTL);
62 int led(int argc, char ** argsv) {
64 if (argsv[1] != NULL) {
65 if (strcmp(argsv[1], "on")) {
69 else if (strcmp(argsv[1], "off")) {
77 int showmem(int argc, char ** argsv) {
79 if ((argsv[1] != NULL) && (strlen(argsv[1]) == 8)) {
81 uint32_t * check = (uint32_t *) hextoreg(argsv[1]);
82 printf("LOCATION 0x%s, VALUE: %#x\n", argsv[1], *check);
90 int exec_cmd(char * buf) {
96 // Parse the command buffer into whitespace-separated arguments
101 while (*buf && strchr(WHITESPACE, *buf))
106 // save and scan past next arg
107 if (argc == MAXARGS-1) {
108 printf("Too many arguments\n");
112 while (*buf && !strchr(WHITESPACE, *buf))
117 // Lookup and invoke the command
120 for (i = 0; i < BUILTINCMDS; i++) {
121 if (strcmp(argv[0], builtincmds[i].name))
122 return builtincmds[i].function(argc, argv);
124 printf("Unknown command\n");
131 builtincmds[0].name = "info";
132 builtincmds[0].function = info;
134 builtincmds[1].name = "led";
135 builtincmds[1].function = led;
137 builtincmds[2].name = "showmem";
138 builtincmds[2].function = showmem;
140 builtincmds[3].name = "uptime";
141 builtincmds[3].function = uptime;
147 buf = readline("root# ");
149 if (exec_cmd(buf) < 0)