aboutsummaryrefslogtreecommitdiff
path: root/common/bootloader.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2012-06-30 11:19:07 +0900
committertmk <nobody@nowhere>2012-06-30 11:19:07 +0900
commitf427529a30487de45ebfbe6fbba9c290738878ab (patch)
tree41dc7ce0eaaba0fababff07b39518d86e557143c /common/bootloader.c
parenta112f3614e0e3204ce35dcdfbf2723c3382c4c35 (diff)
downloadqmk_firmware-f427529a30487de45ebfbe6fbba9c290738878ab.tar.gz
qmk_firmware-f427529a30487de45ebfbe6fbba9c290738878ab.zip
Fix bootloader.c
Diffstat (limited to 'common/bootloader.c')
-rw-r--r--common/bootloader.c68
1 files changed, 51 insertions, 17 deletions
diff --git a/common/bootloader.c b/common/bootloader.c
index 5cbfc72e5..cb971c704 100644
--- a/common/bootloader.c
+++ b/common/bootloader.c
@@ -1,22 +1,56 @@
1/* 1#include <avr/io.h>
2Copyright 2011 Jun Wako <wakojun@gmail.com> 2#include <avr/interrupt.h>
3 3#include <util/delay.h>
4This program is free software: you can redistribute it and/or modify 4#include "bootloader.h"
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8 5
9This program is distributed in the hope that it will be useful, 6/* Start Bootloader from Application
10but WITHOUT ANY WARRANTY; without even the implied warranty of 7 * See
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 8 * http://www.pjrc.com/teensy/jump_to_bootloader.html
12GNU General Public License for more details. 9 * http://www.fourwalledcubicle.com/files/LUFA/Doc/120219/html/_page__software_bootloader_start.html
10 */
13 11
14You should have received a copy of the GNU General Public License 12/* Boot Section Size in bytes
15along with this program. If not, see <http://www.gnu.org/licenses/>. 13 * Teensy halfKay 512
16*/ 14 * Atmel DFU loader 4096
15 * LUFA bootloader 4096
16 */
17#ifndef BOOT_SIZE
18#define BOOT_SIZE 512
19#endif
17 20
18#include "bootloader.h" 21#define FLASH_SIZE (FLASHEND + 1)
22#define BOOTLOADER_START (FLASHEND - BOOT_SIZE)
19 23
24void bootloader_jump(void) {
25 cli();
26 // disable watchdog, if enabled
27 // disable all peripherals
28 UDCON = 1;
29 USBCON = (1<<FRZCLK); // disable USB
30 UCSR1B = 0;
31 _delay_ms(5);
32#if defined(__AVR_AT90USB162__)
33 EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0;
34 TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0;
35 DDRB = 0; DDRC = 0; DDRD = 0;
36 PORTB = 0; PORTC = 0; PORTD = 0;
37#elif defined(__AVR_ATmega32U4__)
38 EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
39 TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0;
40 DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0;
41 PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
42#elif defined(__AVR_AT90USB646__)
43 EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
44 TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
45 DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
46 PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
47#elif defined(__AVR_AT90USB1286__)
48 EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
49 TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
50 DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
51 PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
52#endif
20 53
21void bootloader_jump(void) __attribute__ ((weak)); 54 // start Bootloader
22void bootloader_jump(void) {} 55 ((void (*)(void))BOOTLOADER_START)();
56}