cache_hal_esp32.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "hal/cache_ll.h"
  7. #include "hal/cache_hal.h"
  8. static uint32_t s_cache_status[2];
  9. /**
  10. * On ESP32, The cache_hal_suspend()/cache_hal_resume() are replacements
  11. * for Cache_Read_Disable()/Cache_Read_Enable() in ROM.
  12. * There's a bug that Cache_Read_Disable requires a call to Cache_Flush
  13. * before Cache_Read_Enable, even if cached data was not modified.
  14. */
  15. void cache_hal_suspend(uint32_t cache_level, cache_type_t type)
  16. {
  17. s_cache_status[0] = cache_ll_l1_get_enabled_bus(0);
  18. cache_ll_l1_disable_cache(0);
  19. #if !CONFIG_FREERTOS_UNICORE
  20. s_cache_status[1] = cache_ll_l1_get_enabled_bus(1);
  21. cache_ll_l1_disable_cache(1);
  22. #endif
  23. }
  24. void cache_hal_resume(uint32_t cache_level, cache_type_t type)
  25. {
  26. cache_ll_l1_enable_cache(0);
  27. cache_ll_l1_enable_bus(0, s_cache_status[0]);
  28. #if !CONFIG_FREERTOS_UNICORE
  29. cache_ll_l1_enable_cache(1);
  30. cache_ll_l1_enable_bus(1, s_cache_status[1]);
  31. #endif
  32. }
  33. bool cache_hal_is_cache_enabled(uint32_t cache_level, cache_type_t type)
  34. {
  35. bool result = cache_ll_l1_is_cache_enabled(0, CACHE_TYPE_ALL);
  36. #if !CONFIG_FREERTOS_UNICORE
  37. result = result && cache_ll_l1_is_cache_enabled(1, CACHE_TYPE_ALL);
  38. #endif
  39. return result;
  40. }
  41. bool cache_hal_vaddr_to_cache_level_id(uint32_t vaddr_start, uint32_t len, uint32_t *out_level, uint32_t *out_id)
  42. {
  43. if (!out_level || !out_id) {
  44. return false;
  45. }
  46. return cache_ll_vaddr_to_cache_level_id(vaddr_start, len, out_level, out_id);
  47. }
  48. uint32_t cache_hal_get_cache_line_size(uint32_t cache_level, cache_type_t type)
  49. {
  50. HAL_ASSERT(cache_level <= CACHE_LL_LEVEL_NUMS);
  51. uint32_t line_size = 0;
  52. if (cache_level == CACHE_LL_LEVEL_EXT_MEM) {
  53. line_size = 4;
  54. }
  55. return line_size;
  56. }
  57. bool cache_hal_invalidate_addr(uint32_t vaddr, uint32_t size)
  58. {
  59. //esp32 doesn't support invalidate certain addr
  60. abort();
  61. }