void erase_storage(teDATASTORAGE stype) { uint16_t i; uint32_t address, working_address; uint8_t blocks = 0; uint16_t sectors = 0, remainder = 0; switch(stype) { case STORAGE_MAC: #ifndef __USE_EXT_EEPROM__ erase_flash_sector(DEVICE_MAC_ADDR); // internal data flash for configuration data (DAT0/1) #else erase_eeprom_block(convert_eeprom_addr(DEVICE_MAC_ADDR)); // external eeprom for configuration data #ifdef _EEPROM_DEBUG_ dump_eeprom_block(convert_eeprom_addr(DEVICE_MAC_ADDR)); #endif #endif break; case STORAGE_CONFIG: #ifndef __USE_EXT_EEPROM__ erase_flash_sector(DEVICE_CONFIG_ADDR); // internal data flash for configuration data (DAT0/1) #else erase_eeprom_block(convert_eeprom_addr(DEVICE_CONFIG_ADDR)); // external eeprom for configuration data #ifdef _EEPROM_DEBUG_ dump_eeprom_block(convert_eeprom_addr(DEVICE_CONFIG_ADDR)); #endif #endif break; case STORAGE_APP_MAIN: address = DEVICE_APP_MAIN_ADDR; break; case STORAGE_APP_BACKUP: address = DEVICE_APP_BACKUP_ADDR; break; default: break; } if((stype == STORAGE_APP_MAIN) || (stype == STORAGE_APP_BACKUP)) { blocks = DEVICE_APP_SIZE / BLOCK_SIZE; if(DEVICE_APP_SIZE > (blocks * BLOCK_SIZE)) { remainder = DEVICE_APP_SIZE - (blocks * BLOCK_SIZE); sectors = (remainder / SECT_SIZE); if(remainder > (sectors * SECT_SIZE)) sectors++; } working_address = address; #ifdef _STORAGE_DEBUG_ printf(" > STORAGE:ERASE_START:ADDR - 0x%x\r\n", working_address); #endif // Flash block erase operation for(i = 0; i < blocks; i++) { erase_flash_block(working_address + (BLOCK_SIZE * i)); #ifdef _STORAGE_DEBUG_ printf(" > STORAGE:BLOCK_ERASE:ADDR - 0x%x\r\n", working_address + (BLOCK_SIZE * i)); #endif } working_address += (blocks * BLOCK_SIZE); // Flash sector erase operation if(sectors > 0) { for(i = 0; i < sectors; i++) { erase_flash_sector(working_address + (SECT_SIZE * i)); #ifdef _STORAGE_DEBUG_ printf(" > STORAGE:SECTOR_ERASE:ADDR - 0x%x\r\n", working_address + (SECT_SIZE * i)); #endif } working_address += (sectors * SECT_SIZE); } #ifdef _STORAGE_DEBUG_ printf(" > STORAGE:ERASE_END:ADDR_RANGE - [0x%x ~ 0x%x]\r\n", address, working_address-1); #endif } }
void fs_erase(void) { erase_flash_sector((unsigned int)STORAGE_ADDRESS); flush_cpu_dcache(); }