esp_cache.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdlib.h>
  8. #include <stdint.h>
  9. #include "esp_err.h"
  10. #include "esp_bit_defs.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /**
  15. * Cache msync flags
  16. */
  17. /**
  18. * @brief Do an invalidation
  19. * - For cache-to-memory (C2M) direction: setting this flag will start an invalidation after the cache writeback operation
  20. * - For memory-to-cache (M2C) direction: setting / unsetting this flag will behave similarly, trigger an invalidation
  21. */
  22. #define ESP_CACHE_MSYNC_FLAG_INVALIDATE BIT(0)
  23. /**
  24. * @brief Allow msync to a address block that are not aligned to the data cache line size
  25. */
  26. #define ESP_CACHE_MSYNC_FLAG_UNALIGNED BIT(1)
  27. /**
  28. * @brief Cache msync direction: from Cache to memory
  29. * @note If you don't set direction (ESP_CACHE_MSYNC_FLAG_DIR_x flags), it is by default cache-to-memory (C2M) direction
  30. */
  31. #define ESP_CACHE_MSYNC_FLAG_DIR_C2M BIT(2)
  32. /**
  33. * @brief Cache msync direction: from memory to Cache
  34. */
  35. #define ESP_CACHE_MSYNC_FLAG_DIR_M2C BIT(3)
  36. /**
  37. * @brief Cache msync type: data
  38. * @note If you don't set type (ESP_CACHE_MSYNC_FLAG_TYPE_x flags), it is by default data type
  39. */
  40. #define ESP_CACHE_MSYNC_FLAG_TYPE_DATA BIT(4)
  41. /**
  42. * @brief Cache msync type: instruction
  43. */
  44. #define ESP_CACHE_MSYNC_FLAG_TYPE_INST BIT(5)
  45. /**
  46. * @brief Memory sync between Cache and storage memory
  47. *
  48. *
  49. * For cache-to-memory (C2M) direction:
  50. * - For cache writeback supported chips (you can refer to SOC_CACHE_WRITEBACK_SUPPORTED in soc_caps.h)
  51. * - This API will do a writeback to synchronise between cache and storage memory
  52. * - With ESP_CACHE_MSYNC_FLAG_INVALIDATE, this API will also invalidate the values that just written
  53. * - Note: although ESP32 is with PSRAM, but cache writeback isn't supported, so this API will do nothing on ESP32
  54. * - For other chips, this API will do nothing. The out-of-sync should be already dealt by the SDK
  55. *
  56. * For memory-to-cache (M2C) direction:
  57. * - This API will by default do an invalidation
  58. *
  59. * This API is cache-safe and thread-safe
  60. *
  61. * @note If you don't set direction (ESP_CACHE_MSYNC_FLAG_DIR_x flags), this API is by default C2M direction
  62. * @note If you don't set type (ESP_CACHE_MSYNC_FLAG_TYPE_x flags), this API is by default doing msync for data
  63. * @note You should not call this during any Flash operations (e.g. esp_flash APIs, nvs and some other APIs that are based on esp_flash APIs)
  64. * @note If XIP_From_PSRAM is enabled (by enabling both CONFIG_SPIRAM_FETCH_INSTRUCTIONS and CONFIG_SPIRAM_RODATA), you can call this API during Flash operations
  65. *
  66. * @param[in] addr Starting address to do the msync
  67. * @param[in] size Size to do the msync
  68. * @param[in] flags Flags, see `ESP_CACHE_MSYNC_FLAG_x`
  69. *
  70. * @return
  71. * - ESP_OK:
  72. * - Successful msync
  73. * - For C2M direction, if this chip doesn't support cache writeback, if the input addr is a cache supported one, this API will return ESP_OK
  74. * - ESP_ERR_INVALID_ARG: Invalid argument, not cache supported addr, see printed logs
  75. */
  76. esp_err_t esp_cache_msync(void *addr, size_t size, int flags);
  77. #ifdef __cplusplus
  78. }
  79. #endif