From b7ec38e61a4f92ade80e38744d00311538671179 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 11 Oct 2008 19:27:10 +0000 Subject: * Updating version number to 0013. * Updating ATmega168 bootloader to work with standard distributions of avrdude (responding to signature requests made with the universal SPI command) and correctly store EEPROM data. Thanks to ladyada. * Changing compilation process to generate .eep file and allow for use of EEMEM directive (although not yet uploading EEPROM data). --- bootloaders/atmega168/ATmegaBOOT_168.c | 105 +++++++++++++++------------------ 1 file changed, 49 insertions(+), 56 deletions(-) (limited to 'bootloaders/atmega168/ATmegaBOOT_168.c') diff --git a/bootloaders/atmega168/ATmegaBOOT_168.c b/bootloaders/atmega168/ATmegaBOOT_168.c index f1c1cdf..6a3c634 100755 --- a/bootloaders/atmega168/ATmegaBOOT_168.c +++ b/bootloaders/atmega168/ATmegaBOOT_168.c @@ -65,7 +65,7 @@ #include #include #include - +#include /* the current avr-libc eeprom functions do not support the ATmega168 */ /* own eeprom write/read functions are used instead */ @@ -448,8 +448,9 @@ int main(void) } - /* Enter programming mode */ - else if(ch=='P') { + /* P: Enter programming mode */ + /* R: Erase device, don't care as we will erase one page at a time anyway. */ + else if(ch=='P' || ch=='R') { nothing_response(); } @@ -465,12 +466,6 @@ int main(void) } - /* Erase device, don't care as we will erase one page at a time anyway. */ - else if(ch=='R') { - nothing_response(); - } - - /* Set address, little endian. EEPROM in bytes, FLASH in words */ /* Perhaps extra address bytes may be added in future to support > 128kB FLASH. */ /* This might explain why little endian was used here, big endian used everywhere else. */ @@ -483,8 +478,21 @@ int main(void) /* Universal SPI programming command, disabled. Would be used for fuses and lock bits. */ else if(ch=='V') { - getNch(4); - byte_response(0x00); + if (getch() == 0x30) { + getch(); + ch = getch(); + getch(); + if (ch == 0) { + byte_response(SIG1); + } else if (ch == 1) { + byte_response(SIG2); + } else { + byte_response(SIG3); + } + } else { + getNch(3); + byte_response(0x00); + } } @@ -499,6 +507,7 @@ int main(void) } if (getch() == ' ') { if (flags.eeprom) { //Write to EEPROM one byte at a time + address.word <<= 1; for(w=0;w0x7FFF) flags.rampz = 1; // No go with m256, FIXME else flags.rampz = 0; #endif + address.word = address.word << 1; // address * 2 -> byte location if (getch() == 'E') flags.eeprom = 1; - else { - flags.eeprom = 0; - address.word = address.word << 1; // address * 2 -> byte location - } + else flags.eeprom = 0; if (getch() == ' ') { // Command terminator putch(0x14); for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay @@ -817,42 +824,42 @@ int main(void) } -char gethex(void) { - char ah,al; - - ah = getch(); putch(ah); - al = getch(); putch(al); - if(ah >= 'a') { - ah = ah - 'a' + 0x0a; - } else if(ah >= '0') { - ah -= '0'; +char gethexnib(void) { + char a; + a = getch(); putch(a); + if(a >= 'a') { + return (a - 'a' + 0x0a); + } else if(a >= '0') { + return(a - '0'); } - if(al >= 'a') { - al = al - 'a' + 0x0a; - } else if(al >= '0') { - al -= '0'; - } - return (ah << 4) + al; + return a; +} + + +char gethex(void) { + return (gethexnib() << 4) + gethexnib(); } void puthex(char ch) { - char ah,al; + char ah; - ah = (ch & 0xf0) >> 4; + ah = ch >> 4; if(ah >= 0x0a) { ah = ah - 0x0a + 'a'; } else { ah += '0'; } - al = (ch & 0x0f); - if(al >= 0x0a) { - al = al - 0x0a + 'a'; + + ch &= 0x0f; + if(ch >= 0x0a) { + ch = ch - 0x0a + 'a'; } else { - al += '0'; + ch += '0'; } + putch(ah); - putch(al); + putch(ch); } @@ -917,8 +924,7 @@ char getch(void) void getNch(uint8_t count) { - uint8_t i; - for(i=0;i