1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

REVONANO - emulate bigger sector size for erase operations

This commit is contained in:
Alessio Morale 2015-04-10 15:12:44 +02:00
parent 5ca6e43070
commit 855361488a

View File

@ -32,6 +32,10 @@
#ifdef PIOS_INCLUDE_FLASH_EEPROM
#ifndef PIOS_EEPROM_EMULATED_SECTOR_SIZE
#define PIOS_EEPROM_EMULATED_SECTOR_SIZE 256
#endif
#include <pios_flash_eeprom.h>
#include <pios_math.h>
enum pios_eeprom_dev_magic {
@ -393,8 +397,24 @@ static int32_t PIOS_Flash_EEPROM_EraseSector(uintptr_t flash_id, uint32_t addr)
const uint8_t buf[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
return PIOS_Flash_EEPROM_Write(flash_dev, addr, buf, sizeof(buf));
uint32_t current = addr;
while (current - addr < PIOS_EEPROM_EMULATED_SECTOR_SIZE) {
uint32_t erase_size = (MIN(sizeof(buf), flash_dev->cfg->page_len));
erase_size = MIN(erase_size, (PIOS_EEPROM_EMULATED_SECTOR_SIZE - current + addr));
int32_t res = PIOS_Flash_EEPROM_Write(flash_dev, current, buf, erase_size);
if (!res) {
return res;
}
current += erase_size;
}
return 0;
}
/**