summaryrefslogtreecommitdiffstats
path: root/firmware/main.c
diff options
context:
space:
mode:
authorcpldcpu <cpldcpu@gmail.com>2013-10-07 00:12:29 +0200
committercpldcpu <cpldcpu@gmail.com>2013-10-07 00:12:29 +0200
commit839fd47f9bb8c8195c337cf752a95b1a39bcb1e6 (patch)
treeb800616a4c3893e9b3e6d890d2b79dfb133f1ff7 /firmware/main.c
parent37fed5ca98cf5d47f9aa75dab6463e075643616f (diff)
downloadmicronucleus-839fd47f9bb8c8195c337cf752a95b1a39bcb1e6.tar.gz
micronucleus-839fd47f9bb8c8195c337cf752a95b1a39bcb1e6.tar.bz2
micronucleus-839fd47f9bb8c8195c337cf752a95b1a39bcb1e6.zip
Use a local pointer in eraseApplicatoin() - saves 18 Bytes
Diffstat (limited to 'firmware/main.c')
-rw-r--r--firmware/main.c17
1 files changed, 8 insertions, 9 deletions
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();
}