spi_flash: change argument types

spi_flash_read and spi_flash_write currently have a limitation that source and destination must be word-aligned.
This can be fixed by adding code paths for various unaligned scenarios, but function signatures also need to be adjusted.
As a first step (since we are pre-1.0 and can still change function signatures) alignment checks are added, and pointer types are relaxed to uint8_t.
Later we will add handling of unaligned operations.
This change also introduces spi_flash_erase_range and spi_flash_get_chip_size functions.

We probably need something like spi_flash_chip_size_detect which will detect actual chip size.
This is to allow single application binary to be used on a variety of boards and modules.
This commit is contained in:
Ivan Grokhotkov
2016-10-21 17:28:50 +08:00
parent 079d9ea018
commit 2c5340d47e
6 changed files with 146 additions and 48 deletions
@@ -22,7 +22,7 @@ void spi_flash_emulator_set(SpiFlashEmulator* e)
s_emulator = e;
}
esp_err_t spi_flash_erase_sector(uint16_t sec)
esp_err_t spi_flash_erase_sector(size_t sec)
{
if (!s_emulator) {
return ESP_ERR_FLASH_OP_TIMEOUT;
@@ -35,26 +35,26 @@ esp_err_t spi_flash_erase_sector(uint16_t sec)
return ESP_OK;
}
esp_err_t spi_flash_write(uint32_t des_addr, const uint32_t *src_addr, uint32_t size)
esp_err_t spi_flash_write(size_t des_addr, const uint8_t *src_addr, size_t size)
{
if (!s_emulator) {
return ESP_ERR_FLASH_OP_TIMEOUT;
}
if (!s_emulator->write(des_addr, src_addr, size)) {
if (!s_emulator->write(des_addr, reinterpret_cast<const uint32_t*>(src_addr), size)) {
return ESP_ERR_FLASH_OP_FAIL;
}
return ESP_OK;
}
esp_err_t spi_flash_read(uint32_t src_addr, uint32_t *des_addr, uint32_t size)
esp_err_t spi_flash_read(size_t src_addr, uint8_t *des_addr, size_t size)
{
if (!s_emulator) {
return ESP_ERR_FLASH_OP_TIMEOUT;
}
if (!s_emulator->read(des_addr, src_addr, size)) {
if (!s_emulator->read(reinterpret_cast<uint32_t*>(des_addr), src_addr, size)) {
return ESP_ERR_FLASH_OP_FAIL;
}