am_hal_cachectrl.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //*****************************************************************************
  2. //
  3. // am_hal_cachectrl.h
  4. //! @file
  5. //!
  6. //! @brief Functions for accessing and configuring the CACHE controller.
  7. //
  8. //*****************************************************************************
  9. //*****************************************************************************
  10. //
  11. // Copyright (c) 2017, Ambiq Micro
  12. // All rights reserved.
  13. //
  14. // Redistribution and use in source and binary forms, with or without
  15. // modification, are permitted provided that the following conditions are met:
  16. //
  17. // 1. Redistributions of source code must retain the above copyright notice,
  18. // this list of conditions and the following disclaimer.
  19. //
  20. // 2. Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the distribution.
  23. //
  24. // 3. Neither the name of the copyright holder nor the names of its
  25. // contributors may be used to endorse or promote products derived from this
  26. // software without specific prior written permission.
  27. //
  28. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  29. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  32. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  34. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  35. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  37. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. // POSSIBILITY OF SUCH DAMAGE.
  39. //
  40. // This is part of revision 1.2.9 of the AmbiqSuite Development Package.
  41. //
  42. //*****************************************************************************
  43. #ifndef AM_HAL_CACHECTRL_H
  44. #define AM_HAL_CACHECTRL_H
  45. #ifdef __cplusplus
  46. extern "C"
  47. {
  48. #endif
  49. //*****************************************************************************
  50. //
  51. // Cache configuration structure
  52. //
  53. //*****************************************************************************
  54. typedef struct
  55. {
  56. //
  57. //! Set to 1 to enable the cache.
  58. //
  59. uint8_t ui32EnableCache;
  60. //
  61. //! Set to 1 to enable the LRU cache replacement policy.
  62. //! Set to 0 to enable the LRR (least recently used) replacement policy.
  63. //! LEE minimizes writes to the TAG SRAM.
  64. //
  65. uint8_t ui32LRU;
  66. //
  67. //! Set to 3 to enable non-cachable region 1 and non-cachable region 0.
  68. //! Set to 2 to enable non-cachable region 1.
  69. //! Set to 1 to enable non-cachable region 0.
  70. //! Set to 0 to make all regions cacheable.
  71. //
  72. uint8_t ui32EnableNCregions;
  73. //
  74. //! Set to:
  75. //! AM_HAL_CACHECTRL_CACHECFG_CONFIG_DIRECT_256 for direct-mapped,
  76. //! 128-bit linesize, 256 entries (2 SRAMs active)
  77. //! AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_256 for two-way set associative,
  78. //! 128-bit linesize, 256 entries (4 SRAMs active)
  79. //! AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512 for two-way set associative,
  80. //! 128-bit linesize, 512 entries (8 SRAMs active)
  81. //
  82. uint8_t ui32Config;
  83. //
  84. //! Set to 1 to enable serial cache mode.
  85. //
  86. uint8_t ui32SerialCacheMode;
  87. //
  88. //! Set to 3 to enable flash data caching and flash instruction caching.
  89. //! Set to 2 to enable flash data caching.
  90. //! Set to 1 to enable flash instruction caching.
  91. //! Set to 0 to disable flash data caching and flash instruction caching.
  92. //
  93. uint8_t ui32FlashCachingEnables;
  94. //
  95. //! Set to 1 to enable clock gating of cache RAMs.
  96. //
  97. uint8_t ui32EnableCacheClockGating;
  98. //
  99. //! Set to 1 to enable light sleep of cache RAMs.
  100. //
  101. uint8_t ui32EnableLightSleep;
  102. //
  103. //! Set Data RAM delay value (0x0 - 0xF).
  104. //
  105. uint8_t ui32Dly;
  106. //
  107. //! Set SM Data RAM delay value (0x0 - 0xF).
  108. //
  109. uint8_t ui32SMDly;
  110. //
  111. //! Set to 1 to enable clock gating of the entire data array.
  112. //
  113. uint8_t ui32EnableDataClockGating;
  114. //
  115. //! Set to 1 to enable cache monitor statistics.
  116. //
  117. uint8_t ui32EnableCacheMonitoring;
  118. }
  119. am_hal_cachectrl_config_t;
  120. extern const am_hal_cachectrl_config_t am_hal_cachectrl_defaults;
  121. //*****************************************************************************
  122. //
  123. //! @name Cache enables
  124. //! @brief Configuration selection for the various cache enables.
  125. //!
  126. //! These macros may be used in conjunction with the
  127. //! am_hal_cachectrl_cache_enable() function to enable various cache features.
  128. //!
  129. //! @{
  130. //
  131. //*****************************************************************************
  132. #define AM_HAL_CACHECTRL_CACHECFG_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_M
  133. #define AM_HAL_CACHECTRL_CACHECFG_LRU_ENABLE AM_REG_CACHECTRL_CACHECFG_LRU_M
  134. #define AM_HAL_CACHECTRL_CACHECFG_NC0_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_NC0_M
  135. #define AM_HAL_CACHECTRL_CACHECFG_NC1_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_NC1_M
  136. #define AM_HAL_CACHECTRL_CACHECFG_SERIAL_ENABLE AM_REG_CACHECTRL_CACHECFG_SERIAL_M
  137. #define AM_HAL_CACHECTRL_CACHECFG_ICACHE_ENABLE AM_REG_CACHECTRL_CACHECFG_ICACHE_ENABLE_M
  138. #define AM_HAL_CACHECTRL_CACHECFG_DCACHE_ENABLE AM_REG_CACHECTRL_CACHECFG_DCACHE_ENABLE_M
  139. #define AM_HAL_CACHECTRL_CACHECFG_CACHE_CLKGATE_ENABLE AM_REG_CACHECTRL_CACHECFG_CACHE_CLKGATE_M
  140. #define AM_HAL_CACHECTRL_CACHECFG_LS_ENABLE AM_REG_CACHECTRL_CACHECFG_CACHE_LS_M
  141. #define AM_HAL_CACHECTRL_CACHECFG_DATA_CLKGATE_ENABLE AM_REG_CACHECTRL_CACHECFG_DATA_CLKGATE_M
  142. #define AM_HAL_CACHECTRL_CACHECFG_MONITOR_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_MONITOR_M
  143. //! @}
  144. //*****************************************************************************
  145. //
  146. //! @name Cache Config
  147. //! @brief Configuration selection for the cache.
  148. //!
  149. //! These macros may be used in conjunction with the
  150. //! am_hal_cachectrl_cache_config() function to select the cache type.
  151. //!
  152. //! @{
  153. //
  154. //*****************************************************************************
  155. #define AM_HAL_CACHECTRL_CACHECFG_CONFIG_DIRECT_256 AM_REG_CACHECTRL_CACHECFG_CONFIG_W1_128B_256E
  156. #define AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_256 AM_REG_CACHECTRL_CACHECFG_CONFIG_W2_128B_256E
  157. #define AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512 AM_REG_CACHECTRL_CACHECFG_CONFIG_W2_128B_512E
  158. //! @}
  159. //*****************************************************************************
  160. //
  161. // Default cache settings
  162. //
  163. //*****************************************************************************
  164. #define AM_HAL_CACHECTRL_DEFAULTS \
  165. (AM_HAL_CACHECTRL_CACHECFG_ICACHE_ENABLE | \
  166. AM_HAL_CACHECTRL_CACHECFG_DCACHE_ENABLE | \
  167. AM_HAL_CACHECTRL_CACHECFG_CACHE_CLKGATE_ENABLE | \
  168. AM_HAL_CACHECTRL_CACHECFG_DATA_CLKGATE_ENABLE | \
  169. AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512)
  170. //*****************************************************************************
  171. //
  172. // External function definitions
  173. //
  174. //*****************************************************************************
  175. extern void am_hal_cachectrl_enable(const am_hal_cachectrl_config_t *psConfig);
  176. extern void am_hal_cachectrl_disable(void);
  177. extern void am_hal_cachectrl_config_default(void);
  178. extern void am_hal_cachectrl_config(am_hal_cachectrl_config_t *psConfig);
  179. extern uint32_t am_hal_cachectrl_cache_enables(uint32_t u32EnableMask,
  180. uint32_t u32DisableMask);
  181. extern void am_hal_cachectrl_cache_config(uint32_t ui32CacheConfig);
  182. extern void am_hal_cachectrl_invalidate_flash_cache(void);
  183. extern void am_hal_cachectrl_reset_statistics(void);
  184. extern uint32_t am_hal_cachectrl_sleep_mode_status(void);
  185. extern uint32_t am_hal_cachectrl_sleep_mode_enable(uint32_t ui32EnableMask,
  186. uint32_t ui32DisableMask);
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif // AM_HAL_CACHECTRL_H