1 /*
2 * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <stdarg.h>
8 #include "sdkconfig.h"
9 #include "esp_flash.h"
10 #include "esp_attr.h"
11 #include "esp_rom_sys.h"
12 #include "rom/cache.h"
13 #include "hal/cache_hal.h"
14 #include "hal/cache_ll.h"
15 #include "soc/soc_caps.h"
16
start(void * arg)17 static IRAM_ATTR esp_err_t start(void *arg)
18 {
19 #if CONFIG_IDF_TARGET_ESP32
20 Cache_Read_Disable(0);
21 #if CONFIG_SMP
22 Cache_Read_Disable(1);
23 #endif
24 #else
25 cache_hal_suspend(CACHE_TYPE_ALL);
26 #endif
27
28 return ESP_OK;
29 }
30
end(void * arg)31 static IRAM_ATTR esp_err_t end(void *arg)
32 {
33 #if CONFIG_IDF_TARGET_ESP32
34 Cache_Read_Enable(0);
35 #if CONFIG_SMP
36 Cache_Read_Enable(1);
37 #endif
38 #else
39 cache_hal_resume(CACHE_TYPE_ALL);
40 #endif
41
42 return ESP_OK;
43 }
44
delay_us(void * arg,uint32_t us)45 static IRAM_ATTR esp_err_t delay_us(void *arg, uint32_t us)
46 {
47 esp_rom_delay_us(us);
48 return ESP_OK;
49 }
50
51 // Currently when the os is not up yet, the caller is supposed to call esp_flash APIs with proper
52 // buffers.
get_temp_buffer_not_supported(void * arg,size_t reqest_size,size_t * out_size)53 IRAM_ATTR void* get_temp_buffer_not_supported(void* arg, size_t reqest_size, size_t* out_size)
54 {
55 return NULL;
56 }
57
58 const DRAM_ATTR esp_flash_os_functions_t esp_flash_noos_functions = {
59 .start = start,
60 .end = end,
61 .delay_us = delay_us,
62 .region_protected = NULL,
63 /* the caller is supposed to call esp_flash_read/esp_flash_write APIs with buffers in DRAM */
64 .get_temp_buffer = NULL,
65 .release_temp_buffer = NULL,
66 .yield = NULL,
67 };
68
esp_flash_app_disable_os_functions(esp_flash_t * chip)69 esp_err_t IRAM_ATTR esp_flash_app_disable_os_functions(esp_flash_t* chip)
70 {
71 chip->os_func = &esp_flash_noos_functions;
72
73 return ESP_OK;
74 }
75