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>
26 #include <drivers/led.h>
31 #define WHITESPACE "\t\r\n "
36 * info -- shows basic info of system
37 * uptime -- uptime; read from the RTC register
38 * reset -- software reset TODO
39 * showmem xxxxxxxx -- shows address value
41 * switchmode -- switch to unprivileged mode TODO
44 static char buf[BUFSIZE];
48 int (*function)(int argc, char ** argsv);
51 struct cmd builtincmds[BUILTINCMDS];
53 int info(int argc, char ** argsv) {
54 extern mem_pool_t kheap_pool;
55 kheap_info(&kheap_pool);
59 int uptime(int arg, char ** argsv) {
60 printf("CURRENT UPTIME: %d seconds \n", *RTC_CNTL);
63 int led(int argc, char ** argsv) {
65 if (argsv[1] != NULL) {
66 if (strcmp(argsv[1], "on")) {
70 else if (strcmp(argsv[1], "off")) {
78 int showmem(int argc, char ** argsv) {
80 if ((argsv[1] != NULL) && (strlen(argsv[1]) == 8)) {
82 uint32_t * check = (uint32_t *) hextoreg(argsv[1]);
83 printf("LOCATION 0x%s, VALUE: %#x\n", argsv[1], *check);
91 int exec_cmd(char * buf) {
97 // Parse the command buffer into whitespace-separated arguments
102 while (*buf && strchr(WHITESPACE, *buf))
107 // save and scan past next arg
108 if (argc == MAXARGS-1) {
109 printf("Too many arguments\n");
113 while (*buf && !strchr(WHITESPACE, *buf))
118 // Lookup and invoke the command
121 for (i = 0; i < BUILTINCMDS; i++) {
122 if (strcmp(argv[0], builtincmds[i].name))
123 return builtincmds[i].function(argc, argv);
125 printf("Unknown command\n");
132 builtincmds[0].name = "info";
133 builtincmds[0].function = info;
135 builtincmds[1].name = "led";
136 builtincmds[1].function = led;
138 builtincmds[2].name = "showmem";
139 builtincmds[2].function = showmem;
141 builtincmds[3].name = "uptime";
142 builtincmds[3].function = uptime;
148 buf = readline("root# ");
150 if (exec_cmd(buf) < 0)