From f338df2abc35f85961aa6266458f94ea2a102b81 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 18 Aug 2014 23:40:36 +0200 Subject: Command 'go ' works now Add debug command to display AVR RAM --- avr/main.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'avr/main.c') diff --git a/avr/main.c b/avr/main.c index 79ca3e0..5c4cd0c 100644 --- a/avr/main.c +++ b/avr/main.c @@ -29,8 +29,15 @@ /*--------------------------------------------------------------------------*/ +static uint8_t mcusr; + +static void setup_avr(void) { + /* save and clear reset reason(s) */ + mcusr = MCUSR; + MCUSR = 0; + /* WD */ /* CPU */ @@ -59,6 +66,30 @@ void setup_avr(void) TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt } +static const FLASH char * const FLASH rreasons[] = { + FSTR("Power on"), + FSTR("External"), + FSTR("Brown out"), + FSTR("Watchdog"), + FSTR("JTAG"), + }; + +static +void print_reset_reason(void) +{ + uint8_t r = mcusr & 0x1f; + const FLASH char * const FLASH *p = rreasons; + + printf_P(PSTR("Reset reason(s): ")); + for ( ; r; p++, r >>= 1) { + if (r & 1) { + my_puts_P(*p); + if (r & ~1) + printf_P(PSTR(", ")); + } + } + printf_P(PSTR(".\n")); +} /*******************************************************************************/ @@ -120,6 +151,7 @@ static int abortboot(int bootdelay) return abort; } +static const char *bootdelay_process(void) { char *s; @@ -137,6 +169,7 @@ const char *bootdelay_process(void) return s; } +static void autoboot_command(const char *s) { debug("### main_loop: bootcmd=\"%s\"\n", s ? s : PSTR("")); @@ -148,6 +181,7 @@ void autoboot_command(const char *s) } +static void main_loop(void) { const char *s; @@ -166,6 +200,9 @@ int main(void) sei(); debug("\n=========================< (RE)START DEBUG >=========================\n"); +#if DEBUG + print_reset_reason(); +#endif env_init(); -- cgit v1.2.3