X-Git-Url: http://git.rrze.uni-erlangen.de/gitweb/?p=moodlight.git;a=blobdiff_plain;f=console.c;h=8dff9f4b72ecef5c2d034fd52f6e9bd6657f5a0e;hp=87f20434bc2d8fcf998dd787dd49ed3ca98f0bf3;hb=ff29bc2b3dbad7885497cfd9aa2b3aa98cc4ebb0;hpb=dfbc0cefbdd8cdc0aecbad960c804cb1128d5b32 diff --git a/console.c b/console.c index 87f2043..8dff9f4 100644 --- a/console.c +++ b/console.c @@ -1,4 +1,4 @@ -/* $Id: console.c,v 1.3 2010/06/30 19:40:49 simimeie Exp $ +/* $Id: console.c,v 1.4 2010/07/24 20:55:48 simimeie Exp $ * Functions for a serial console. */ @@ -6,11 +6,13 @@ #include #include #include +#include #include #include #include #include "console.h" #include "ledpwm.h" +#include "rfm12.h" /* PD0 is RXD, PD1 is TXD, but we don't need to address them manually */ @@ -38,6 +40,19 @@ static prog_uint8_t WELCOMEMSG[] = "\r\n"\ "\r\nSoftware Version 0.1, Compiled " __DATE__ " " __TIME__; static prog_uint8_t PROMPT[] = "\r\nroot@moodlight# "; +uint8_t mcusr_mirror __attribute__ ((section (".noinit"))); + +/* This is needed to recover from a watchdog reset, as the watchdog + * stays active after the reset. + * The variable is just to make the reason of the last reset accessible + * later. */ +void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3"))); +void get_mcusr(void) { + mcusr_mirror = MCUSR; + MCUSR = 0; + wdt_disable(); +} + /* Handler for TXC (TX Complete) IRQ */ ISR(USART_TX_vect) { if (outputhead == outputtail) { /* Nothing more to send! */ @@ -177,6 +192,19 @@ void console_init(void) { /* Enable Send and Receive and IRQs */ UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(TXCIE0) | _BV(RXCIE0); console_printpgm_noirq_P(WELCOMEMSG); + console_printpgm_noirq_P(PSTR("\r\nNOTE: last reset was from")); + if (mcusr_mirror & _BV(WDRF)) { + console_printpgm_noirq_P(PSTR(" WatchdogTimer")); + } + if (mcusr_mirror & _BV(BORF)) { + console_printpgm_noirq_P(PSTR(" Brownout")); + } + if (mcusr_mirror & _BV(EXTRF)) { + console_printpgm_noirq_P(PSTR(" ExternalReset")); + } + if (mcusr_mirror & _BV(PORF)) { + console_printpgm_noirq_P(PSTR(" PowerOn")); + } console_printpgm_noirq_P(PROMPT); return; } @@ -263,6 +291,7 @@ ISR(USART_RX_vect) { console_printpgm_noirq_P(PSTR("\r\n showpins [x] shows the avrs inputpins")); console_printpgm_noirq_P(PSTR("\r\n status show status / counters")); console_printpgm_noirq_P(PSTR("\r\n [rgb] n sets the brightness of the red / green / blue LED to n")); + console_printpgm_noirq_P(PSTR("\r\n rfstatus show RFM12 status")); /* console_printpgm_noirq_P(PSTR("\r\n save saves settings to EEPROM")); */ } else if (strcmp_P(inputbuf, PSTR("motd")) == 0) { console_printpgm_noirq_P(WELCOMEMSG); @@ -329,28 +358,27 @@ ISR(USART_RX_vect) { console_printhex8_noirq(ledpwm_bl); console_printpgm_noirq_P(PSTR(", brightness = ")); console_printhex8_noirq(ledpwm_bri); - /*console_printpgm_noirq_P(CRLF);*/ } else if (strncmp_P(inputbuf, PSTR("r "), 2) == 0) { uint8_t v; v = strtoul(&inputbuf[2], NULL, 0); ledpwm_re = v; ledpwm_setled(LEDPWM_REDLED, (((uint16_t)ledpwm_re * ledpwm_bri) / 255)); - console_printpgm_P(PSTR("RED value set to 0x")); - console_printhex8(v); + console_printpgm_noirq_P(PSTR("RED value set to 0x")); + console_printhex8_noirq(v); } else if (strncmp_P(inputbuf, PSTR("g "), 2) == 0) { uint8_t v; v = strtoul(&inputbuf[2], NULL, 0); ledpwm_gr = v; ledpwm_setled(LEDPWM_GREENLED, (((uint16_t)ledpwm_gr * ledpwm_bri) / 255)); - console_printpgm_P(PSTR("GREEN value set to 0x")); - console_printhex8(v); + console_printpgm_noirq_P(PSTR("GREEN value set to 0x")); + console_printhex8_noirq(v); } else if (strncmp_P(inputbuf, PSTR("b "), 2) == 0) { uint8_t v; v = strtoul(&inputbuf[2], NULL, 0); ledpwm_bl = v; ledpwm_setled(LEDPWM_BLUELED, (((uint16_t)ledpwm_bl * ledpwm_bri) / 255)); - console_printpgm_P(PSTR("BLUE value set to 0x")); - console_printhex8(v); + console_printpgm_noirq_P(PSTR("BLUE value set to 0x")); + console_printhex8_noirq(v); } else if (strncmp_P(inputbuf, PSTR("bri "), 2) == 0) { uint8_t v; v = strtoul(&inputbuf[4], NULL, 0); @@ -358,8 +386,16 @@ ISR(USART_RX_vect) { ledpwm_setled(LEDPWM_REDLED, (((uint16_t)ledpwm_re * ledpwm_bri) / 255)); ledpwm_setled(LEDPWM_GREENLED, (((uint16_t)ledpwm_gr * ledpwm_bri) / 255)); ledpwm_setled(LEDPWM_BLUELED, (((uint16_t)ledpwm_bl * ledpwm_bri) / 255)); - console_printpgm_P(PSTR("brightness set to 0x")); - console_printhex8(v); + console_printpgm_noirq_P(PSTR("brightness set to 0x")); + console_printhex8_noirq(v); + } else if (strcmp_P(inputbuf, PSTR("rfstatus")) == 0) { + uint32_t st; + st = rfm12_readstatus(); + console_printpgm_noirq_P(PSTR("rfm12 status is ")); + console_printhex8_noirq(st >> 24); + console_printhex8_noirq(st >> 16); + console_printhex8_noirq(st >> 8); + console_printhex8_noirq(st >> 0); #ifdef JOKECMDS } else if (strncmp_P(inputbuf, PSTR("ls"), 2) == 0) { console_printpgm_noirq_P(PSTR("Total 4711\r\n"));