1 /*
2  * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdint.h>
8 #include <stdbool.h>
9 #include "esp_attr.h"
10 #include "sdkconfig.h"
11 #include "esp_rom_spiflash.h"
12 
13 #if CONFIG_SPI_FLASH_BROWNOUT_RESET
14 
15 static bool flash_brownout_needs_reset = false;
16 static bool flash_erasing = false;
17 
18 // This function could be called in startup
spi_flash_needs_reset_check(void)19 void spi_flash_needs_reset_check(void)
20 {
21     // Currently only XMC is suggested to reset when brownout
22 #if CONFIG_SPI_FLASH_BROWNOUT_RESET_XMC
23     if ((g_rom_flashchip.device_id >> 16) == 0x20) {
24         flash_brownout_needs_reset = true;
25     }
26 #endif
27 }
28 
spi_flash_set_erasing_flag(bool status)29 void spi_flash_set_erasing_flag(bool status)
30 {
31     flash_erasing = status;
32 }
33 
spi_flash_brownout_need_reset(void)34 bool spi_flash_brownout_need_reset(void)
35 {
36     return (flash_brownout_needs_reset && flash_erasing);
37 }
38 
39 #endif //CONFIG_SPI_FLASH_BROWNOUT_RESET
40