|
@@ -35,12 +35,31 @@
|
35
|
35
|
// Public Variables
|
36
|
36
|
// ------------------------
|
37
|
37
|
|
38
|
|
-//uint8_t MCUSR;
|
|
38
|
+// Don't initialize/override variable (which would happen in .init4)
|
|
39
|
+uint8_t reset_reason __attribute__((section(".noinit")));
|
39
|
40
|
|
40
|
41
|
// ------------------------
|
41
|
42
|
// Public functions
|
42
|
43
|
// ------------------------
|
43
|
44
|
|
|
45
|
+__attribute__((naked)) // Don't output function pro- and epilogue
|
|
46
|
+__attribute__((used)) // Output the function, even if "not used"
|
|
47
|
+__attribute__((section(".init3"))) // Put in an early user definable section
|
|
48
|
+void HAL_save_reset_reason() {
|
|
49
|
+ #if ENABLED(OPTIBOOT_RESET_REASON)
|
|
50
|
+ __asm__ __volatile__(
|
|
51
|
+ A("STS %0, r2")
|
|
52
|
+ : "=m"(reset_reason)
|
|
53
|
+ );
|
|
54
|
+ #else
|
|
55
|
+ reset_reason = MCUSR;
|
|
56
|
+ #endif
|
|
57
|
+
|
|
58
|
+ // Clear within 16ms since WDRF bit enables a 16ms watchdog timer -> Boot loop
|
|
59
|
+ MCUSR = 0;
|
|
60
|
+ wdt_disable();
|
|
61
|
+}
|
|
62
|
+
|
44
|
63
|
void HAL_init() {
|
45
|
64
|
// Init Servo Pins
|
46
|
65
|
#define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
|