cache_utils.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "sdkconfig.h"
  8. #include <stdbool.h>
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #include "esp_err.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /**
  16. * This header file contains declarations of cache manipulation functions
  17. * used both in flash_ops.c and flash_mmap.c.
  18. *
  19. * These functions are considered internal and are not designed to be called from applications.
  20. */
  21. // Init mutex protecting access to spi_flash_* APIs
  22. void spi_flash_init_lock(void);
  23. // Take mutex protecting access to spi_flash_* APIs
  24. void spi_flash_op_lock(void);
  25. // Release said mutex
  26. void spi_flash_op_unlock(void);
  27. // Suspend the scheduler on both CPUs, disable cache.
  28. // Contrary to its name this doesn't do anything with interrupts, yet.
  29. // Interrupt disabling capability will be added once we implement
  30. // interrupt allocation API.
  31. void spi_flash_disable_interrupts_caches_and_other_cpu(void);
  32. // Enable cache, enable interrupts (to be added in future), resume scheduler
  33. void spi_flash_enable_interrupts_caches_and_other_cpu(void);
  34. // Disables non-IRAM interrupt handlers on current CPU and caches on both CPUs.
  35. // This function is implied to be called when other CPU is not running or running code from IRAM.
  36. void spi_flash_disable_interrupts_caches_and_other_cpu_no_os(void);
  37. // Enable cache, enable interrupts on current CPU.
  38. // This function is implied to be called when other CPU is not running or running code from IRAM.
  39. void spi_flash_enable_interrupts_caches_no_os(void);
  40. // Mark the pages containing a flash region as having been
  41. // erased or written to. This means the flash cache needs
  42. // to be evicted before these pages can be flash_mmap()ed again,
  43. // as they may contain stale data
  44. //
  45. // Only call this while holding spi_flash_op_lock()
  46. // Returns true if cache was flushed, false otherwise
  47. bool spi_flash_check_and_flush_cache(size_t start_addr, size_t length);
  48. //config cache mode
  49. #if !CONFIG_IDF_TARGET_ESP32
  50. //config instrcutin cache size and cache block size by menuconfig
  51. void esp_config_instruction_cache_mode(void);
  52. //config data cache size and cache block size by menuconfig
  53. void esp_config_data_cache_mode(void);
  54. //enable cache wrap mode for instruction cache and data cache
  55. esp_err_t esp_enable_cache_wrap(bool icache_wrap_enable, bool dcache_wrap_enable);
  56. #endif
  57. /** @brief Check at runtime if flash cache is enabled on both CPUs
  58. *
  59. * @return true if both CPUs have flash cache enabled, false otherwise.
  60. */
  61. bool spi_flash_cache_enabled(void);
  62. /**
  63. * @brief Re-enable cache for the core defined as cpuid parameter.
  64. *
  65. * @param cpuid the core number to enable instruction cache for
  66. */
  67. void spi_flash_enable_cache(uint32_t cpuid);
  68. #ifdef __cplusplus
  69. }
  70. #endif