#include #include #include #include #include #define INPUT_BUFLEN 1000 #define PM_PASSWORD 0x5a000000 #define PM_RSTC 0x3F10001c #define PM_WDOG 0x3F100024 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) { uart_puts( "hwinfo: " ENDL "board revision: " ); uart_hex(get_board_revision()); uart_puts( ENDL "memory base addr: " ); uart_hex(get_memory_base_addr()); uart_puts( ENDL "memory size: " ); uart_hex(get_memory_size()); uart_puts(ENDL); } 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; }