summaryrefslogtreecommitdiffstats
path: root/firmware/main.c
diff options
context:
space:
mode:
authorJenna Fox <a@creativepony.com>2012-09-24 00:59:13 +1000
committerJenna Fox <a@creativepony.com>2012-09-24 00:59:13 +1000
commitc2bee67e1e35dda3cd1aa9fabc755be39de4a83c (patch)
tree11efff2c298d066dd5f02aa970d4552446ac382e /firmware/main.c
parentd9ed646bd2495c6ab8524a35bd984f5526ee65ec (diff)
downloadmicronucleus-c2bee67e1e35dda3cd1aa9fabc755be39de4a83c.tar.gz
micronucleus-c2bee67e1e35dda3cd1aa9fabc755be39de4a83c.tar.bz2
micronucleus-c2bee67e1e35dda3cd1aa9fabc755be39de4a83c.zip
Victory
Diffstat (limited to 'firmware/main.c')
-rw-r--r--firmware/main.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/firmware/main.c b/firmware/main.c
index b8a88ea..f94498f 100644
--- a/firmware/main.c
+++ b/firmware/main.c
@@ -121,6 +121,7 @@ static inline void eraseFlashPage(void) {
}
static void writeFlashPage(void) {
+ didWriteSomething = 1;
cli();
boot_page_write(currentAddress - 2);
boot_spm_busy_wait(); // Wait until the memory is written.
@@ -183,29 +184,6 @@ static void fillFlashWithVectors(void) {
writeFlashPage();
}
-
-static inline __attribute__((noreturn)) void leaveBootloader(void) {
- //DBG1(0x01, 0, 0);
- bootLoaderExit();
- cli();
- USB_INTR_ENABLE = 0;
- USB_INTR_CFG = 0; /* also reset config bits */
-
- // make sure remainder of flash is erased and write checksum and application reset vectors
- if (didWriteSomething) {
- while (currentAddress < BOOTLOADER_ADDRESS) {
- fillFlashWithVectors();
- }
- }
-
- // clear magic word from bottom of stack before jumping to the app
- *(uint8_t*)(RAMEND) = 0x00;
- *(uint8_t*)(RAMEND-1) = 0x00;
-
- // jump to application reset vector at end of flash
- asm volatile ("rjmp __vectors - 4");
-}
-
/* ------------------------------------------------------------------------ */
static uchar usbFunctionSetup(uchar data[8]) {
@@ -319,6 +297,28 @@ static inline void tiny85FlashWrites(void) {
}
}
+static inline __attribute__((noreturn)) void leaveBootloader(void) {
+ //DBG1(0x01, 0, 0);
+ bootLoaderExit();
+ cli();
+ USB_INTR_ENABLE = 0;
+ USB_INTR_CFG = 0; /* also reset config bits */
+
+ // make sure remainder of flash is erased and write checksum and application reset vectors
+ if (didWriteSomething) {
+ while (currentAddress < BOOTLOADER_ADDRESS) {
+ fillFlashWithVectors();
+ }
+ }
+
+ // clear magic word from bottom of stack before jumping to the app
+ *(uint8_t*)(RAMEND) = 0x00;
+ *(uint8_t*)(RAMEND-1) = 0x00;
+
+ // jump to application reset vector at end of flash
+ asm volatile ("rjmp __vectors - 4");
+}
+
int __attribute__((noreturn)) main(void) {
uint16_t idlePolls = 0;