summaryrefslogtreecommitdiff
path: root/avr/main.c
diff options
context:
space:
mode:
authorLeo C2014-08-18 23:40:36 +0200
committerLeo C2014-08-18 23:40:36 +0200
commitf338df2abc35f85961aa6266458f94ea2a102b81 (patch)
tree2f608280c2368cda835b6de19fa0ff8f6c85dfd7 /avr/main.c
parent1da3acc4b7215e76d459905c3e74675ffa679ce0 (diff)
downloadz180-stamp-f338df2abc35f85961aa6266458f94ea2a102b81.zip
Command 'go <startaddr>' works now
Add debug command to display AVR RAM
Diffstat (limited to 'avr/main.c')
-rw-r--r--avr/main.c37
1 files changed, 37 insertions, 0 deletions
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("<UNDEFINED>"));
@@ -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();