Optional complemented writes/reads and faster word reads

This commit is contained in:
dak664 2009-07-15 22:10:08 +00:00
parent 450aa16a5b
commit af981496b1
2 changed files with 47 additions and 9 deletions

View file

@ -333,21 +333,38 @@ avr_flash_read(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE siz
#endif #endif
#ifndef FLASH_WORD_READS #ifndef FLASH_WORD_READS
for (;size>0;size--) { for (;size>0;size--) {
#if FLASH_COMPLEMENT_DATA
*buf++=~(uint8_t)pgm_read_byte_far(addr32++);
#else
*buf++=(uint8_t)pgm_read_byte_far(addr32++); *buf++=(uint8_t)pgm_read_byte_far(addr32++);
#endif /*FLASH_COMPLEMENT_DATA*/
} }
#else #else
/* 130 bytes more PROGMEM, but faster */ /* 130 bytes more PROGMEM, but faster */
if (size&0x01) { //handle first odd byte if (size&0x01) { //handle first odd byte
#if FLASH_COMPLEMENT_DATA
*buf++=~(uint8_t)pgm_read_byte_far(addr32++);
#else
*buf++=(uint8_t)pgm_read_byte_far(addr32++); *buf++=(uint8_t)pgm_read_byte_far(addr32++);
#endif /*FLASH_COMPLEMENT_DATA*/
size--; size--;
} }
for (;size>1;size-=2) {//read words from flash for (;size>1;size-=2) {//read words from flash
#if FLASH_COMPLEMENT_DATA
*(uint16_t *)buf=~(uint16_t)pgm_read_word_far(addr32);
#else
*(uint16_t *)buf=(uint16_t)pgm_read_word_far(addr32); *(uint16_t *)buf=(uint16_t)pgm_read_word_far(addr32);
#endif /*FLASH_COMPLEMENT_DATA*/
buf+=2; buf+=2;
addr32+=2; addr32+=2;
} }
if (size) { //handle last odd byte if (size) { //handle last odd byte
#if FLASH_COMPLEMENT_DATA
*buf++=~(uint8_t)pgm_read_byte_far(addr32);
#else
*buf++=(uint8_t)pgm_read_byte_far(addr32); *buf++=(uint8_t)pgm_read_byte_far(addr32);
#endif /*FLASH_COMPLEMENT_DATA*/
} }
#endif /* FLASH_WORD_READS */ #endif /* FLASH_WORD_READS */
@ -398,7 +415,7 @@ void
avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size) avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE size)
{ {
uint32_t addr32; uint32_t addr32;
uint16_t i,w,startpage; uint16_t w,startpage;
uint8_t bb,ba,sreg; uint8_t bb,ba,sreg;
/* Disable interrupts, make sure no eeprom write in progress */ /* Disable interrupts, make sure no eeprom write in progress */
@ -438,6 +455,9 @@ avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE si
while (size>1) { while (size>1) {
if (bb) { //handle odd byte boundary if (bb) { //handle odd byte boundary
w=pgm_read_word_far(addr32); w=pgm_read_word_far(addr32);
#if FLASH_COMPLEMENT_DATA
w = ~w;
#endif /*FLASH_COMPLEMENT_DATA*/
w &= 0xff; w &= 0xff;
bb=0; bb=0;
size++; size++;
@ -445,6 +465,9 @@ avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE si
w = *buf++; w = *buf++;
} }
w += (*buf++) << 8; w += (*buf++) << 8;
#if FLASH_COMPLEMENT_DATA
w = ~w;
#endif /*FLASH_COMPLEMENT_DATA*/
boot_page_fill(addr32, w); boot_page_fill(addr32, w);
size-=2; size-=2;
/* Below ought to work but writing to 0xnnnnnnfe modifies the NEXT flash page /* Below ought to work but writing to 0xnnnnnnfe modifies the NEXT flash page
@ -478,7 +501,11 @@ avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE si
w=pgm_read_word_far(addr32); w=pgm_read_word_far(addr32);
if (size) { //handle odd byte boundary if (size) { //handle odd byte boundary
w &= 0xff00; w &= 0xff00;
#if FLASH_COMPLEMENT_DATA
w +=~(*buf);
#else
w +=*buf; w +=*buf;
#endif /*FLASH_COMPLEMENT_DATA*/
size=0; size=0;
} }
boot_page_fill(addr32,w); boot_page_fill(addr32,w);
@ -487,18 +514,28 @@ avr_flash_write(CFS_CONF_OFFSET_TYPE addr, uint8_t *buf, CFS_CONF_OFFSET_TYPE si
} }
/* If buf is null, erase the page to zero */ /* If buf is null, erase the page to zero */
} else { } else {
for (i=0;i<SPM_PAGESIZE;i++) { #if FLASH_COMPLEMENT_DATA
addr32+=2*SPM_PAGESIZE;
#else
for (w=0;w<SPM_PAGESIZE;w++) {
boot_page_fill(addr32, 0); boot_page_fill(addr32, 0);
addr32+=2; addr32+=2;
} }
#endif /*FLASH_COMPLEMENT_DATA*/
} }
/* Write the last (or only) page */ /* Write the last (or only) page */
addr32-=0x42; //get an address within the page addr32-=0x42; //get an address within the page
boot_page_erase(addr32); boot_page_erase(addr32);
boot_spm_busy_wait(); boot_spm_busy_wait();
#if FLASH_COMPLEMENT_DATA
if (buf) { //don't write zeroes to erased page
boot_page_write(addr32); boot_page_write(addr32);
boot_spm_busy_wait(); boot_spm_busy_wait();
}
#else
boot_page_write(addr32);
boot_spm_busy_wait();
#endif /*FLASH_COMPLEMENT_DATA*/
/* Reenable RWW-section again. We need this if we want to jump back /* Reenable RWW-section again. We need this if we want to jump back
* to the application after bootloading. */ * to the application after bootloading. */
boot_rww_enable(); boot_rww_enable();

