🐛 Prevent AVR watchdogpile (#23075)
This commit is contained in:
@ -35,12 +35,31 @@
|
||||
// Public Variables
|
||||
// ------------------------
|
||||
|
||||
//uint8_t MCUSR;
|
||||
// Don't initialize/override variable (which would happen in .init4)
|
||||
uint8_t reset_reason __attribute__((section(".noinit")));
|
||||
|
||||
// ------------------------
|
||||
// Public functions
|
||||
// ------------------------
|
||||
|
||||
__attribute__((naked)) // Don't output function pro- and epilogue
|
||||
__attribute__((used)) // Output the function, even if "not used"
|
||||
__attribute__((section(".init3"))) // Put in an early user definable section
|
||||
void HAL_save_reset_reason() {
|
||||
#if ENABLED(OPTIBOOT_RESET_REASON)
|
||||
__asm__ __volatile__(
|
||||
A("STS %0, r2")
|
||||
: "=m"(reset_reason)
|
||||
);
|
||||
#else
|
||||
reset_reason = MCUSR;
|
||||
#endif
|
||||
|
||||
// Clear within 16ms since WDRF bit enables a 16ms watchdog timer -> Boot loop
|
||||
MCUSR = 0;
|
||||
wdt_disable();
|
||||
}
|
||||
|
||||
void HAL_init() {
|
||||
// Init Servo Pins
|
||||
#define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
|
||||
|
@ -91,7 +91,7 @@ typedef int8_t pin_t;
|
||||
// Public Variables
|
||||
// ------------------------
|
||||
|
||||
//extern uint8_t MCUSR;
|
||||
extern uint8_t reset_reason;
|
||||
|
||||
// Serial ports
|
||||
#ifdef USBCON
|
||||
@ -152,8 +152,8 @@ void HAL_init();
|
||||
|
||||
//void _delay_ms(const int delay);
|
||||
|
||||
inline void HAL_clear_reset_source() { MCUSR = 0; }
|
||||
inline uint8_t HAL_get_reset_source() { return MCUSR; }
|
||||
inline void HAL_clear_reset_source() { }
|
||||
inline uint8_t HAL_get_reset_source() { return reset_reason; }
|
||||
|
||||
void HAL_reboot();
|
||||
|
||||
|
Reference in New Issue
Block a user