spi_flash(new driver): Add vTaskDelay while a long erasing

pull/5191/head
KonstantinKondrashov 2020-04-02 17:29:21 +08:00
rodzic 3cb655eaab
commit ae89f98d59
1 zmienionych plików z 16 dodań i 1 usunięć

Wyświetl plik

@ -23,6 +23,8 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_heap_caps.h" #include "esp_heap_caps.h"
#include "esp_flash_internal.h" #include "esp_flash_internal.h"
#include <freertos/task.h>
#include "esp_timer.h"
static const char TAG[] = "spi_flash"; static const char TAG[] = "spi_flash";
@ -337,8 +339,13 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui
err = spiflash_end(chip, err); err = spiflash_end(chip, err);
} }
#ifdef CONFIG_SPI_FLASH_YIELD_DURING_ERASE
int64_t no_yield_time_us = 0;
#endif
while (err == ESP_OK && len >= sector_size) { while (err == ESP_OK && len >= sector_size) {
#ifdef CONFIG_SPI_FLASH_YIELD_DURING_ERASE
int64_t start_time_us = esp_timer_get_time();
#endif
err = spiflash_start(chip); err = spiflash_start(chip);
if (err != ESP_OK) { if (err != ESP_OK) {
return err; return err;
@ -358,6 +365,14 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui
} }
err = spiflash_end(chip, err); err = spiflash_end(chip, err);
#ifdef CONFIG_SPI_FLASH_YIELD_DURING_ERASE
no_yield_time_us += (esp_timer_get_time() - start_time_us);
if (no_yield_time_us / 1000 >= CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS) {
no_yield_time_us = 0;
vTaskDelay(CONFIG_SPI_FLASH_ERASE_YIELD_TICKS);
}
#endif
} }
return err; return err;
} }