diff options
author | WestfW <westfw@gmail.com> | 2011-06-10 23:02:25 -0700 |
---|---|---|
committer | WestfW <westfw@gmail.com> | 2011-06-10 23:02:25 -0700 |
commit | a78553bd13fb9cbb03b574b363c8f68a7289dc11 (patch) | |
tree | 44ace5d942d8acfa04f4436253df8538ca9770f0 /bootloaders/optiboot/optiboot.c | |
parent | 2a83ee55b38c81df04d7d3b83d6bf68ed72936e4 (diff) |
Shrink code by using registers for variables "length" and "address"
http://code.google.com/p/optiboot/issues/detail?id=33
Fix high-value watchdog timeouts on ATmega8
http://code.google.com/p/optiboot/issues/detail?id=38
Change "start app on bad commands" code to start the app via the
watchdog timer, so that the app is always started with the chip
in fully reset state.
http://code.google.com/p/optiboot/issues/detail?id=37
Diffstat (limited to 'bootloaders/optiboot/optiboot.c')
-rw-r--r-- | bootloaders/optiboot/optiboot.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/bootloaders/optiboot/optiboot.c b/bootloaders/optiboot/optiboot.c index ece8b43..8940359 100644 --- a/bootloaders/optiboot/optiboot.c +++ b/bootloaders/optiboot/optiboot.c @@ -198,8 +198,8 @@ asm(" .section .version\n" #define WATCHDOG_1S (_BV(WDP2) | _BV(WDP1) | _BV(WDE)) #define WATCHDOG_2S (_BV(WDP2) | _BV(WDP1) | _BV(WDP0) | _BV(WDE)) #ifndef __AVR_ATmega8__ -#define WATCHDOG_4S (_BV(WDE3) | _BV(WDE)) -#define WATCHDOG_8S (_BV(WDE3) | _BV(WDE0) | _BV(WDE)) +#define WATCHDOG_4S (_BV(WDP3) | _BV(WDE)) +#define WATCHDOG_8S (_BV(WDP3) | _BV(WDP0) | _BV(WDE)) #endif /* Function Prototypes */ @@ -244,8 +244,6 @@ void appStart() __attribute__ ((naked)); /* These definitions are NOT zero initialised, but that doesn't matter */ /* This allows us to drop the zero init code, saving us memory */ #define buff ((uint8_t*)(RAMSTART)) -#define address (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2)) -#define length (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+2)) #ifdef VIRTUAL_BOOT_PARTITION #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4)) #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6)) @@ -255,6 +253,13 @@ void appStart() __attribute__ ((naked)); int main(void) { uint8_t ch; + /* + * Making these local and in registers prevents the need for initializing + * them, and also saves space because code no longer stores to memory. + */ + register uint16_t address; + register uint8_t length; + // After the zero init loop, this is the first code to run. // // This code makes the following assumptions: @@ -350,7 +355,9 @@ int main(void) { uint8_t *bufPtr; uint16_t addrPtr; - getLen(); + getch(); /* getlen() */ + length = getch(); + getch(); // If we are in RWW section, immediately start page erase if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address); @@ -415,7 +422,10 @@ int main(void) { /* Read memory block mode, length is big endian. */ else if(ch == STK_READ_PAGE) { // READ PAGE - we only read flash - getLen(); + getch(); /* getlen() */ + length = getch(); + getch(); + verifySpace(); #ifdef VIRTUAL_BOOT_PARTITION do { @@ -575,7 +585,11 @@ void getNch(uint8_t count) { } void verifySpace() { - if (getch() != CRC_EOP) appStart(); + if (getch() != CRC_EOP) { + watchdogConfig(WATCHDOG_16MS); // shorten WD timeout + while (1) // and busy-loop so that WD causes + ; // a reset and app start. + } putch(STK_INSYNC); } @@ -595,12 +609,6 @@ void flash_led(uint8_t count) { } #endif -uint8_t getLen() { - getch(); - length = getch(); - return getch(); -} - // Watchdog functions. These are only safe with interrupts turned off. void watchdogReset() { __asm__ __volatile__ ( |