]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/con-utils.c
fat cp: copy_dir (untested)
[z180-stamp.git] / avr / con-utils.c
index f4023ff4e896be07ddbb7965a3682abfab026cae..410822108b971a710c8fde7b7c29c76690a39a78 100644 (file)
@@ -1,7 +1,14 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
 
-#include <string.h>
 #include "common.h"
+#include <string.h>
+#include <avr/wdt.h>
 
+#include "config.h"
 #include "serial.h"
 #include "background.h"
 #include "con-utils.h"
@@ -21,6 +28,31 @@ int my_getchar(uint_fast8_t waitforchar)
                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;
 }
 
@@ -32,6 +64,7 @@ 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 */
@@ -47,13 +80,29 @@ uint_fast8_t ctrlc(void)
 /* Reads user's confirmation.
    Returns 1 if user's input is "y", "Y", "yes" or "YES"
 */
+uint_fast8_t confirm_yes(void)
+{
+       uint_fast8_t checkch, ch;
+
+       checkch = ch = my_getchar(1);
+       putchar(ch);
+       while (ch != '\r') {
+               ch = my_getchar(1);
+               putchar(ch);
+       }
+       putchar('\n');
+
+       return (checkch  == 'y');
+}
+
+#if 0
 uint_fast8_t confirm_yesno(void)
 {
        unsigned int i;
        char str_input[5];
 
        /* Flush input */
-       while (serial_getc())
+       while (serial_getc() < 0)
                ;
        i = 0;
        while (i < sizeof(str_input)) {
@@ -71,6 +120,7 @@ uint_fast8_t confirm_yesno(void)
                return 1;
        return 0;
 }
+#endif
 
 /* pass 1 to disable ctrlc() checking, 0 to enable.
  * returns previous state