esp_cache.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 with the values that just written
  19. */
  20. #define ESP_CACHE_MSYNC_FLAG_INVALIDATE BIT(0)
  21. /**
  22. * @brief Allow writeback a block that are not aligned to the data cache line size
  23. */
  24. #define ESP_CACHE_MSYNC_FLAG_UNALIGNED BIT(1)
  25. /**
  26. * @brief Memory sync between Cache and external memory
  27. *
  28. * - For cache writeback supported chips (you can refer to SOC_CACHE_WRITEBACK_SUPPORTED in soc_caps.h)
  29. * - this API will do a writeback to synchronise between cache and the PSRAM
  30. * - with ESP_CACHE_MSYNC_FLAG_INVALIDATE, this API will also invalidate the values that just written
  31. * - note: although ESP32 is with PSRAM, but cache writeback isn't supported, so this API will do nothing on ESP32
  32. * - For other chips, this API will do nothing. The out-of-sync should be already dealt by the SDK
  33. *
  34. * This API is cache-safe and thread-safe
  35. *
  36. * @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)
  37. * @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
  38. *
  39. * @param[in] addr Starting address to do the msync
  40. * @param[in] size Size to do the msync
  41. * @param[in] flags Flags, see `ESP_CACHE_MSYNC_FLAG_x`
  42. *
  43. * @return
  44. * - ESP_OK:
  45. * - Successful msync
  46. * - If this chip doesn't support cache writeback, if the input addr is a cache supported one, this API will return ESP_OK
  47. * - ESP_ERR_INVALID_ARG: Invalid argument, not cache supported addr, see printed logs
  48. */
  49. esp_err_t esp_cache_msync(void *addr, size_t size, int flags);
  50. #ifdef __cplusplus
  51. }
  52. #endif