initial commit
This commit is contained in:
75
lib/shell.c
Normal file
75
lib/shell.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <uart.h>
|
||||
#include <mbox.h>
|
||||
#include <shell.h>
|
||||
|
||||
#define INPUT_BUFLEN 1000
|
||||
|
||||
void help (void)
|
||||
{
|
||||
uart_puts(
|
||||
"help : print this help menu" ENDL
|
||||
"hello : print Hello World!" ENDL
|
||||
"hwinfo: print hardware info" ENDL
|
||||
"reboot: reboot the device" ENDL
|
||||
);
|
||||
}
|
||||
|
||||
void hello (void)
|
||||
{
|
||||
uart_puts("hello, world" ENDL);
|
||||
}
|
||||
|
||||
void hwinfo (void)
|
||||
{
|
||||
unsigned int val = get_board_revision();
|
||||
uart_puts("hwinfo: ");
|
||||
uart_hex(val);
|
||||
uart_puts(ENDL);
|
||||
}
|
||||
|
||||
#define PM_PASSWORD 0x5a000000
|
||||
#define PM_RSTC 0x3F10001c
|
||||
#define PM_WDOG 0x3F100024
|
||||
|
||||
void set(long addr, unsigned int value) {
|
||||
volatile unsigned int* point = (unsigned int*)addr;
|
||||
*point = value;
|
||||
}
|
||||
|
||||
void reset(int tick) { // reboot after watchdog timer expire
|
||||
set(PM_RSTC, PM_PASSWORD | 0x20); // full reset
|
||||
set(PM_WDOG, PM_PASSWORD | tick); // number of watchdog tick
|
||||
}
|
||||
|
||||
void reboot(void)
|
||||
{
|
||||
reset(1 << 16);
|
||||
}
|
||||
|
||||
int shell (void)
|
||||
{
|
||||
uart_puts("# ");
|
||||
|
||||
char buf[INPUT_BUFLEN], ch;
|
||||
int sz = 0;
|
||||
while ((ch = uart_getc()) != '\n') {
|
||||
buf[sz++] = ch;
|
||||
uart_send(ch);
|
||||
}
|
||||
uart_puts(ENDL);
|
||||
buf[sz] = '\0';
|
||||
|
||||
if (strcmp(buf, "help") == 0) {
|
||||
help();
|
||||
} else if (strcmp(buf, "hello") == 0) {
|
||||
hello();
|
||||
} else if (strcmp(buf, "hwinfo") == 0) {
|
||||
hwinfo();
|
||||
} else if (strcmp(buf, "reboot") == 0) {
|
||||
reboot();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user