From c4907c6896943eb3ff778cb007a9891ac7b68248 Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Sat, 4 Jan 2014 15:22:34 +0100 Subject: just log current state --- firmware/main.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 91 insertions(+), 19 deletions(-) (limited to 'firmware/main.c') diff --git a/firmware/main.c b/firmware/main.c index 16cca65..1fdda03 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -27,9 +27,6 @@ #include #include "bootloaderconfig.h" - - - #include "usbdrv/usbdrv.c" // verify the bootloader address aligns with page size @@ -100,9 +97,9 @@ static inline void eraseApplication(void) { // simply write currently stored page in to already erased flash memory static void writeFlashPage(void) { - cli(); + // cli(); boot_page_write(currentAddress.w - 2); // will halt CPU, no waiting required - sei(); + // sei(); } // clear memory which stores data to be written by next writeFlashPage call @@ -147,14 +144,14 @@ static void writeWordToPageBuffer(uint16_t data) { #endif } - previous_sreg=SREG; - cli(); // ensure interrupts are disabled + // previous_sreg=SREG; + // cli(); // ensure interrupts are disabled boot_page_fill(currentAddress.w, data); // increment progmem address by one word currentAddress.w += 2; - SREG=previous_sreg; + // SREG=previous_sreg; } // This function is never called, it is just here to suppress a compiler warning. @@ -231,11 +228,14 @@ static void initHardware (void) #endif usbDeviceDisconnect(); /* do this while interrupts are disabled */ - _delay_ms(500); + _delay_ms(300); usbDeviceConnect(); + + // Todo: timeout if no reset is found + calibrateOscillatorASM(); usbInit(); // Initialize INT settings after reconnect - - sei(); + + // sei(); } /* ------------------------------------------------------------------------ */ @@ -244,7 +244,7 @@ static void leaveBootloader(void) __attribute__((__noreturn__)); static inline void leaveBootloader(void) { bootLoaderExit(); - cli(); + //cli(); usbDeviceDisconnect(); /* Disconnect micronucleus */ USB_INTR_ENABLE = 0; @@ -271,6 +271,33 @@ static inline void leaveBootloader(void) { for (;;); // Make sure function does not return to help compiler optimize } + +static void wait_usb_interrupt( void ) +{ + // Clear any stale pending interrupt, then wait for interrupt flag + USB_INTR_PENDING = 1<