aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/avr/bootloader.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/avr/bootloader.c')
-rw-r--r--tmk_core/common/avr/bootloader.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c
index 7c744e8c7..fb9bf2d1c 100644
--- a/tmk_core/common/avr/bootloader.c
+++ b/tmk_core/common/avr/bootloader.c
@@ -73,26 +73,46 @@ uint32_t reset_key __attribute__ ((section (".noinit")));
73 73
74/* initialize MCU status by watchdog reset */ 74/* initialize MCU status by watchdog reset */
75void bootloader_jump(void) { 75void bootloader_jump(void) {
76#ifdef PROTOCOL_LUFA 76 #ifndef CATERINA_BOOTLOADER
77 USB_Disable();
78 cli();
79 _delay_ms(2000);
80#endif
81 77
82#ifdef PROTOCOL_PJRC 78 #ifdef PROTOCOL_LUFA
83 cli(); 79 USB_Disable();
84 UDCON = 1; 80 cli();
85 USBCON = (1<<FRZCLK); 81 _delay_ms(2000);
86 UCSR1B = 0; 82 #endif
87 _delay_ms(5);
88#endif
89 83
90 // watchdog reset 84 #ifdef PROTOCOL_PJRC
91 reset_key = BOOTLOADER_RESET_KEY; 85 cli();
92 wdt_enable(WDTO_250MS); 86 UDCON = 1;
93 for (;;); 87 USBCON = (1<<FRZCLK);
94} 88 UCSR1B = 0;
89 _delay_ms(5);
90 #endif
91
92 // watchdog reset
93 reset_key = BOOTLOADER_RESET_KEY;
94 wdt_enable(WDTO_250MS);
95 for (;;);
96
97 #else
98 // this block may be optional
99 // TODO: figure it out
100
101 uint16_t *const bootKeyPtr = (uint16_t *)0x0800;
95 102
103 // Value used by Caterina bootloader use to determine whether to run the
104 // sketch or the bootloader programmer.
105 uint16_t bootKey = 0x7777;
106
107 *bootKeyPtr = bootKey;
108
109 // setup watchdog timeout
110 wdt_enable(WDTO_60MS);
111
112 while(1) {} // wait for watchdog timer to trigger
113
114 #endif
115}
96 116
97/* this runs before main() */ 117/* this runs before main() */
98void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); 118void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3")));