View file

@ -86,11 +86,12 @@ void avr_eeprom_erase(uint16_t sector);
#define COFFEE_PAGE_START 65536UL/COFFEE_PAGE_SIZE //Starting page at 64KB for webserver #define COFFEE_PAGE_START 65536UL/COFFEE_PAGE_SIZE //Starting page at 64KB for webserver
#define COFFEE_PAGES 512UL-COFFEE_PAGE_START-32UL //Number of pages to use (reserve NWWR pages) #define COFFEE_PAGES 512UL-COFFEE_PAGE_START-32UL //Number of pages to use (reserve NWWR pages)
#define COFFEE_START (COFFEE_PAGE_START)*COFFEE_PAGE_SIZE //Starting address of the file system, on a page boundary #define COFFEE_START (COFFEE_PAGE_START)*COFFEE_PAGE_SIZE //Starting address of the file system, on a page boundary
#define FLASH_WORD_READS 1 //Faster but takes 130 bytes more PROGMEM #define FLASH_WORD_READS 1 //1=Faster, but 130 bytes more PROGMEM
#define FLASH_COMPLEMENT_DATA 0 //1=Slower reads, but no page writes after erase and 18 bytes less PROGMEM
#define COFFEE_SIZE (COFFEE_PAGES)*COFFEE_PAGE_SIZE //Bytes in filesystem #define COFFEE_SIZE (COFFEE_PAGES)*COFFEE_PAGE_SIZE //Bytes in filesystem
#define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*1) //Each page a sector? #define COFFEE_SECTOR_SIZE (COFFEE_PAGE_SIZE*1) //Each page a sector
#define COFFEE_NAME_LENGTH 16 #define COFFEE_NAME_LENGTH 16 //processes.shtml is longest file name
#define COFFEE_MAX_OPEN_FILES 4 #define COFFEE_MAX_OPEN_FILES 4
#define COFFEE_FD_SET_SIZE 8 //Size of file descriptor #define COFFEE_FD_SET_SIZE 8 //Size of file descriptor
#define COFFEE_LOG_TABLE_LIMIT 16 #define COFFEE_LOG_TABLE_LIMIT 16