aboutsummaryrefslogtreecommitdiff
path: root/fsm
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-11-10 21:34:40 -0700
committerSelene ToyKeeper2023-11-10 21:34:40 -0700
commit3d12b7066d27b591e0283e20ed066bc66e29fbe4 (patch)
tree08a0ed41a4b0baa7f7f5ea4eed6ee10ac250250c /fsm
parentadded md5sum to build-all.sh output per target (diff)
downloadanduril-3d12b7066d27b591e0283e20ed066bc66e29fbe4.tar.gz
anduril-3d12b7066d27b591e0283e20ed066bc66e29fbe4.tar.bz2
anduril-3d12b7066d27b591e0283e20ed066bc66e29fbe4.zip
refactor checkpoint: splitting MCU-specific code into arch/$MCU.[ch]
Phew, that's a lot of changes! And there's still a lot more to do...
Diffstat (limited to '')
-rw-r--r--fsm/adc.c159
-rw-r--r--fsm/adc.h12
-rw-r--r--fsm/main.c62
-rw-r--r--fsm/misc.c22
-rw-r--r--fsm/misc.h4
-rw-r--r--fsm/pcint.c54
-rw-r--r--fsm/pcint.h6
-rw-r--r--fsm/spaghetti-monster.h9
-rw-r--r--fsm/wdt.c78
-rw-r--r--fsm/wdt.h7
10 files changed, 47 insertions, 366 deletions
diff --git a/fsm/adc.c b/fsm/adc.c
index 31b250f..6d4eeb1 100644
--- a/fsm/adc.c
+++ b/fsm/adc.c
@@ -16,57 +16,14 @@
static inline void set_admux_therm() {
- #if (ATTINY == 1634)
- ADMUX = ADMUX_THERM;
- #elif (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
- ADMUX = ADMUX_THERM | (1 << ADLAR);
- #elif (ATTINY == 841) // FIXME: not tested
- ADMUXA = ADMUXA_THERM;
- ADMUXB = ADMUXB_THERM;
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- ADC0.MUXPOS = ADC_MUXPOS_TEMPSENSE_gc; // read temperature
- ADC0.CTRLC = ADC_SAMPCAP_bm | ADC_PRESC_DIV64_gc | ADC_REFSEL_INTREF_gc; // Internal ADC reference
- #else
- #error Unrecognized MCU type
- #endif
+ hwdef_set_admux_therm();
adc_channel = 1;
adc_sample_count = 0; // first result is unstable
ADC_start_measurement();
}
inline void set_admux_voltage() {
- #if (ATTINY == 1634)
- #ifdef USE_VOLTAGE_DIVIDER // 1.1V / pin7
- ADMUX = ADMUX_VOLTAGE_DIVIDER;
- #else // VCC / 1.1V reference
- ADMUX = ADMUX_VCC;
- #endif
- #elif (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
- #ifdef USE_VOLTAGE_DIVIDER // 1.1V / pin7
- ADMUX = ADMUX_VOLTAGE_DIVIDER | (1 << ADLAR);
- #else // VCC / 1.1V reference
- ADMUX = ADMUX_VCC | (1 << ADLAR);
- #endif
- #elif (ATTINY == 841) // FIXME: not tested
- #ifdef USE_VOLTAGE_DIVIDER // 1.1V / pin7
- ADMUXA = ADMUXA_VOLTAGE_DIVIDER;
- ADMUXB = ADMUXB_VOLTAGE_DIVIDER;
- #else // VCC / 1.1V reference
- ADMUXA = ADMUXA_VCC;
- ADMUXB = ADMUXB_VCC;
- #endif
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- #ifdef USE_VOLTAGE_DIVIDER // 1.1V / ADC input pin
- // verify that this is correct!!! untested
- ADC0.MUXPOS = ADMUX_VOLTAGE_DIVIDER; // read the requested ADC pin
- ADC0.CTRLC = ADC_SAMPCAP_bm | ADC_PRESC_DIV64_gc | ADC_REFSEL_INTREF_gc; // Use internal ADC reference
- #else // VCC / 1.1V reference
- ADC0.MUXPOS = ADC_MUXPOS_INTREF_gc; // read internal reference
- ADC0.CTRLC = ADC_SAMPCAP_bm | ADC_PRESC_DIV64_gc | ADC_REFSEL_VDDREF_gc; // Vdd (Vcc) be ADC reference
- #endif
- #else
- #error Unrecognized MCU type
- #endif
+ hwdef_set_admux_voltage();
adc_channel = 0;
adc_sample_count = 0; // first result is unstable
ADC_start_measurement();
@@ -74,79 +31,19 @@ inline void set_admux_voltage() {
#ifdef TICK_DURING_STANDBY
-inline void adc_sleep_mode() {
// needs a special sleep mode to get accurate measurements quickly
// ... full power-down ends up using more power overall, and causes
// some weird issues when the MCU doesn't stay awake enough cycles
// to complete a reading
- #ifdef SLEEP_MODE_ADC
- // attiny1634
- set_sleep_mode(SLEEP_MODE_ADC);
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- set_sleep_mode(SLEEP_MODE_STANDBY);
- #else
- #error No ADC sleep mode defined for this hardware.
- #endif
-}
+ #define adc_sleep_mode mcu_adc_sleep_mode
#endif
-inline void ADC_start_measurement() {
- #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) || (ATTINY == 841) || (ATTINY == 1634)
- ADCSRA |= (1 << ADSC) | (1 << ADIE);
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- ADC0.INTCTRL |= ADC_RESRDY_bm; // enable interrupt
- ADC0.COMMAND |= ADC_STCONV_bm; // Start the ADC conversions
- #else
- #error unrecognized MCU type
- #endif
-}
+#define ADC_start_measurement mcu_adc_start_measurement
// set up ADC for reading battery voltage
-inline void ADC_on()
-{
- #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) || (ATTINY == 1634)
- set_admux_voltage();
- #ifdef USE_VOLTAGE_DIVIDER
- // disable digital input on divider pin to reduce power consumption
- VOLTAGE_ADC_DIDR |= (1 << VOLTAGE_ADC);
- #else
- // disable digital input on VCC pin to reduce power consumption
- //VOLTAGE_ADC_DIDR |= (1 << VOLTAGE_ADC); // FIXME: unsure how to handle for VCC pin
- #endif
- #if (ATTINY == 1634)
- //ACSRA |= (1 << ACD); // turn off analog comparator to save power
- ADCSRB |= (1 << ADLAR); // left-adjust flag is here instead of ADMUX
- #endif
- // enable, start, auto-retrigger, prescale
- ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADATE) | ADC_PRSCL;
- // end tiny25/45/85
- #elif (ATTINY == 841) // FIXME: not tested, missing left-adjust
- ADCSRB = 0; // Right adjusted, auto trigger bits cleared.
- //ADCSRA = (1 << ADEN ) | 0b011; // ADC on, prescaler division factor 8.
- set_admux_voltage();
- // enable, start, auto-retrigger, prescale
- ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADATE) | ADC_PRSCL;
- //ADCSRA |= (1 << ADSC); // start measuring
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- VREF.CTRLA |= VREF_ADC0REFSEL_1V1_gc; // Set Vbg ref to 1.1V
- // Enabled, free-running (aka, auto-retrigger), run in standby
- ADC0.CTRLA = ADC_ENABLE_bm | ADC_FREERUN_bm | ADC_RUNSTBY_bm;
- // set a INITDLY value because the AVR manual says so (section 30.3.5)
- // (delay 1st reading until Vref is stable)
- ADC0.CTRLD |= ADC_INITDLY_DLY16_gc;
- set_admux_voltage();
- #else
- #error Unrecognized MCU type
- #endif
-}
-
-inline void ADC_off() {
- #ifdef AVRXMEGA3 // ATTINY816, 817, etc
- ADC0.CTRLA &= ~(ADC_ENABLE_bm); // disable the ADC
- #else
- ADCSRA &= ~(1<<ADEN); //ADC off
- #endif
-}
+#define ADC_on mcu_adc_on
+// stop the ADC
+#define ADC_off mcu_adc_off
#ifdef USE_VOLTAGE_DIVIDER
static inline uint8_t calc_voltage_divider(uint16_t value) {
@@ -171,15 +68,11 @@ static inline uint8_t calc_voltage_divider(uint16_t value) {
#define ADC_CYCLES_PER_SECOND 2
#endif
-#ifdef AVRXMEGA3 // ATTINY816, 817, etc
-#define ADC_vect ADC0_RESRDY_vect
-#endif
// happens every time the ADC sampler finishes a measurement
ISR(ADC_vect) {
- #ifdef AVRXMEGA3 // ATTINY816, 817, etc
- ADC0.INTFLAGS = ADC_RESRDY_bm; // clear the interrupt
- #endif
+ // clear the interrupt flag
+ mcu_adc_vect_clear();
if (adc_sample_count) {
@@ -188,22 +81,12 @@ ISR(ADC_vect) {
uint8_t channel = adc_channel;
// update the latest value
- #ifdef AVRXMEGA3 // ATTINY816, 817, etc
- // Use the factory calibrated values in SIGROW.TEMPSENSE0 and SIGROW.TEMPSENSE1
- // to calculate a temperature reading in Kelvin, then left-align it.
- if (channel == 1) { // thermal, convert ADC reading to left-aligned Kelvin
- int8_t sigrow_offset = SIGROW.TEMPSENSE1; // Read signed value from signature row
- uint8_t sigrow_gain = SIGROW.TEMPSENSE0; // Read unsigned value from signature row
- uint32_t temp = ADC0.RES - sigrow_offset;
- temp *= sigrow_gain; // Result might overflow 16 bit variable (10bit+8bit)
- temp += 0x80; // Add 1/2 to get correct rounding on division below
- temp >>= 8; // Divide result to get Kelvin
- m = (temp << 6); // left align it
- }
- else { m = (ADC0.RES << 6); } // voltage, force left-alignment
-
+ #ifdef MCU_ADC_RESULT_PER_TYPE
+ // thermal, convert ADC reading to left-aligned Kelvin
+ if (channel) m = mcu_adc_result_temp();
+ else m = mcu_adc_result_volts();
#else
- m = ADC;
+ m = mcu_adc_result();
#endif
adc_raw[channel] = m;
@@ -235,11 +118,7 @@ void adc_deferred() {
// real-world entropy makes this a true random, not pseudo
// Why here instead of the ISR? Because it makes the time-critical ISR
// code a few cycles faster and we don't need crypto-grade randomness.
- #ifdef AVRXMEGA3 // ATTINY816, 817, etc
- pseudo_rand_seed += ADC0.RESL; // right aligned, not left... so should be equivalent?
- #else
- pseudo_rand_seed += (ADCL >> 6) + (ADCH << 2);
- #endif
+ pseudo_rand_seed += mcu_adc_lsb();
#endif
// the ADC triggers repeatedly when it's on, but we only need to run the
@@ -373,9 +252,9 @@ static inline void ADC_voltage_handler() {
if (lvp_timer) {
lvp_timer --;
} else { // it has been long enough since the last warning
- #ifdef DUAL_VOLTAGE_FLOOR
- if (((voltage < VOLTAGE_LOW) && (voltage > DUAL_VOLTAGE_FLOOR)) || (voltage < DUAL_VOLTAGE_LOW_LOW)) {
- #else
+ #ifdef DUAL_VOLTAGE_FLOOR
+ if (((voltage < VOLTAGE_LOW) && (voltage > DUAL_VOLTAGE_FLOOR)) || (voltage < DUAL_VOLTAGE_LOW_LOW)) {
+ #else
if (voltage < VOLTAGE_LOW) {
#endif
// send out a warning
@@ -440,6 +319,8 @@ static inline void ADC_temperature_handler() {
// let the UI see the current temperature in C
// Convert ADC units to Celsius (ish)
+ // FIXME: call something in arch/$mcu.h or hwdef.h
+ // instead of calculating this here
#ifndef USE_EXTERNAL_TEMP_SENSOR
// onboard sensor for attiny25/45/85/1634
temperature = (measurement>>1) + THERM_CAL_OFFSET + (int16_t)TH_CAL - 275;
diff --git a/fsm/adc.h b/fsm/adc.h
index 1bb67ed..e4046a4 100644
--- a/fsm/adc.h
+++ b/fsm/adc.h
@@ -102,11 +102,15 @@ static inline void ADC_temperature_handler();
#endif // ifdef USE_THERMAL_REGULATION
-inline void ADC_on();
-inline void ADC_off();
-inline void ADC_start_measurement();
+//inline void ADC_on();
+#define ADC_on mcu_adc_on
+//inline void ADC_off();
+#define ADC_off mcu_adc_off
+//inline void ADC_start_measurement();
+#define ADC_start_measurement mcu_adc_start_measurement
#ifdef TICK_DURING_STANDBY
-inline void adc_sleep_mode();
+ //inline void adc_sleep_mode();
+ #define adc_sleep_mode mcu_adc_sleep_mode
#endif
diff --git a/fsm/main.c b/fsm/main.c
index 0524115..1c01878 100644
--- a/fsm/main.c
+++ b/fsm/main.c
@@ -23,66 +23,6 @@ ISR(TIMER1_COMPA_vect) {
}
#endif
-// FIXME: hw_setup() shouldn't be here ... move it entirely to hwdef files
-#if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
-static inline void hw_setup() {
- #if !defined(USE_GENERIC_HWDEF_SETUP)
- hwdef_setup();
- #else
- // configure PWM channels
- #if PWM_CHANNELS >= 1
- DDRB |= (1 << PWM1_PIN);
- TCCR0B = 0x01; // pre-scaler for timer (1 => 1, 2 => 8, 3 => 64...)
- TCCR0A = PHASE;
- #if (PWM1_PIN == PB4) // Second PWM counter is ... weird
- TCCR1 = _BV (CS10);
- GTCCR = _BV (COM1B1) | _BV (PWM1B);
- OCR1C = 255; // Set ceiling value to maximum
- #endif
- #endif
- // tint ramping needs second channel enabled,
- // despite PWM_CHANNELS being only 1
- #if (PWM_CHANNELS >= 2) || defined(USE_TINT_RAMPING)
- DDRB |= (1 << PWM2_PIN);
- #if (PWM2_PIN == PB4) // Second PWM counter is ... weird
- TCCR1 = _BV (CS10);
- GTCCR = _BV (COM1B1) | _BV (PWM1B);
- OCR1C = 255; // Set ceiling value to maximum
- #endif
- #endif
- #if PWM_CHANNELS >= 3
- DDRB |= (1 << PWM3_PIN);
- #if (PWM3_PIN == PB4) // Second PWM counter is ... weird
- TCCR1 = _BV (CS10);
- GTCCR = _BV (COM1B1) | _BV (PWM1B);
- OCR1C = 255; // Set ceiling value to maximum
- #endif
- #endif
- #if PWM_CHANNELS >= 4
- // 4th PWM channel is ... not actually supported in hardware :(
- DDRB |= (1 << PWM4_PIN);
- //OCR1C = 255; // Set ceiling value to maximum
- TCCR1 = 1<<CTC1 | 1<<PWM1A | 3<<COM1A0 | 2<<CS10;
- GTCCR = (2<<COM1B0) | (1<<PWM1B);
- // set up an interrupt to control PWM4 pin
- TIMSK |= (1<<OCIE1A) | (1<<TOIE1);
- #endif
-
- // configure e-switch
- PORTB = (1 << SWITCH_PIN); // e-switch is the only input
- PCMSK = (1 << SWITCH_PIN); // pin change interrupt uses this pin
- #endif // ifdef USE_GENERIC_HWDEF_SETUP
-}
-#elif (ATTINY == 1634) || defined(AVRXMEGA3) // ATTINY816, 817, etc
-static inline void hw_setup() {
- // this gets tricky with so many pins...
- // ... so punt it to the hwdef file
- hwdef_setup();
-}
-#else
- #error Unrecognized MCU type
-#endif
-
//#ifdef USE_REBOOT
static inline void prevent_reboot_loop() {
@@ -107,7 +47,7 @@ int main() {
prevent_reboot_loop();
//#endif
- hw_setup();
+ hwdef_setup();
#if 0
#ifdef HALFSPEED
diff --git a/fsm/misc.c b/fsm/misc.c
index bc10ea1..5d58f52 100644
--- a/fsm/misc.c
+++ b/fsm/misc.c
@@ -288,25 +288,3 @@ uint8_t triangle_wave(uint8_t phase) {
}
#endif
-#ifdef USE_REBOOT
-void reboot() {
- // put the WDT in hard reset mode, then trigger it
- cli();
- #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
- WDTCR = 0xD8 | WDTO_15MS;
- #elif (ATTINY == 1634)
- // allow protected configuration changes for next 4 clock cycles
- CCP = 0xD8; // magic number
- // reset (WDIF + WDE), no WDIE, fastest (16ms) timing (0000)
- // (DS section 8.5.2 and table 8-4)
- WDTCSR = 0b10001000;
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- CCP = CCP_IOREG_gc; // temporarily disable change protection
- WDT.CTRLA = WDT_PERIOD_8CLK_gc; // Enable, timeout 8ms
- #endif
- sei();
- wdt_reset();
- while (1) {}
-}
-#endif
-
diff --git a/fsm/misc.h b/fsm/misc.h
index 8de6b29..ba1f8d9 100644
--- a/fsm/misc.h
+++ b/fsm/misc.h
@@ -62,7 +62,3 @@ void rgb_led_set(uint8_t value);
uint8_t triangle_wave(uint8_t phase);
#endif
-#ifdef USE_REBOOT
-void reboot();
-#endif
-
diff --git a/fsm/pcint.c b/fsm/pcint.c
index 131d0c3..d00b51d 100644
--- a/fsm/pcint.c
+++ b/fsm/pcint.c
@@ -13,58 +13,8 @@ uint8_t button_is_pressed() {
return value;
}
-inline void PCINT_on() {
- #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
- // enable pin change interrupt
- GIMSK |= (1 << PCIE);
- // only pay attention to the e-switch pin
- #if 0 // this is redundant; was already done in main()
- PCMSK = (1 << SWITCH_PCINT);
- #endif
- // set bits 1:0 to 0b01 (interrupt on rising *and* falling edge) (default)
- // MCUCR &= 0b11111101; MCUCR |= 0b00000001;
- #elif (ATTINY == 1634)
- // enable pin change interrupt
- #ifdef SWITCH2_PCIE
- GIMSK |= ((1 << SWITCH_PCIE) | (1 << SWITCH2_PCIE));
- #else
- GIMSK |= (1 << SWITCH_PCIE);
- #endif
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc)
- SWITCH_ISC_REG |= PORT_ISC_BOTHEDGES_gc;
- #else
- #error Unrecognized MCU type
- #endif
-}
-
-inline void PCINT_off() {
- #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
- // disable all pin-change interrupts
- GIMSK &= ~(1 << PCIE);
- #elif (ATTINY == 1634)
- // disable all pin-change interrupts
- GIMSK &= ~(1 << SWITCH_PCIE);
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc)
- SWITCH_ISC_REG &= ~(PORT_ISC_gm);
- #else
- #error Unrecognized MCU type
- #endif
-}
-
-//void button_change_interrupt() {
-#if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) || (ATTINY == 1634)
- #ifdef PCINT_vect
- ISR(PCINT_vect) {
- #else
- ISR(PCINT0_vect) {
- #endif
-#elif defined(AVRXMEGA3) // ATTINY816, 817, etc)
- ISR(SWITCH_VECT) {
- // Write a '1' to clear the interrupt flag
- SWITCH_INTFLG |= (1 << SWITCH_PIN);
-#else
- #error Unrecognized MCU type
-#endif
+ISR(SWITCH_VECT) {
+ mcu_switch_vect_clear();
irq_pcint = 1; // let deferred code know an interrupt happened
diff --git a/fsm/pcint.h b/fsm/pcint.h
index cd7ba02..62f93ab 100644
--- a/fsm/pcint.h
+++ b/fsm/pcint.h
@@ -9,7 +9,9 @@ volatile uint8_t irq_pcint = 0; // pin change interrupt happened?
#define BP_SAMPLES 32
volatile uint8_t button_last_state;
uint8_t button_is_pressed();
-inline void PCINT_on();
-inline void PCINT_off();
+//inline void PCINT_on();
+//inline void PCINT_off();
+#define PCINT_on mcu_pcint_on
+#define PCINT_off mcu_pcint_off
void PCINT_inner(uint8_t pressed);
diff --git a/fsm/spaghetti-monster.h b/fsm/spaghetti-monster.h
index c035d5b..7084ad4 100644
--- a/fsm/spaghetti-monster.h
+++ b/fsm/spaghetti-monster.h
@@ -13,10 +13,9 @@
* - ...
*/
-#include "arch/mcu.h"
+////////// include all the .h files //////////
-#include <avr/eeprom.h>
-#include <avr/power.h>
+#include "arch/mcu.h"
// include project definitions to help with recognizing symbols
#include "fsm/events.h"
@@ -39,6 +38,10 @@
#include "arch/delay.h"
#endif
+////////// include all the .c files //////////
+
+#include "arch/mcu.c"
+
#ifdef USE_DEBUG_BLINK
#define DEBUG_FLASH PWM1_LVL = 64; delay_4ms(2); PWM1_LVL = 0;
void debug_blink(uint8_t num) {
diff --git a/fsm/wdt.c b/fsm/wdt.c
index 64f006e..1095d44 100644
--- a/fsm/wdt.c
+++ b/fsm/wdt.c
@@ -7,85 +7,9 @@
#include <avr/interrupt.h>
#include <avr/wdt.h>
-// *** Note for the AVRXMEGA3 (1-Series, eg 816 and 817), the WDT
-// is not used for time-based interrupts. A new peripheral, the
-// Periodic Interrupt Timer ("PIT") is used for this purpose.
-
-void WDT_on()
-{
- #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
- // interrupt every 16ms
- //cli(); // Disable interrupts
- wdt_reset(); // Reset the WDT
- WDTCR |= (1<<WDCE) | (1<<WDE); // Start timed sequence
- WDTCR = (1<<WDIE); // Enable interrupt every 16ms
- //sei(); // Enable interrupts
- #elif (ATTINY == 1634)
- wdt_reset(); // Reset the WDT
- WDTCSR = (1<<WDIE); // Enable interrupt every 16ms
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- RTC.PITINTCTRL = RTC_PI_bm; // enable the Periodic Interrupt
- while (RTC.PITSTATUS > 0) {} // make sure the register is ready to be updated
- RTC.PITCTRLA = RTC_PERIOD_CYC512_gc | RTC_PITEN_bm; // Period = 16ms, enable the PI Timer
- #else
- #error Unrecognized MCU type
- #endif
-}
-
-#ifdef TICK_DURING_STANDBY
-inline void WDT_slow()
-{
- #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
- // interrupt slower
- //cli(); // Disable interrupts
- wdt_reset(); // Reset the WDT
- WDTCR |= (1<<WDCE) | (1<<WDE); // Start timed sequence
- WDTCR = (1<<WDIE) | STANDBY_TICK_SPEED; // Enable interrupt every so often
- //sei(); // Enable interrupts
- #elif (ATTINY == 1634)
- wdt_reset(); // Reset the WDT
- WDTCSR = (1<<WDIE) | STANDBY_TICK_SPEED;
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- RTC.PITINTCTRL = RTC_PI_bm; // enable the Periodic Interrupt
- while (RTC.PITSTATUS > 0) {} // make sure the register is ready to be updated
- RTC.PITCTRLA = (1<<6) | (STANDBY_TICK_SPEED<<3) | RTC_PITEN_bm; // Set period, enable the PI Timer
- #else
- #error Unrecognized MCU type
- #endif
-}
-#endif
-
-inline void WDT_off()
-{
- #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
- //cli(); // Disable interrupts
- wdt_reset(); // Reset the WDT
- MCUSR &= ~(1<<WDRF); // Clear Watchdog reset flag
- WDTCR |= (1<<WDCE) | (1<<WDE); // Start timed sequence
- WDTCR = 0x00; // Disable WDT
- //sei(); // Enable interrupts
- #elif (ATTINY == 1634)
- cli(); // needed because CCP, below
- wdt_reset(); // Reset the WDT
- MCUSR &= ~(1<<WDRF); // clear watchdog reset flag
- CCP = 0xD8; // enable config changes
- WDTCSR = 0; // disable and clear all WDT settings
- sei();
- #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- while (RTC.PITSTATUS > 0) {} // make sure the register is ready to be updated
- RTC.PITCTRLA = 0; // Disable the PI Timer
- #else
- #error Unrecognized MCU type
- #endif
-}
-
// clock tick -- this runs every 16ms (62.5 fps)
-#ifdef AVRXMEGA3 // ATTINY816, 817, etc
-ISR(RTC_PIT_vect) {
- RTC.PITINTFLAGS = RTC_PI_bm; // clear the PIT interrupt flag
-#else
ISR(WDT_vect) {
-#endif
+ mcu_wdt_vect_clear();
irq_wdt = 1; // WDT event happened
}
diff --git a/fsm/wdt.h b/fsm/wdt.h
index abf34c5..98eaf25 100644
--- a/fsm/wdt.h
+++ b/fsm/wdt.h
@@ -6,8 +6,11 @@
#define TICKS_PER_SECOND 62
-void WDT_on();
-inline void WDT_off();
+//void WDT_on();
+//inline void WDT_off();
+#define WDT_on mcu_wdt_active
+#define WDT_slow mcu_wdt_standby
+#define WDT_off mcu_wdt_stop
volatile uint8_t irq_wdt = 0; // WDT interrupt happened?