cache_utils.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2015-2016 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. #ifndef ESP_SPI_FLASH_CACHE_UTILS_H
  15. #define ESP_SPI_FLASH_CACHE_UTILS_H
  16. #include <stdbool.h>
  17. /**
  18. * This header file contains declarations of cache manipulation functions
  19. * used both in flash_ops.c and flash_mmap.c.
  20. *
  21. * These functions are considered internal and are not designed to be called from applications.
  22. */
  23. // Init mutex protecting access to spi_flash_* APIs
  24. void spi_flash_init_lock(void);
  25. // Take mutex protecting access to spi_flash_* APIs
  26. void spi_flash_op_lock(void);
  27. // Release said mutex
  28. void spi_flash_op_unlock(void);
  29. // Suspend the scheduler on both CPUs, disable cache.
  30. // Contrary to its name this doesn't do anything with interrupts, yet.
  31. // Interrupt disabling capability will be added once we implement
  32. // interrupt allocation API.
  33. void spi_flash_disable_interrupts_caches_and_other_cpu(void);
  34. // Enable cache, enable interrupts (to be added in future), resume scheduler
  35. void spi_flash_enable_interrupts_caches_and_other_cpu(void);
  36. // Disables non-IRAM interrupt handlers on current CPU and caches on both CPUs.
  37. // This function is implied to be called when other CPU is not running or running code from IRAM.
  38. void spi_flash_disable_interrupts_caches_and_other_cpu_no_os(void);
  39. // Enable cache, enable interrupts on current CPU.
  40. // This function is implied to be called when other CPU is not running or running code from IRAM.
  41. void spi_flash_enable_interrupts_caches_no_os(void);
  42. // Mark the pages containing a flash region as having been
  43. // erased or written to. This means the flash cache needs
  44. // to be evicted before these pages can be flash_mmap()ed again,
  45. // as they may contain stale data
  46. //
  47. // Only call this while holding spi_flash_op_lock()
  48. // Returns true if cache was flushed, false otherwise
  49. bool spi_flash_check_and_flush_cache(uint32_t start_addr, uint32_t length);
  50. //config cache mode
  51. #ifdef CONFIG_IDF_TARGET_ESP32S2
  52. //config instrcutin cache size and cache block size by menuconfig
  53. void esp_config_instruction_cache_mode(void);
  54. //config data cache size and cache block size by menuconfig
  55. void esp_config_data_cache_mode(void);
  56. //enable cache wrap mode for instruction cache and data cache
  57. esp_err_t esp_enable_cache_wrap(bool icache_wrap_enable, bool dcache_wrap_enable);
  58. #endif
  59. #endif //ESP_SPI_FLASH_CACHE_UTILS_H