spi_flash_os_func_noos.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <stdarg.h>
  15. #include "sdkconfig.h"
  16. #include "esp_flash.h"
  17. #include "esp_attr.h"
  18. #if CONFIG_IDF_TARGET_ESP32
  19. #include "esp32/rom/ets_sys.h"
  20. #include "esp32/rom/cache.h"
  21. #elif CONFIG_IDF_TARGET_ESP32S2
  22. #include "esp32s2/rom/ets_sys.h"
  23. #include "esp32s2/rom/cache.h"
  24. #endif
  25. #include "esp_attr.h"
  26. #if CONFIG_IDF_TARGET_ESP32S2
  27. typedef struct {
  28. uint32_t icache_autoload;
  29. uint32_t dcache_autoload;
  30. } spi_noos_arg_t;
  31. static DRAM_ATTR spi_noos_arg_t spi_arg = { 0 };
  32. #endif
  33. static IRAM_ATTR esp_err_t start(void *arg)
  34. {
  35. #if CONFIG_IDF_TARGET_ESP32
  36. Cache_Read_Disable(0);
  37. Cache_Read_Disable(1);
  38. #elif CONFIG_IDF_TARGET_ESP32S2
  39. spi_noos_arg_t *spi_arg = arg;
  40. spi_arg->icache_autoload = Cache_Suspend_ICache();
  41. spi_arg->dcache_autoload = Cache_Suspend_DCache();
  42. #endif
  43. return ESP_OK;
  44. }
  45. static IRAM_ATTR esp_err_t end(void *arg)
  46. {
  47. #if CONFIG_IDF_TARGET_ESP32
  48. Cache_Flush(0);
  49. Cache_Flush(1);
  50. Cache_Read_Enable(0);
  51. Cache_Read_Enable(1);
  52. #elif CONFIG_IDF_TARGET_ESP32S2
  53. spi_noos_arg_t *spi_arg = arg;
  54. Cache_Invalidate_ICache_All();
  55. Cache_Resume_ICache(spi_arg->icache_autoload);
  56. Cache_Resume_DCache(spi_arg->dcache_autoload);
  57. #endif
  58. return ESP_OK;
  59. }
  60. static IRAM_ATTR esp_err_t delay_us(void *arg, unsigned us)
  61. {
  62. ets_delay_us(us);
  63. return ESP_OK;
  64. }
  65. const DRAM_ATTR esp_flash_os_functions_t esp_flash_noos_functions = {
  66. .start = start,
  67. .end = end,
  68. .delay_us = delay_us,
  69. .region_protected = NULL,
  70. .yield = NULL,
  71. };
  72. esp_err_t IRAM_ATTR esp_flash_app_disable_os_functions(esp_flash_t* chip)
  73. {
  74. chip->os_func = &esp_flash_noos_functions;
  75. #if CONFIG_IDF_TARGET_ESP32S2
  76. chip->os_func_data = &spi_arg;
  77. #endif
  78. return ESP_OK;
  79. }