summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware/main.c
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2009-04-17 18:29:03 +0200
committerMichael Buesch <mb@bu3sch.de>2009-04-17 18:29:03 +0200
commit4ade0d3b6f545db13d54bad1c2eababfd3f7ee84 (patch)
tree0e225cb5b7fefe864323d72d328d80ff9ff419c8 /pressure_control/firmware/main.c
parentcae474acff0da74af07cd2194dc694714076d1f0 (diff)
downloadcnc-4ade0d3b6f545db13d54bad1c2eababfd3f7ee84.tar.xz
cnc-4ade0d3b6f545db13d54bad1c2eababfd3f7ee84.zip
pressure_control: Fix bootup
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control/firmware/main.c')
-rw-r--r--pressure_control/firmware/main.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/pressure_control/firmware/main.c b/pressure_control/firmware/main.c
index 593e2a5..d2d849d 100644
--- a/pressure_control/firmware/main.c
+++ b/pressure_control/firmware/main.c
@@ -28,6 +28,8 @@
#include <string.h>
#include <avr/eeprom.h>
+#include <avr/io.h>
+#include <avr/wdt.h>
struct eeprom_data {
@@ -42,7 +44,7 @@ struct pressure_state state;
/* EEPROM contents */
static struct eeprom_data EEMEM eeprom = {
.cfg = {
- .desired = 4000, /* Millibar */
+ .desired = 2500, /* Millibar */
.hysteresis = 200, /* Millibar */
.autoadjust_enable = 1,
},
@@ -179,7 +181,20 @@ static void print_banner(void)
int main(void)
{
+ uint8_t mcucsr;
+
cli();
+ mcucsr = MCUCSR;
+ MCUCSR = 0;
+ wdt_disable();
+ if (mcucsr & (1 << BORF)) {
+ /* If we have a brownout, try to enter valve emergency state. */
+ valves_emergency_state();
+ mdelay(500);
+ /* This wasn't a real brownout, if we're still alife.
+ * Go on with initialization. */
+ }
+ wdt_enable(WDTO_500MS);
/* It's OK to init the remote interface that early, as we
* have IRQs disabled throughout the init process. So we can't
@@ -187,6 +202,8 @@ int main(void)
* to send error messages early. */
remote_init();
print_banner();
+ if (!(mcucsr & (1 << PORF)) && (mcucsr & (1 << WDRF)))
+ print("WATCHDOG RESET!\n");
valves_init();
sensor_init();
@@ -208,11 +225,24 @@ int main(void)
}
if (state.needs_checking) {
check_pressure();
- /* Trigger another measurement in 50 milliseconds. */
- state.sensor_trigger_cnt = 50;
+ /* Trigger another measurement in 25 milliseconds. */
+ state.sensor_trigger_cnt = 25;
state.needs_checking = 0;
mb();
}
remote_work();
+ wdt_reset();
}
}
+
+/* The fuse bits - AT_Mega8
+ * External clock, 0ms startup
+ * BOD 4.0V
+ * Boot vector disabled
+ * Preserve EEPROM disabled
+ * SPI enabled
+ */
+FUSES = {
+ .low = 0x00,
+ .high = 0xD9,
+};
bues.ch cgit interface