]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/con-utils.c
cli.c bugfix: Comment only lines are not an error.
[z180-stamp.git] / avr / con-utils.c
index 430ba98ae6407fbdc964f42e87a207b34766aa08..4a96771040c536123388f92657a0d1e6fe54c982 100644 (file)
@@ -1,33 +1,70 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
 
+#include "common.h"
 #include <string.h>
-#include <stdio.h>
+#include <avr/wdt.h>
 
+#include "config.h"
 #include "serial.h"
+#include "background.h"
 #include "con-utils.h"
 
-
 uint_fast8_t tstc(void)
 {
+       bg_shed();
        return serial_tstc();
 }
 
-int my_getchar(void)
+int my_getchar(uint_fast8_t waitforchar)
 {
        int c;
-       
-       while((c = serial_getc()) < 0)
-               ;
+
+       do {
+               bg_shed();
+               c = serial_getc();
+       } while ((c < 0) && waitforchar);
+
+#ifdef CONFIG_SYS_FBOOTSIG
+       if (c < 0)
+               return c;
+
+       static const FLASH unsigned char bootsig[] = {CONFIG_SYS_FBOOTSIG};
+       static uint8_t pb;
+       unsigned char uc = c;
+
+
+       if (bootsig[pb] == 0) {
+               if (uc == 0xff) {
+                       wdt_enable(WDTO_15MS);
+                       for(;;)
+                               ;
+               } else
+                       pb = 0;
+
+       } else {
+               if (bootsig[pb] == uc)
+                       pb++;
+               else
+                       pb = 0;
+       }
+#endif
+
        return c;
 }
 
 
 /* test if ctrl-c was pressed */
 
-static uint_fast8_t ctrlc_disabled = 0;        /* see disable_ctrl() */
-static uint_fast8_t ctrlc_was_pressed = 0;
+static uint_fast8_t ctrlc_disabled;    /* see disable_ctrl() */
+static uint_fast8_t ctrlc_was_pressed;
 
 uint_fast8_t ctrlc(void)
 {
+       bg_shed();
        if (!ctrlc_disabled) {
                switch (serial_getc()) {
                case 0x03:              /* ^C - Control C */
@@ -53,7 +90,7 @@ uint_fast8_t confirm_yesno(void)
                ;
        i = 0;
        while (i < sizeof(str_input)) {
-               str_input[i] = my_getchar();
+               str_input[i] = my_getchar(1);
                putchar(str_input[i]);
                if (str_input[i] == '\r')
                        break;
@@ -88,4 +125,3 @@ void clear_ctrlc(void)
 {
        ctrlc_was_pressed = 0;
 }
-