1 2 /* 3 * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 #pragma once 9 10 #include <stdbool.h> 11 #include "hal/cache_types.h" 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /** 18 * Cache init and cache hal context init 19 */ 20 void cache_hal_init(void); 21 22 /** 23 * @brief Disable cache 24 * 25 * Disable the ICache or DCache or both, all the items in the corresponding Cache(s) will be invalideated. 26 * Next request to these items will trigger a transaction to the external memory (flash / psram) 27 * 28 * @note If the autoload feature is enabled, this API will return until the ICache autoload is disabled. 29 * 30 * @param type see `cache_type_t` 31 */ 32 void cache_hal_disable(cache_type_t type); 33 34 /** 35 * @brief Enable cache 36 * 37 * Enable the ICache or DCache or both. 38 * 39 * @param type see `cache_type_t` 40 */ 41 void cache_hal_enable(cache_type_t type); 42 43 /** 44 * @brief Suspend cache 45 * 46 * Suspend the ICache or DCache or both,suspends the CPU access to cache for a while, without invalidation. 47 * 48 * @param type see `cache_type_t` 49 * 50 * @return Current status of corresponding Cache(s) 51 */ 52 void cache_hal_suspend(cache_type_t type); 53 54 /** 55 * @brief Resume cache 56 * 57 * Resume the ICache or DCache or both. 58 * 59 * @param type see `cache_type_t` 60 */ 61 void cache_hal_resume(cache_type_t type); 62 63 /** 64 * @brief Check if corresponding cache is enabled or not 65 * 66 * @param type see `cache_type_t` 67 * 68 * @return true: enabled; false: disabled 69 */ 70 bool cache_hal_is_cache_enabled(cache_type_t type); 71 72 /** 73 * @brief Invalidate cache supported addr 74 * 75 * Invalidate a Cache item for either ICache or DCache. 76 * 77 * @param vaddr Start address of the region to be invalidated 78 * @param size Size of the region to be invalidated 79 */ 80 void cache_hal_invalidate_addr(uint32_t vaddr, uint32_t size); 81 82 #if SOC_CACHE_WRITEBACK_SUPPORTED 83 /** 84 * @brief Writeback cache supported addr 85 * 86 * Writeback the DCache item to external memory 87 * 88 * @param vaddr Start address of the region to writeback 89 * @param size Size of the region to writeback 90 */ 91 void cache_hal_writeback_addr(uint32_t vaddr, uint32_t size); 92 #endif //#if SOC_CACHE_WRITEBACK_SUPPORTED 93 94 #if SOC_CACHE_FREEZE_SUPPORTED 95 /** 96 * @brief Freeze cache 97 * 98 * Freeze cache, CPU access to cache will be suspended, until the cache is unfrozen. 99 * 100 * @param type see `cache_type_t` 101 */ 102 void cache_hal_freeze(cache_type_t type); 103 104 /** 105 * @brief Unfreeze cache 106 * 107 * Unfreeze cache, CPU access to cache will be restored 108 * 109 * @param type see `cache_type_t` 110 */ 111 void cache_hal_unfreeze(cache_type_t type); 112 #endif //#if SOC_CACHE_FREEZE_SUPPORTED 113 114 /** 115 * @brief Get cache line size, in bytes 116 * 117 * @param type see `cache_type_t` 118 * 119 * @return cache line size, in bytes 120 */ 121 uint32_t cache_hal_get_cache_line_size(cache_type_t type); 122 123 #ifdef __cplusplus 124 } 125 #endif 126