#include "ao.h"
__xdata uint16_t ao_cmd_lex_i;
+__xdata uint32_t ao_cmd_lex_u32;
__xdata char ao_cmd_lex_c;
__xdata enum ao_cmd_status ao_cmd_status;
static __xdata uint8_t lex_echo;
{
__xdata uint8_t r = ao_cmd_lex_error;
- ao_cmd_lex_i = 0;
+ ao_cmd_lex_u32 = 0;
ao_cmd_white();
for(;;) {
if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9')
- ao_cmd_lex_i = (ao_cmd_lex_i * 10) + (ao_cmd_lex_c - '0');
+ ao_cmd_lex_u32 = (ao_cmd_lex_u32 * 10) + (ao_cmd_lex_c - '0');
else
break;
r = ao_cmd_success;
}
if (r != ao_cmd_success)
ao_cmd_status = r;
+ ao_cmd_lex_i = (uint16_t) ao_cmd_lex_u32;
+}
+
+uint8_t
+ao_match_word(__code char *word)
+{
+ while (*word) {
+ if (ao_cmd_lex_c != *word) {
+ ao_cmd_status = ao_cmd_syntax_error;
+ return 0;
+ }
+ word++;
+ ao_cmd_lex();
+ }
+ return 1;
}
static void
}
static void
-dump(void)
+echo(void)
{
- __xdata uint16_t c;
- __xdata uint8_t * __xdata start, * __xdata end;
-
- ao_cmd_hex();
- start = (uint8_t __xdata *) ao_cmd_lex_i;
ao_cmd_hex();
- end = (uint8_t __xdata *) ao_cmd_lex_i;
- if (ao_cmd_status != ao_cmd_success)
- return;
- c = 0;
- while (start <= end) {
- if ((c & 7) == 0) {
- if (c)
- putchar('\n');
- ao_cmd_put16((uint16_t) start);
- }
- putchar(' ');
- ao_cmd_put8(*start);
- ++c;
- start++;
- }
- putchar('\n');
+ lex_echo = ao_cmd_lex_i != 0;
}
static void
-echo(void)
+ao_reboot(void)
{
- ao_cmd_hex();
- lex_echo = ao_cmd_lex_i != 0;
+ ao_cmd_white();
+ if (!ao_match_word("eboot"))
+ return;
+ WDCTL = WDCTL_EN | WDCTL_MODE_WATCHDOG | WDCTL_INT_64;
+ ao_delay(AO_SEC_TO_TICKS(2));
+ ao_panic(AO_PANIC_REBOOT);
}
static void
puts(help_txt);
for (cmds = 0; cmds < ao_ncmds; cmds++) {
cs = ao_cmds[cmds];
- for (cmd = 0; cs[cmd].cmd != '\0'; cmd++)
- puts(cs[cmd].help);
+ for (cmd = 0; cs[cmd].func; cmd++)
+ printf("%-45s %s\n",
+ cs[cmd].help,
+ cs[cmd].help+1+strlen(cs[cmd].help));
}
}
}
void
-ao_cmd(void *parameters)
+ao_cmd(void)
{
__xdata char c;
__xdata uint8_t cmd, cmds;
__code struct ao_cmds * __xdata cs;
void (*__xdata func)(void);
- (void) parameters;
lex_echo = 1;
for (;;) {
func = (void (*)(void)) NULL;
for (cmds = 0; cmds < ao_ncmds; cmds++) {
cs = ao_cmds[cmds];
- for (cmd = 0; cs[cmd].cmd != '\0'; cmd++)
- if (cs[cmd].cmd == c) {
+ for (cmd = 0; cs[cmd].func; cmd++)
+ if (cs[cmd].help[0] == c) {
func = cs[cmd].func;
break;
}
__xdata struct ao_task ao_cmd_task;
__code struct ao_cmds ao_base_cmds[] = {
- { '?', help, "? Print this message" },
- { 'T', ao_task_info, "T Show task states" },
- { 'E', echo, "E <0 off, 1 on> Set command echo mode" },
- { 'd', dump, "d <start> <end> Dump memory" },
- { 'v', version, "v Show version" },
- { 0, help, NULL },
+ { help, "?\0Print this message" },
+ { ao_task_info, "T\0Show task states" },
+ { echo, "E <0 off, 1 on>\0Set command echo mode" },
+ { ao_reboot, "r eboot\0Reboot" },
+ { version, "v\0Show version" },
+ { 0, NULL },
};
void