aboutsummaryrefslogtreecommitdiff
path: root/bootloaders/optiboot/optiboot.c
diff options
context:
space:
mode:
authorWestfW <westfw@gmail.com>2011-06-10 23:02:25 -0700
committerDavid A. Mellis <d.mellis@arduino.cc>2011-10-10 12:11:15 -0400
commitc7af5068526a3474592f3407d9f34e9340ed86a9 (patch)
treeb844bc1e2ce990b2c37f4f54ab04f6cabf472f5c /bootloaders/optiboot/optiboot.c
parentb4952051f6eb9a47c9bd08918a093cd070637704 (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 (cherry picked from commit 6f7687b0f925cb07447cbbcc692766c51c02f700)
Diffstat (limited to 'bootloaders/optiboot/optiboot.c')
-rw-r--r--bootloaders/optiboot/optiboot.c34
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__ (