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.11 of the AmbiqSuite Development Package.
  41. //
  42. //*****************************************************************************
  43. #ifndef AM_HAL_CACHECTRL_H
  44. #define AM_HAL_CACHECTRL_H
  45. //*****************************************************************************
  46. //
  47. // Cache configuration structure
  48. //
  49. //*****************************************************************************
  50. typedef struct
  51. {
  52. //
  53. //! Set to 1 to enable the cache.
  54. //
  55. uint8_t ui32EnableCache;
  56. //
  57. //! Set to 1 to enable the LRU cache replacement policy.
  58. //! Set to 0 to enable the LRR (least recently used) replacement policy.
  59. //! LEE minimizes writes to the TAG SRAM.
  60. //
  61. uint8_t ui32LRU;
  62. //
  63. //! Set to 3 to enable non-cachable region 1 and non-cachable region 0.
  64. //! Set to 2 to enable non-cachable region 1.
  65. //! Set to 1 to enable non-cachable region 0.
  66. //! Set to 0 to make all regions cacheable.
  67. //
  68. uint8_t ui32EnableNCregions;
  69. //
  70. //! Set to:
  71. //! AM_HAL_CACHECTRL_CACHECFG_CONFIG_DIRECT_256 for direct-mapped,
  72. //! 128-bit linesize, 256 entries (2 SRAMs active)
  73. //! AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_256 for two-way set associative,
  74. //! 128-bit linesize, 256 entries (4 SRAMs active)
  75. //! AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512 for two-way set associative,
  76. //! 128-bit linesize, 512 entries (8 SRAMs active)
  77. //
  78. uint8_t ui32Config;
  79. //
  80. //! Set to 1 to enable serial cache mode.
  81. //
  82. uint8_t ui32SerialCacheMode;
  83. //
  84. //! Set to 3 to enable flash data caching and flash instruction caching.
  85. //! Set to 2 to enable flash data caching.
  86. //! Set to 1 to enable flash instruction caching.
  87. //! Set to 0 to disable flash data caching and flash instruction caching.
  88. //
  89. uint8_t ui32FlashCachingEnables;
  90. //
  91. //! Set to 1 to enable clock gating of cache RAMs.
  92. //
  93. uint8_t ui32EnableCacheClockGating;
  94. //
  95. //! Set to 1 to enable light sleep of cache RAMs.
  96. //
  97. uint8_t ui32EnableLightSleep;
  98. //
  99. //! Set Data RAM delay value (0x0 - 0xF).
  100. //
  101. uint8_t ui32Dly;
  102. //
  103. //! Set SM Data RAM delay value (0x0 - 0xF).
  104. //
  105. uint8_t ui32SMDly;
  106. //
  107. //! Set to 1 to enable clock gating of the entire data array.
  108. //
  109. uint8_t ui32EnableDataClockGating;
  110. //
  111. //! Set to 1 to enable cache monitor statistics.
  112. //
  113. uint8_t ui32EnableCacheMonitoring;
  114. }
  115. am_hal_cachectrl_config_t;
  116. extern const am_hal_cachectrl_config_t am_hal_cachectrl_defaults;
  117. //*****************************************************************************
  118. //
  119. //! @name Cache enables
  120. //! @brief Configuration selection for the various cache enables.
  121. //!
  122. //! These macros may be used in conjunction with the
  123. //! am_hal_cachectrl_cache_enable() function to enable various cache features.
  124. //!
  125. //! @{
  126. //
  127. //*****************************************************************************
  128. #define AM_HAL_CACHECTRL_CACHECFG_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_M
  129. #define AM_HAL_CACHECTRL_CACHECFG_LRU_ENABLE AM_REG_CACHECTRL_CACHECFG_LRU_M
  130. #define AM_HAL_CACHECTRL_CACHECFG_NC0_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_NC0_M
  131. #define AM_HAL_CACHECTRL_CACHECFG_NC1_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_NC1_M
  132. #define AM_HAL_CACHECTRL_CACHECFG_SERIAL_ENABLE AM_REG_CACHECTRL_CACHECFG_SERIAL_M
  133. #define AM_HAL_CACHECTRL_CACHECFG_ICACHE_ENABLE AM_REG_CACHECTRL_CACHECFG_ICACHE_ENABLE_M
  134. #define AM_HAL_CACHECTRL_CACHECFG_DCACHE_ENABLE AM_REG_CACHECTRL_CACHECFG_DCACHE_ENABLE_M
  135. #define AM_HAL_CACHECTRL_CACHECFG_CACHE_CLKGATE_ENABLE AM_REG_CACHECTRL_CACHECFG_CACHE_CLKGATE_M
  136. #define AM_HAL_CACHECTRL_CACHECFG_LS_ENABLE AM_REG_CACHECTRL_CACHECFG_CACHE_LS_M
  137. #define AM_HAL_CACHECTRL_CACHECFG_DATA_CLKGATE_ENABLE AM_REG_CACHECTRL_CACHECFG_DATA_CLKGATE_M
  138. #define AM_HAL_CACHECTRL_CACHECFG_MONITOR_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_MONITOR_M
  139. //! @}
  140. //*****************************************************************************
  141. //
  142. //! @name Cache Config
  143. //! @brief Configuration selection for the cache.
  144. //!
  145. //! These macros may be used in conjunction with the
  146. //! am_hal_cachectrl_cache_config() function to select the cache type.
  147. //!
  148. //! @{
  149. //
  150. //*****************************************************************************
  151. #define AM_HAL_CACHECTRL_CACHECFG_CONFIG_DIRECT_256 AM_REG_CACHECTRL_CACHECFG_CONFIG_W1_128B_256E
  152. #define AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_256 AM_REG_CACHECTRL_CACHECFG_CONFIG_W2_128B_256E
  153. #define AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512 AM_REG_CACHECTRL_CACHECFG_CONFIG_W2_128B_512E
  154. //! @}
  155. //*****************************************************************************
  156. //
  157. // Default cache settings
  158. //
  159. //*****************************************************************************
  160. #define AM_HAL_CACHECTRL_DEFAULTS \
  161. (AM_HAL_CACHECTRL_CACHECFG_ICACHE_ENABLE | \
  162. AM_HAL_CACHECTRL_CACHECFG_DCACHE_ENABLE | \
  163. AM_HAL_CACHECTRL_CACHECFG_CACHE_CLKGATE_ENABLE | \
  164. AM_HAL_CACHECTRL_CACHECFG_DATA_CLKGATE_ENABLE | \
  165. AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512)
  166. #ifdef __cplusplus
  167. extern "C"
  168. {
  169. #endif
  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