X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/4bc81323e51ac138e733c14eeb6f283ae706e904..b30c4e8f1aef96f6fdc93da9f125545f5f74d06e:/avr/con-utils.c diff --git a/avr/con-utils.c b/avr/con-utils.c index 02657b9..4a96771 100644 --- a/avr/con-utils.c +++ b/avr/con-utils.c @@ -1,7 +1,14 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ -#include #include "common.h" +#include +#include +#include "config.h" #include "serial.h" #include "background.h" #include "con-utils.h" @@ -12,14 +19,39 @@ uint_fast8_t tstc(void) return serial_tstc(); } -int my_getchar(void) +int my_getchar(uint_fast8_t waitforchar) { int c; - + do { bg_shed(); c = serial_getc(); - } while (c < 0); + } 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 */ @@ -57,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; @@ -92,4 +125,3 @@ void clear_ctrlc(void) { ctrlc_was_pressed = 0; } -