aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-11-19 01:47:40 -0700
committerSelene ToyKeeper2023-11-19 01:47:40 -0700
commite6909adcb1d44797e097dcf93ee7459276a4516a (patch)
treef9cf19bfe6d0d670750fa64a0b9a2e2d166392d9
parenttemporary fix for aux LEDs on avrdd; needs proper refactoring (diff)
downloadanduril-e6909adcb1d44797e097dcf93ee7459276a4516a.tar.gz
anduril-e6909adcb1d44797e097dcf93ee7459276a4516a.tar.bz2
anduril-e6909adcb1d44797e097dcf93ee7459276a4516a.zip
moved prevent_reboot_loop() and some other junk out of fsm/main.c
-rw-r--r--arch/attiny1616.c6
-rw-r--r--arch/attiny1616.h2
-rw-r--r--arch/attiny1634.c6
-rw-r--r--arch/attiny1634.h2
-rw-r--r--arch/attiny85.c21
-rw-r--r--arch/attiny85.h2
-rw-r--r--fsm/main.c50
7 files changed, 42 insertions, 47 deletions
diff --git a/arch/attiny1616.c b/arch/attiny1616.c
index 3b170bb..a3ead7e 100644
--- a/arch/attiny1616.c
+++ b/arch/attiny1616.c
@@ -145,3 +145,9 @@ void reboot() {
while (1) {}
}
+inline void prevent_reboot_loop() {
+ // prevent WDT from rebooting MCU again
+ RSTCTRL.RSTFR &= ~(RSTCTRL_WDRF_bm); // reset status flag
+ wdt_disable();
+}
+
diff --git a/arch/attiny1616.h b/arch/attiny1616.h
index 5989785..b4e17fc 100644
--- a/arch/attiny1616.h
+++ b/arch/attiny1616.h
@@ -94,3 +94,5 @@ inline void mcu_pcint_off();
void reboot();
+inline void prevent_reboot_loop();
+
diff --git a/arch/attiny1634.c b/arch/attiny1634.c
index d4b3767..0737a81 100644
--- a/arch/attiny1634.c
+++ b/arch/attiny1634.c
@@ -123,3 +123,9 @@ void reboot() {
while (1) {}
}
+inline void prevent_reboot_loop() {
+ // prevent WDT from rebooting MCU again
+ MCUSR &= ~(1<<WDRF); // reset status flag
+ wdt_disable();
+}
+
diff --git a/arch/attiny1634.h b/arch/attiny1634.h
index e01abad..fb89fa8 100644
--- a/arch/attiny1634.h
+++ b/arch/attiny1634.h
@@ -96,3 +96,5 @@ inline void mcu_pcint_off();
void reboot();
+inline void prevent_reboot_loop();
+
diff --git a/arch/attiny85.c b/arch/attiny85.c
index 40cbcfe..0d2d7fe 100644
--- a/arch/attiny85.c
+++ b/arch/attiny85.c
@@ -165,3 +165,24 @@ void reboot() {
while (1) {}
}
+inline void prevent_reboot_loop() {
+ // prevent WDT from rebooting MCU again
+ MCUSR &= ~(1<<WDRF); // reset status flag
+ wdt_disable();
+}
+
+
+#if 0 // example for one way of creating a 4th PWM channel
+// 4th PWM channel requires manually turning the pin on/off via interrupt :(
+ISR(TIMER1_OVF_vect) {
+ //bitClear(PORTB, 3);
+ PORTB &= 0b11110111;
+ //PORTB |= 0b00001000;
+}
+ISR(TIMER1_COMPA_vect) {
+ //if (!bitRead(TIFR,TOV1)) bitSet(PORTB, 3);
+ if (! (TIFR & (1<<TOV1))) PORTB |= 0b00001000;
+ //if (! (TIFR & (1<<TOV1))) PORTB &= 0b11110111;
+}
+#endif
+
diff --git a/arch/attiny85.h b/arch/attiny85.h
index 840079c..2753fd7 100644
--- a/arch/attiny85.h
+++ b/arch/attiny85.h
@@ -89,3 +89,5 @@ inline void mcu_pcint_off();
void reboot();
+inline void prevent_reboot_loop();
+
diff --git a/fsm/main.c b/fsm/main.c
index 1c01878..bb93862 100644
--- a/fsm/main.c
+++ b/fsm/main.c
@@ -6,46 +6,14 @@
#include "fsm/main.h"
-#if PWM_CHANNELS == 4
-#ifdef AVRXMEGA3 // ATTINY816, 817, etc
-#error 4-channel PWM not currently set up for the AVR 1-Series
-#endif
-// 4th PWM channel requires manually turning the pin on/off via interrupt :(
-ISR(TIMER1_OVF_vect) {
- //bitClear(PORTB, 3);
- PORTB &= 0b11110111;
- //PORTB |= 0b00001000;
-}
-ISR(TIMER1_COMPA_vect) {
- //if (!bitRead(TIFR,TOV1)) bitSet(PORTB, 3);
- if (! (TIFR & (1<<TOV1))) PORTB |= 0b00001000;
- //if (! (TIFR & (1<<TOV1))) PORTB &= 0b11110111;
-}
-#endif
-
-
-//#ifdef USE_REBOOT
-static inline void prevent_reboot_loop() {
- // prevent WDT from rebooting MCU again
- #ifdef AVRXMEGA3 // ATTINY816, 817, etc
- RSTCTRL.RSTFR &= ~(RSTCTRL_WDRF_bm); // reset status flag
- #else
- MCUSR &= ~(1<<WDRF); // reset status flag
- #endif
- wdt_disable();
-}
-//#endif
-
int main() {
// Don't allow interrupts while booting
cli();
- //#ifdef USE_REBOOT
// prevents cycling after a crash,
// whether intentional (like factory reset) or not (bugs)
prevent_reboot_loop();
- //#endif
hwdef_setup();
@@ -64,6 +32,9 @@ int main() {
// all booted -- turn interrupts back on
PCINT_on();
+ // FIXME: support both WDT *and* RTC PIT on newer devices
+ // (WDT to recover from crashes, PIT for task scheduling)
+ // (old AVR had only WDT, newer ones split it into WDT, RTC, and PIT)
WDT_on();
ADC_on();
sei();
@@ -100,22 +71,7 @@ int main() {
// enter standby mode if requested
// (works better if deferred like this)
if (go_to_standby) {
- #ifdef USE_RAMPING
set_level(0);
- #else
- #if PWM_CHANNELS >= 1
- PWM1_LVL = 0;
- #endif
- #if PWM_CHANNELS >= 2
- PWM2_LVL = 0;
- #endif
- #if PWM_CHANNELS >= 3
- PWM3_LVL = 0;
- #endif
- #if PWM_CHANNELS >= 4
- PWM4_LVL = 255; // inverted :(
- #endif
- #endif
standby_mode();
}