-/* $Id: console.c,v 1.1 2010/06/26 12:28:08 simimeie Exp $
+/* $Id: console.c,v 1.5 2010/07/25 20:40:44 simimeie Exp $
* Functions for a serial console.
*/
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/version.h>
+#include <avr/wdt.h>
#include <util/delay.h>
#include <stdio.h>
+#include <stdlib.h>
#include "console.h"
+#include "ledpwm.h"
+#include "rfm12.h"
/* PD0 is RXD, PD1 is TXD, but we don't need to address them manually */
static prog_uint8_t CRLF[] = "\r\n";
static prog_uint8_t WELCOMEMSG[] = "\r\n"\
"\r\n ******************************************"\
- "\r\n * universal mainboard v1 *"\
- "\r\n * (C) Michael 'PoempelFox' Meier 05/2010 *"\
+ "\r\n * HaWo Moodlight v0 (prototype) *"\
+ "\r\n * (C) Michael 'PoempelFox' Meier 06/2010 *"\
"\r\n ******************************************"\
"\r\n"\
"\r\nProcessor: atmega328"\
"\r\nAVR-libc: " __AVR_LIBC_VERSION_STRING__ " (" __AVR_LIBC_DATE_STRING__ ")"\
"\r\nSoftware Version 0.1, Compiled " __DATE__ " " __TIME__;
-static prog_uint8_t PROMPT[] = "\r\nroot@mbv1# ";
+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) {
/* 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;
}
console_printpgm_noirq_P(PSTR("\r\n motd repeat welcome message"));
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);
saveeepromsettings();
console_printpgm_noirq_P(PSTR("Settings written to EEPROM."));*/
} else if (strcmp_P(inputbuf, PSTR("status")) == 0) {
+ uint8_t v;
console_printpgm_noirq_P(PSTR("Current status:\r\n"));
- console_printpgm_noirq_P(PSTR("none. nothing implemented yet."));
+ console_printpgm_noirq_P(PSTR("red = "));
+ console_printhex8_noirq(ledpwm_re);
+ console_printpgm_noirq_P(PSTR(", green = "));
+ console_printhex8_noirq(ledpwm_gr);
+ console_printpgm_noirq_P(PSTR(", blue = "));
+ console_printhex8_noirq(ledpwm_bl);
+ console_printpgm_noirq_P(PSTR(", brightness = "));
+ console_printhex8_noirq(ledpwm_bri);
+ console_printpgm_noirq_P(PSTR("\r\nvalues "));
+ for (v = 0; v < 3; v++) {
+ console_printhex8_noirq(ledpwm_val[v] >> 8);
+ console_printhex8_noirq(ledpwm_val[v] & 0xff);
+ console_printpgm_noirq_P(PSTR(" "));
+ }
+ } 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));
+ 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));
+ 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));
+ 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);
+ ledpwm_bri = v;
+ ledpwm_set(ledpwm_re, ledpwm_gr, ledpwm_bl, ledpwm_bri);
+ 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"));