From 839fd47f9bb8c8195c337cf752a95b1a39bcb1e6 Mon Sep 17 00:00:00 2001 From: cpldcpu Date: Mon, 7 Oct 2013 00:12:29 +0200 Subject: Use a local pointer in eraseApplicatoin() - saves 18 Bytes --- firmware/main.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'firmware/main.c') diff --git a/firmware/main.c b/firmware/main.c index e56de62..d9f9949 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -96,7 +96,7 @@ static uchar events = 0; // bitmap of events to run #define isEvent(event) (events & (event)) #define clearEvents() events = 0 -// length of bytes to write in to flash memory in upcomming usbFunctionWrite calls +// length of bytes to write in to flash memory in upcoming usbFunctionWrite calls //static unsigned char writeLength; // becomes 1 when some programming happened @@ -105,12 +105,9 @@ static uchar didWriteSomething = 0; uint16_t idlePolls = 0; // how long have we been idle? - - static uint16_t vectorTemp[2]; // remember data to create tinyVector table before BOOTLOADER_ADDRESS static addr_t currentAddress; // current progmem address, used for erasing and writing - /* ------------------------------------------------------------------------ */ static inline void eraseApplication(void); static void writeFlashPage(void); @@ -127,21 +124,23 @@ static inline void leaveBootloader(void); // erase any existing application and write in jumps for usb interrupt and reset to bootloader // - Because flash can be erased once and programmed several times, we can write the bootloader // - vectors in now, and write in the application stuff around them later. -// - if vectors weren't written back in immidately, usb would fail. +// - if vectors weren't written back in immediately, usb would fail. static inline void eraseApplication(void) { // erase all pages until bootloader, in reverse order (so our vectors stay in place for as long as possible) // while the vectors don't matter for usb comms as interrupts are disabled during erase, it's important // to minimise the chance of leaving the device in a state where the bootloader wont run, if there's power failure // during upload - currentAddress = BOOTLOADER_ADDRESS; + addr_t ptr = BOOTLOADER_ADDRESS; +// currentAddress = BOOTLOADER_ADDRESS; cli(); - while (currentAddress) { - currentAddress -= SPM_PAGESIZE; + while (ptr) { + ptr -= SPM_PAGESIZE; - boot_page_erase(currentAddress); + boot_page_erase(ptr); boot_spm_busy_wait(); } + currentAddress = 0; fillFlashWithVectors(); sei(); } -- cgit v1.2.3