summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcpldcpu <cpldcpu@gmail.com>2013-12-01 08:28:35 +0100
committercpldcpu <cpldcpu@gmail.com>2013-12-01 08:28:35 +0100
commitc2fddbf652e3b6b7c8787683a85990cc6ab099cd (patch)
tree0125bc4eb5fa905222b7572a0a0094c50fcc81fd
parent4d24478ab799cbb760b6b78cc04057dda8571e83 (diff)
downloadmicronucleus-c2fddbf652e3b6b7c8787683a85990cc6ab099cd.tar.gz
micronucleus-c2fddbf652e3b6b7c8787683a85990cc6ab099cd.tar.bz2
micronucleus-c2fddbf652e3b6b7c8787683a85990cc6ab099cd.zip
removed redundant code - untested
-rw-r--r--firmware/main.c54
1 files changed, 20 insertions, 34 deletions
diff --git a/firmware/main.c b/firmware/main.c
index f03484d..8765c0c 100644
--- a/firmware/main.c
+++ b/firmware/main.c
@@ -58,11 +58,6 @@ static void leaveBootloader() __attribute__((__noreturn__));
#define addr_t uint
-// typedef union longConverter{
-// addr_t l;
-// uint w[sizeof(addr_t)/2];
-// uchar b[sizeof(addr_t)];
-// } longConverter_t;
//////// Stuff Bluebie Added
// postscript are the few bytes at the end of programmable memory which store tinyVectors
@@ -168,10 +163,23 @@ static void writeWordToPageBuffer(uint16_t data) {
uint8_t previous_sreg;
// first two interrupt vectors get replaced with a jump to the bootloader's vector table
+ /*
if (currentAddress == (RESET_VECTOR_OFFSET * 2) || currentAddress == (USBPLUS_VECTOR_OFFSET * 2)) {
data = 0xC000 + (BOOTLOADER_ADDRESS/2) - 1;
}
-
+ */
+
+ // remember vectors or the tinyvector table
+ if (currentAddress == RESET_VECTOR_OFFSET * 2) {
+ vectorTemp[0] = data;
+ data = 0xC000 + (BOOTLOADER_ADDRESS/2) - 1;
+ }
+
+ if (currentAddress == USBPLUS_VECTOR_OFFSET * 2) {
+ vectorTemp[1] = data;
+ data = 0xC000 + (BOOTLOADER_ADDRESS/2) - 1;
+ }
+
// at end of page just before bootloader, write in tinyVector table
// see http://embedded-creations.com/projects/attiny85-usb-bootloader-overview/avr-jtag-programmer/
// for info on how the tiny vector table works
@@ -217,7 +225,6 @@ static void fillFlashWithVectors(void) {
// TODO: Or more simply:
-
#if SPM_PAGESIZE<256
do {
writeWordToPageBuffer(0xFFFF);
@@ -228,7 +235,6 @@ static void fillFlashWithVectors(void) {
} while (currentAddress % SPM_PAGESIZE);
#endif
-
writeFlashPage();
}
@@ -273,16 +279,7 @@ static uchar usbFunctionWrite(uchar *data, uchar length) {
//if (length > writeLength) length = writeLength; // test for missing final page bug
//writeLength -= length;
- do {
- // remember vectors or the tinyvector table
- if (currentAddress == RESET_VECTOR_OFFSET * 2) {
- vectorTemp[0] = *(short *)data;
- }
-
- if (currentAddress == USBPLUS_VECTOR_OFFSET * 2) {
- vectorTemp[1] = *(short *)data;
- }
-
+ do {
// make sure we don't write over the bootloader!
if (currentAddress >= BOOTLOADER_ADDRESS) {
//__boot_page_fill_clear();
@@ -345,24 +342,13 @@ static inline void tiny85FlashInit(void) {
currentAddress = 0;
}
+
+// Write page buffer to flash. May only be called for full pages.
+
static inline void tiny85FlashWrites(void) {
- _delay_us(2000); // TODO: why is this here? - it just adds pointless two level deep loops seems like?
- // write page to flash, interrupts will be disabled for > 4.5ms including erase
-
- // TODO: Do we need this? Wouldn't the programmer always send full sized pages?
+ _delay_us(2000); // Wait for USB traffic to finish before halting CPU with write-
-#if SPM_PAGESIZE<256
- // Hack to reduce code size
- if ((uchar)currentAddress % SPM_PAGESIZE)
-#else
- if (currentAddress % SPM_PAGESIZE)
-#endif
- {
- // when we aren't perfectly aligned to a flash page boundary
- fillFlashWithVectors(); // fill up the rest of the page with 0xFFFF (unprogrammed) bits
- } else {
- writeFlashPage(); // otherwise just write it
- }
+ writeFlashPage();
}
// reset system to a normal state and launch user program