summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
29b27ab)
Apparently, after WDT reset, WDT is still running, and has to be
disabled. Otherwise it will kick in again during the initialization.
We want to indicate the WDT reset contition somehow. We use the GPIO
LED 0 - we set it to on if the reset source was WDT.
Also, we want to read and reset MCUSR as early as possible. We do it
from main(), and we then send the saved value where needed (init_log()
and power_down()).
static inline void long_press(unsigned char button)
{
if (button == 0) {
static inline void long_press(unsigned char button)
{
if (button == 0) {
/* logging.c */
#ifdef USE_LOGGING
/* logging.c */
#ifdef USE_LOGGING
+void init_log(unsigned char mcusr);
void log_set_state(unsigned char val);
void log_flush();
void log_byte(unsigned char byte);
void log_word(uint16_t word);
#else
void log_set_state(unsigned char val);
void log_flush();
void log_byte(unsigned char byte);
void log_word(uint16_t word);
#else
-void inline init_log() { }
+void inline init_log(unsigned char mcusr) { }
void inline log_set_state(unsigned char val) { }
void inline log_flush() { }
void inline log_byte(unsigned char byte) { }
void inline log_set_state(unsigned char val) { }
void inline log_flush() { }
void inline log_byte(unsigned char byte) { }
pattern_t *laser_pattern_select();
/* main.c */
pattern_t *laser_pattern_select();
/* main.c */
+void power_down(unsigned char err);
eeprom_write_byte(&log_state, val);
}
eeprom_write_byte(&log_state, val);
}
+void init_log(unsigned char mcusr)
if (r_count < 5) {
r_count++;
eeprom_write_byte(&reboot_count,
if (r_count < 5) {
r_count++;
eeprom_write_byte(&reboot_count,
- (r_count << 4) | (MCUSR & 0xF));
- MCUSR = 0;
+ (r_count << 4) | (mcusr & 0xF));
can_write_eeprom = 1;
} else {
//eeprom_write_byte(&log_state, 0xFF);
can_write_eeprom = 1;
} else {
//eeprom_write_byte(&log_state, 0xFF);
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/power.h>
+void power_down(unsigned char err)
+ if (err)
+ gpio_set(0, 1);
+
// G'night
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
// G'night
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
+ unsigned char mcusr_save;
+
+ // disable the WDT if running
+ wdt_reset();
+ mcusr_save = MCUSR;
+ MCUSR = 0;
+ wdt_disable();
+
+ if (mcusr_save & _BV(WDRF)) // was watchdog reset?
+ gpio_set(0, 1);
+
+ init_log(mcusr_save);
power_usi_disable(); // Once for lifetime
ACSRA |= _BV(ACD); // disable analog comparator
power_usi_disable(); // Once for lifetime
ACSRA |= _BV(ACD); // disable analog comparator
log_set_state(3);
hw_setup();
log_set_state(3);
hw_setup();
+ power_down(mcusr_save & _BV(WDRF));