diff options
| author | Selene ToyKeeper | 2023-11-10 21:34:40 -0700 |
|---|---|---|
| committer | Selene ToyKeeper | 2023-11-10 21:34:40 -0700 |
| commit | 3d12b7066d27b591e0283e20ed066bc66e29fbe4 (patch) | |
| tree | 08a0ed41a4b0baa7f7f5ea4eed6ee10ac250250c /fsm/wdt.c | |
| parent | added md5sum to build-all.sh output per target (diff) | |
| download | anduril-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/wdt.c | 78 |
1 files changed, 1 insertions, 77 deletions
@@ -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 } |
