Merge remote-tracking branch 'uniarch/master' into multiarch
[fw/altos] / src / core / ao_cmd.c
index 1442ebea8eafc9a32e31ae18006bf61ef2af9316..2b64b8ca210efe871b6eaadd4f14b37d6f281707 100644 (file)
@@ -22,7 +22,7 @@ __pdata uint32_t ao_cmd_lex_u32;
 __pdata char   ao_cmd_lex_c;
 __pdata enum ao_cmd_status ao_cmd_status;
 
-#define CMD_LEN        32
+#define CMD_LEN        48
 
 static __xdata char    cmd_line[CMD_LEN];
 static __pdata uint8_t cmd_len;
@@ -32,7 +32,7 @@ static void
 put_string(__code char *s)
 {
        char    c;
-       while (c = *s++)
+       while ((c = *s++))
                putchar(c);
 }
 
@@ -128,22 +128,48 @@ ao_cmd_white(void)
                ao_cmd_lex();
 }
 
+int8_t
+ao_cmd_hexchar(char c)
+{
+       if ('0' <= c && c <= '9')
+               return (c - '0');
+       if ('a' <= c && c <= 'f')
+               return (c - 'a' + 10);
+       if ('A' <= c && c <= 'F')
+               return (c - 'A' + 10);
+       return -1;
+}
+
+void
+ao_cmd_hexbyte(void)
+{
+       uint8_t i;
+       int8_t  n;
+
+       ao_cmd_lex_i = 0;
+       ao_cmd_white();
+       for (i = 0; i < 2; i++) {
+               n = ao_cmd_hexchar(ao_cmd_lex_c);
+               if (n < 0) {
+                       ao_cmd_status = ao_cmd_syntax_error;
+                       break;
+               }
+               ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
+               ao_cmd_lex();
+       }
+}
+
 void
 ao_cmd_hex(void)
 {
        __pdata uint8_t r = ao_cmd_lex_error;
-       uint8_t n;
+       int8_t  n;
 
        ao_cmd_lex_i = 0;
        ao_cmd_white();
        for(;;) {
-               if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9')
-                       n = (ao_cmd_lex_c - '0');
-               else if ('a' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'f')
-                       n = (ao_cmd_lex_c - 'a' + 10);
-               else if ('A' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'F')
-                       n = (ao_cmd_lex_c - 'A' + 10);
-               else
+               n = ao_cmd_hexchar(ao_cmd_lex_c);
+               if (n < 0)
                        break;
                ao_cmd_lex_i = (ao_cmd_lex_i << 4) | n;
                r = ao_cmd_success;
@@ -187,13 +213,6 @@ ao_match_word(__code char *word)
        return 1;
 }
 
-static void
-eol(void)
-{
-       while (ao_cmd_lex_c != '\n')
-               ao_cmd_lex();
-}
-
 static void
 echo(void)
 {
@@ -208,8 +227,13 @@ ao_reboot(void)
        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));
+       /* Delay waiting for the packet master to be turned off
+        * so that we don't end up back in idle mode because we
+        * received a packet after boot.
+        */
+       flush();
+       ao_delay(AO_SEC_TO_TICKS(1));
+       ao_arch_reboot();
        ao_panic(AO_PANIC_REBOOT);
 }
 
@@ -219,7 +243,7 @@ version(void)
        printf("manufacturer     %s\n", ao_manufacturer);
        printf("product          %s\n", ao_product);
        printf("serial-number    %u\n", ao_serial_number);
-#if HAS_EEPROM
+#if HAS_LOG
        printf("log-format       %u\n", ao_log_format);
 #endif
        printf("software-version %s\n", ao_version);
@@ -254,6 +278,7 @@ report(void)
        case ao_cmd_syntax_error:
                puts("Syntax error");
                ao_cmd_status = 0;
+       default:
                break;
        }
 }