// fills the rest of this page with vectors - interrupt vector or tinyvector tables where needed static void fillFlashWithVectors(void) { int16_t i; // fill all or remainder of page with 0xFFFF (as if unprogrammed) for (i = currentAddress % SPM_PAGESIZE; i < SPM_PAGESIZE; i += 2) { writeWordToPageBuffer(0xFFFF); // is where vector tables are sorted out } writeFlashPage(); }
static void fillFlashWithVectors(void) { int16_t i; // fill all or remainder of page starting at CURRENT_ADDRESS with 0xFFs, unless we're // at a special address that needs a vector replaced for (i = CURRENT_ADDRESS % SPM_PAGESIZE; i < SPM_PAGESIZE; i += 2) { writeWordToPageBuffer(0xFFFF); } writeFlashPage(); }
// fills the rest of this page with vectors - interrupt vector or tinyvector tables where needed static void fillFlashWithVectors(void) { //int16_t i; // // fill all or remainder of page with 0xFFFF (as if unprogrammed) //for (i = currentAddress % SPM_PAGESIZE; i < SPM_PAGESIZE; i += 2) { // writeWordToPageBuffer(0xFFFF); // is where vector tables are sorted out //} // TODO: Or more simply: do { writeWordToPageBuffer(0xFFFF); } while (currentAddress % SPM_PAGESIZE); writeFlashPage(); }
uchar usbFunctionWrite(uchar *data, uchar len) { uchar isLast; DBG1(0x31, (void *)¤tAddress.l, 4); if(len > bytesRemaining) len = bytesRemaining; bytesRemaining -= len; isLast = bytesRemaining == 0; if(currentRequest >= USBASP_FUNC_READEEPROM){ uchar i; for(i = 0; i < len; i++){ eeprom_write_byte((void *)(currentAddress.w[0]++), *data++); } }else { uchar i; for(i = 0; i < len;){ #ifdef TINY85MODE #if 1 if(CURRENT_ADDRESS == RESET_VECTOR_OFFSET * 2) { vectorTemp[0] = *(short *)data; } if(CURRENT_ADDRESS == USBPLUS_VECTOR_OFFSET * 2) { vectorTemp[1] = *(short *)data; } #else if(CURRENT_ADDRESS == RESET_VECTOR_OFFSET * 2 || CURRENT_ADDRESS == USBPLUS_VECTOR_OFFSET * 2) { vectorTemp[CURRENT_ADDRESS ? 1:0] = *(short *)data; } #endif #else # if !HAVE_CHIP_ERASE if((currentAddress.w[0] & (SPM_PAGESIZE - 1)) == 0){ /* if page start: erase */ DBG1(0x33, 0, 0); # ifndef NO_FLASH_WRITE cli(); boot_page_erase(CURRENT_ADDRESS); /* erase page */ sei(); boot_spm_busy_wait(); /* wait until page is erased */ # endif # endif #endif i += 2; DBG1(0x32, 0, 0); #ifdef TINY85MODE if(CURRENT_ADDRESS >= BOOTLOADER_ADDRESS - 6) { // stop writing data to flash if the application is too big, and clear any leftover data in the page buffer __boot_page_fill_clear(); return isLast; } writeWordToPageBuffer(*(short *)data); #else cli(); boot_page_fill(CURRENT_ADDRESS, *(short *)data); sei(); CURRENT_ADDRESS += 2; #endif data += 2; /* write page when we cross page boundary or we have the last partial page */ if((currentAddress.w[0] & (SPM_PAGESIZE - 1)) == 0 || (isLast && i >= len && isLastPage)){ DBG1(0x34, 0, 0); #ifdef TINY85MODE flashPageLoaded = 1; #else # ifndef NO_FLASH_WRITE cli(); boot_page_write(CURRENT_ADDRESS - 2); sei(); boot_spm_busy_wait(); cli(); boot_rww_enable(); sei(); # endif #endif } } DBG1(0x35, (void *)¤tAddress.l, 4); } return isLast; } uchar usbFunctionRead(uchar *data, uchar len) { uchar i; if(len > bytesRemaining) len = bytesRemaining; bytesRemaining -= len; for(i = 0; i < len; i++){ if(currentRequest >= USBASP_FUNC_READEEPROM){ *data = eeprom_read_byte((void *)currentAddress.w[0]); }else{ *data = pgm_read_byte((void *)CURRENT_ADDRESS); // read back original vectors #ifdef TINY85MODE #if 1 if(CURRENT_ADDRESS == RESET_VECTOR_OFFSET * 2) *data = vectorTemp[0]; if(CURRENT_ADDRESS == (RESET_VECTOR_OFFSET * 2) + 1) *data = vectorTemp[0]/256; if(CURRENT_ADDRESS == (USBPLUS_VECTOR_OFFSET * 2)) *data = vectorTemp[1]; if(CURRENT_ADDRESS == (USBPLUS_VECTOR_OFFSET * 2) + 1) *data = vectorTemp[1]/256; #else if(CURRENT_ADDRESS == RESET_VECTOR_OFFSET * 2 || CURRENT_ADDRESS == USBPLUS_VECTOR_OFFSET * 2) { *(short *)data = vectorTemp[CURRENT_ADDRESS ? 1:0]; data++; CURRENT_ADDRESS++; } #endif #endif } data++; CURRENT_ADDRESS++; } return len; }