am_hal_cachectrl.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. //*****************************************************************************
  2. //
  3. // am_hal_cachectrl.c
  4. //! @file
  5. //!
  6. //! @brief Functions for interfacing with the CACHE controller.
  7. //!
  8. //! @addtogroup clkgen2 Clock Generator (CACHE)
  9. //! @ingroup apollo2hal
  10. //! @{
  11. //
  12. //*****************************************************************************
  13. //*****************************************************************************
  14. //
  15. // Copyright (c) 2017, Ambiq Micro
  16. // All rights reserved.
  17. //
  18. // Redistribution and use in source and binary forms, with or without
  19. // modification, are permitted provided that the following conditions are met:
  20. //
  21. // 1. Redistributions of source code must retain the above copyright notice,
  22. // this list of conditions and the following disclaimer.
  23. //
  24. // 2. Redistributions in binary form must reproduce the above copyright
  25. // notice, this list of conditions and the following disclaimer in the
  26. // documentation and/or other materials provided with the distribution.
  27. //
  28. // 3. Neither the name of the copyright holder nor the names of its
  29. // contributors may be used to endorse or promote products derived from this
  30. // software without specific prior written permission.
  31. //
  32. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  33. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  36. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  37. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  39. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  40. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  42. // POSSIBILITY OF SUCH DAMAGE.
  43. //
  44. // This is part of revision 1.2.11 of the AmbiqSuite Development Package.
  45. //
  46. //*****************************************************************************
  47. #include <stdint.h>
  48. #include <stdbool.h>
  49. #include "am_mcu_apollo.h"
  50. //*****************************************************************************
  51. //
  52. // Default settings for the cache.
  53. //
  54. //*****************************************************************************
  55. const am_hal_cachectrl_config_t am_hal_cachectrl_defaults =
  56. {
  57. 1, // ui32EnableCache
  58. 0, // ui32LRU
  59. 0, // ui32EnableNCregions
  60. AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512, // ui32Config
  61. 0, // ui32SerialCacheMode
  62. 3, // ui32FlashCachingEnables
  63. 1, // ui32EnableCacheClockGating
  64. 0, // ui32EnableLightSleep
  65. 1, // ui32Dly
  66. 1, // ui32SMDly
  67. 1, // ui32EnableDataClockGating
  68. 0, // ui32EnableCacheMonitoring
  69. };
  70. //*****************************************************************************
  71. //
  72. //! @brief Enable the cache using the supplied settings
  73. //!
  74. //! @param psConfig - pointer to a config structure containing cache settings.
  75. //!
  76. //! This function takes in a structure of cache settings, and uses them to
  77. //! enable the cache. This function will take care of the necessary register
  78. //! writes both in this module and in the power control module, so a separate
  79. //! powerctrl call is not necessary.
  80. //!
  81. //! For most applications, the default cache settings will be the most
  82. //! efficient choice. To use the default cache settings with this function, use
  83. //! the address of the global am_hal_cachectrl_defaults structure as the
  84. //! psConfig argument.
  85. //!
  86. //! @return None.
  87. //
  88. //*****************************************************************************
  89. void
  90. am_hal_cachectrl_enable(const am_hal_cachectrl_config_t *psConfig)
  91. {
  92. uint32_t ui32ConfigValue;
  93. uint32_t ui32Timeout;
  94. //
  95. // Pull the configuration data from the structure, and prepare to write the
  96. // cache configuration register.
  97. //
  98. // NOTE: ICACHE and DCACHE settings were left out from this step. This is a
  99. // workaround for a timing issue with early versions of Apollo2 that caused
  100. // the cache to incorrectly mark itself valid during the startup sequence.
  101. // The workaround calls for us to start the cache, manually invalidate it,
  102. // and then enable ICACHE and DCACHE operation.
  103. //
  104. ui32ConfigValue = (AM_REG_CACHECTRL_CACHECFG_ENABLE( 1 ) |
  105. AM_REG_CACHECTRL_CACHECFG_LRU( psConfig->ui32LRU ) |
  106. AM_REG_CACHECTRL_CACHECFG_ENABLE_NC0( (psConfig->ui32EnableNCregions & 0x1) >> 0 ) |
  107. AM_REG_CACHECTRL_CACHECFG_ENABLE_NC1( (psConfig->ui32EnableNCregions & 0x2) >> 1 ) |
  108. psConfig->ui32Config |
  109. AM_REG_CACHECTRL_CACHECFG_SERIAL(psConfig->ui32SerialCacheMode) |
  110. AM_REG_CACHECTRL_CACHECFG_CACHE_CLKGATE( psConfig->ui32EnableCacheClockGating ) |
  111. AM_REG_CACHECTRL_CACHECFG_CACHE_LS(psConfig->ui32EnableLightSleep ) |
  112. AM_REG_CACHECTRL_CACHECFG_DLY( psConfig->ui32Dly ) |
  113. AM_REG_CACHECTRL_CACHECFG_SMDLY( psConfig->ui32SMDly ) |
  114. AM_REG_CACHECTRL_CACHECFG_DATA_CLKGATE(psConfig->ui32EnableDataClockGating) |
  115. AM_REG_CACHECTRL_CACHECFG_ENABLE_MONITOR(psConfig->ui32EnableCacheMonitoring) );
  116. //
  117. // Make sure the cache is enabled in the power control block.
  118. //
  119. am_hal_pwrctrl_memory_enable(AM_HAL_PWRCTRL_MEMEN_CACHE);
  120. //
  121. // Set the initial cache settings.
  122. //
  123. AM_REG(CACHECTRL, CACHECFG) = ui32ConfigValue;
  124. //
  125. // Wait for the cache ready signal.
  126. //
  127. for (ui32Timeout = 0; ui32Timeout < 50; ui32Timeout++)
  128. {
  129. if (AM_BFM(CACHECTRL, CACHECTRL, CACHE_READY))
  130. {
  131. break;
  132. }
  133. }
  134. //
  135. // Manually invalidate the cache (workaround for the issue described above.)
  136. //
  137. AM_BFW(CACHECTRL, CACHECTRL, INVALIDATE, 1);
  138. //
  139. // Wait for the cache ready signal again.
  140. //
  141. for (ui32Timeout = 0; ui32Timeout < 50; ui32Timeout++)
  142. {
  143. if (AM_BFM(CACHECTRL, CACHECTRL, CACHE_READY))
  144. {
  145. break;
  146. }
  147. }
  148. //
  149. // Now that the cache is running, and correctly marked invalid, we can OR in
  150. // the ICACHE and DCACHE settings.
  151. //
  152. ui32ConfigValue |= (AM_REG_CACHECTRL_CACHECFG_ICACHE_ENABLE( (psConfig->ui32FlashCachingEnables & 0x1) >> 0 ) |
  153. AM_REG_CACHECTRL_CACHECFG_DCACHE_ENABLE( (psConfig->ui32FlashCachingEnables & 0x2) >> 1 ) );
  154. //
  155. // Write the final configuration settings to the CACHECTRL register.
  156. //
  157. AM_REG(CACHECTRL, CACHECFG) = ui32ConfigValue;
  158. }
  159. //*****************************************************************************
  160. //
  161. //! @brief Disable the cache.
  162. //!
  163. //! Call this function to completely shut down cache features.
  164. //!
  165. //! @return None.
  166. //
  167. //*****************************************************************************
  168. void
  169. am_hal_cachectrl_disable(void)
  170. {
  171. uint32_t ui32CacheCfg;
  172. //
  173. // Save the cache settings.
  174. //
  175. ui32CacheCfg = AM_REG(CACHECTRL, CACHECFG);
  176. //
  177. // Remove the ICACHE and DCACHE settings.
  178. //
  179. ui32CacheCfg &= (AM_REG_CACHECTRL_CACHECFG_DCACHE_ENABLE(0) |
  180. AM_REG_CACHECTRL_CACHECFG_ICACHE_ENABLE(0));
  181. //
  182. // Write the resulting value back to the register.
  183. //
  184. AM_REG(CACHECTRL, CACHECFG) = ui32CacheCfg;
  185. //
  186. // Read the CACHECTRL register a few times
  187. //
  188. AM_REG(CACHECTRL, CACHECTRL);
  189. AM_REG(CACHECTRL, CACHECTRL);
  190. AM_REG(CACHECTRL, CACHECTRL);
  191. //
  192. // Disable the cache completely.
  193. //
  194. AM_BFW(CACHECTRL, CACHECFG, ENABLE, 0);
  195. //
  196. // Power the cache down in the powerctrl block.
  197. //
  198. am_hal_pwrctrl_memory_enable(AM_HAL_PWRCTRL_MEMEN_CACHE_DIS);
  199. }
  200. //*****************************************************************************
  201. //
  202. //! @brief Set a default cache configuration.
  203. //!
  204. //! This function is used to set a default cache configuration.
  205. //
  206. //*****************************************************************************
  207. void
  208. am_hal_cachectrl_config_default(void)
  209. {
  210. //
  211. // Set PWRCTRL
  212. //
  213. am_hal_pwrctrl_memory_enable(AM_HAL_PWRCTRL_MEMEN_CACHE);
  214. //
  215. // Write a default configuration to the CACHECFG register.
  216. //
  217. AM_REG(CACHECTRL, CACHECFG) = \
  218. AM_REG_CACHECTRL_CACHECFG_ENABLE( 1 ) | \
  219. AM_REG_CACHECTRL_CACHECFG_LRU( 0 ) | \
  220. AM_REG_CACHECTRL_CACHECFG_ENABLE_NC0( 0 ) | \
  221. AM_REG_CACHECTRL_CACHECFG_ENABLE_NC1( 0 ) | \
  222. AM_REG_CACHECTRL_CACHECFG_CONFIG_W2_128B_512E | \
  223. AM_REG_CACHECTRL_CACHECFG_SERIAL( 0 ) | \
  224. AM_REG_CACHECTRL_CACHECFG_ICACHE_ENABLE( 1 ) | \
  225. AM_REG_CACHECTRL_CACHECFG_DCACHE_ENABLE( 1 ) | \
  226. AM_REG_CACHECTRL_CACHECFG_CACHE_CLKGATE( 1 ) | \
  227. AM_REG_CACHECTRL_CACHECFG_CACHE_LS( 0 ) | \
  228. AM_REG_CACHECTRL_CACHECFG_DLY( 1 ) | \
  229. AM_REG_CACHECTRL_CACHECFG_SMDLY( 1 ) | \
  230. AM_REG_CACHECTRL_CACHECFG_DATA_CLKGATE( 1 ) | \
  231. AM_REG_CACHECTRL_CACHECFG_ENABLE_MONITOR( 0 );
  232. //
  233. // Write a default configuration to the FLASHCFG register.
  234. //
  235. AM_REG(CACHECTRL, FLASHCFG) = AM_REG_CACHECTRL_FLASHCFG_RD_WAIT(1);
  236. //
  237. // Write a default configuration to the CACHECTRL register.
  238. //
  239. AM_REG(CACHECTRL, CACHECTRL) = \
  240. AM_REG_CACHECTRL_CACHECTRL_FLASH1_SLM_ENABLE(1) | \
  241. AM_REG_CACHECTRL_CACHECTRL_FLASH1_SLM_DISABLE(0) | \
  242. AM_REG_CACHECTRL_CACHECTRL_FLASH0_SLM_ENABLE(1) | \
  243. AM_REG_CACHECTRL_CACHECTRL_FLASH0_SLM_DISABLE(0) | \
  244. AM_REG_CACHECTRL_CACHECTRL_RESET_STAT(0) | \
  245. AM_REG_CACHECTRL_CACHECTRL_INVALIDATE(0);
  246. //
  247. // Write a default configuration to the NCR0START and NCR0END registers.
  248. //
  249. AM_REG(CACHECTRL, NCR0START) = \
  250. AM_REG_CACHECTRL_NCR0START_ADDR(0);
  251. AM_REG(CACHECTRL, NCR0END) = \
  252. AM_REG_CACHECTRL_NCR0END_ADDR(0);
  253. //
  254. // Write a default configuration to the NCR1START and NCR1END registers.
  255. //
  256. AM_REG(CACHECTRL, NCR1START) = \
  257. AM_REG_CACHECTRL_NCR1START_ADDR(0);
  258. AM_REG(CACHECTRL, NCR1END) = \
  259. AM_REG_CACHECTRL_NCR1END_ADDR(0);
  260. //
  261. // Write a default configuration to the DMONn and IMONn registers.
  262. //
  263. AM_REG(CACHECTRL, DMON0) = \
  264. AM_REG_CACHECTRL_DMON0_DACCESS_COUNT(0);
  265. AM_REG(CACHECTRL, DMON1) = \
  266. AM_REG_CACHECTRL_DMON1_DLOOKUP_COUNT(0);
  267. AM_REG(CACHECTRL, DMON2) = \
  268. AM_REG_CACHECTRL_DMON2_DHIT_COUNT(0);
  269. AM_REG(CACHECTRL, DMON3) = \
  270. AM_REG_CACHECTRL_DMON3_DLINE_COUNT(0);
  271. AM_REG(CACHECTRL, IMON0) = \
  272. AM_REG_CACHECTRL_IMON0_IACCESS_COUNT(0);
  273. AM_REG(CACHECTRL, IMON1) = \
  274. AM_REG_CACHECTRL_IMON1_ILOOKUP_COUNT(0);
  275. AM_REG(CACHECTRL, IMON2) = \
  276. AM_REG_CACHECTRL_IMON2_IHIT_COUNT(0);
  277. AM_REG(CACHECTRL, IMON3) = \
  278. AM_REG_CACHECTRL_IMON3_ILINE_COUNT(0);
  279. }
  280. //*****************************************************************************
  281. //
  282. //! @brief Enable the flash cache controller via a configuration structure.
  283. //!
  284. //! @param psConfig - Pointer to a data structure containing all of the data
  285. // necessary to configure the CACHECFG register.
  286. //!
  287. //! This function is used to configure all fields of the CACHECFG.
  288. //
  289. //*****************************************************************************
  290. void
  291. am_hal_cachectrl_config(am_hal_cachectrl_config_t *psConfig)
  292. {
  293. uint32_t u32ConfigValue;
  294. //
  295. // Arrange all of the members of the data structure into a single u32 that
  296. // can be written to the register.
  297. //
  298. u32ConfigValue =
  299. AM_REG_CACHECTRL_CACHECFG_ENABLE( psConfig->ui32EnableCache ) |
  300. AM_REG_CACHECTRL_CACHECFG_LRU( psConfig->ui32LRU ) |
  301. AM_REG_CACHECTRL_CACHECFG_ENABLE_NC0(
  302. (psConfig->ui32EnableNCregions & 0x1) >> 0 ) |
  303. AM_REG_CACHECTRL_CACHECFG_ENABLE_NC1(
  304. (psConfig->ui32EnableNCregions & 0x2) >> 1 ) |
  305. psConfig->ui32Config |
  306. AM_REG_CACHECTRL_CACHECFG_SERIAL(psConfig->ui32SerialCacheMode) |
  307. AM_REG_CACHECTRL_CACHECFG_ICACHE_ENABLE(
  308. (psConfig->ui32FlashCachingEnables & 0x1) >> 0 ) |
  309. AM_REG_CACHECTRL_CACHECFG_DCACHE_ENABLE(
  310. (psConfig->ui32FlashCachingEnables & 0x2) >> 1 ) |
  311. AM_REG_CACHECTRL_CACHECFG_CACHE_CLKGATE(
  312. psConfig->ui32EnableCacheClockGating ) |
  313. AM_REG_CACHECTRL_CACHECFG_CACHE_LS(
  314. psConfig->ui32EnableLightSleep ) |
  315. AM_REG_CACHECTRL_CACHECFG_DLY( psConfig->ui32Dly ) |
  316. AM_REG_CACHECTRL_CACHECFG_SMDLY( psConfig->ui32SMDly ) |
  317. AM_REG_CACHECTRL_CACHECFG_DATA_CLKGATE(
  318. psConfig->ui32EnableDataClockGating ) |
  319. AM_REG_CACHECTRL_CACHECFG_ENABLE_MONITOR(
  320. psConfig->ui32EnableCacheMonitoring );
  321. //
  322. // Write the configuration value to the CACHECFG register.
  323. //
  324. AM_REG(CACHECTRL, CACHECFG) = u32ConfigValue;
  325. }
  326. //*****************************************************************************
  327. //
  328. //! @brief Configure the various flash cache controller enables.
  329. //!
  330. //! @param u32EnableMask - Mask of features to be enabled.
  331. //! @param u32DisableMask - Mask of features to be disabled.
  332. //!
  333. //! This function is used to enable or disable the various flash cache
  334. //! controller configuration enables which consist of the following:
  335. //! AM_HAL_CACHECTRL_CACHECFG_ENABLE Flash cache controller
  336. //! AM_HAL_CACHECTRL_CACHECFG_LRU_ENABLE LRU (disabled = LRR)
  337. //! AM_HAL_CACHECTRL_CACHECFG_NC0_ENABLE Non-cacheable region 0
  338. //! AM_HAL_CACHECTRL_CACHECFG_NC1_ENABLE Non-cacheable region 1
  339. //! AM_HAL_CACHECTRL_CACHECFG_SERIAL_ENABLE Serial cache mode
  340. //! AM_HAL_CACHECTRL_CACHECFG_ICACHE_ENABLE Instruction caching
  341. //! AM_HAL_CACHECTRL_CACHECFG_DCACHE_ENABLE Data caching.
  342. //! AM_HAL_CACHECTRL_CACHECFG_CACHE_CLKGATE_ENABLE Cache clock gating
  343. //! AM_HAL_CACHECTRL_CACHECFG_LS_ENABLE Light sleep cache RAMs
  344. //! AM_HAL_CACHECTRL_CACHECFG_DATA_CLKGATE_ENABLE Data clock gating
  345. //! AM_HAL_CACHECTRL_CACHECFG_MONITOR_ENABLE Cache Monitoring Stats
  346. //!
  347. //! Note that if both an enable and disable are provided in their respective
  348. //! masks, the enable will take precendence.
  349. //!
  350. //! @return The previous status of the flash cache controller enables.
  351. //
  352. //*****************************************************************************
  353. #define CACHECTRL_VALID_ENABLES ( \
  354. AM_REG_CACHECTRL_CACHECFG_ENABLE_M | \
  355. AM_REG_CACHECTRL_CACHECFG_LRU_M | \
  356. AM_REG_CACHECTRL_CACHECFG_ENABLE_NC0_M | \
  357. AM_REG_CACHECTRL_CACHECFG_ENABLE_NC1_M | \
  358. AM_REG_CACHECTRL_CACHECFG_SERIAL_M | \
  359. AM_REG_CACHECTRL_CACHECFG_ICACHE_ENABLE_M | \
  360. AM_REG_CACHECTRL_CACHECFG_DCACHE_ENABLE_M | \
  361. AM_REG_CACHECTRL_CACHECFG_CACHE_CLKGATE_M | \
  362. AM_REG_CACHECTRL_CACHECFG_CACHE_LS_M | \
  363. AM_REG_CACHECTRL_CACHECFG_DATA_CLKGATE_M | \
  364. AM_REG_CACHECTRL_CACHECFG_ENABLE_MONITOR_M )
  365. uint32_t
  366. am_hal_cachectrl_cache_enables(uint32_t u32EnableMask, uint32_t u32DisableMask)
  367. {
  368. uint32_t ui32RetVal = AM_BFR(CACHECTRL, CACHECFG, ENABLE) &
  369. CACHECTRL_VALID_ENABLES;
  370. //
  371. // Make sure the enable masks include only valid bits.
  372. //
  373. u32EnableMask &= CACHECTRL_VALID_ENABLES;
  374. u32DisableMask &= CACHECTRL_VALID_ENABLES;
  375. //
  376. // First, do the disables.
  377. //
  378. AM_REG(CACHECTRL, CACHECFG) &= ~u32DisableMask;
  379. //
  380. // Now set the enables.
  381. //
  382. AM_REG(CACHECTRL, CACHECFG) |= u32EnableMask;
  383. return ui32RetVal;
  384. }
  385. //*****************************************************************************
  386. //
  387. //! @brief Select the cache configuration type.
  388. //!
  389. //! This functions only sets the CACHECFG CONFIG field.
  390. //!
  391. //! @param ui32CacheConfig - The cache configuration value.
  392. //!
  393. //! This function can be used to select the type of cache.frequency of the main
  394. //! system clock. The ui32CacheConfig parameter should be set to one of the
  395. //! following values:
  396. //!
  397. //! AM_HAL_CACHECTRL_CACHECFG_CONFIG_DIRECT_256 : Direct mapped,
  398. //! 128-bit linesize, 256 entries (2 SRAMs active).
  399. //! AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_256 : Two-way set associative,
  400. //! 128-bit linesize, 256 entries (4 SRAMs active).
  401. //! AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512 : Two-way set associative,
  402. //! 128-bit linesize, 512 entries (8 SRAMs active).
  403. //!
  404. //! @return None.
  405. //
  406. //*****************************************************************************
  407. void
  408. am_hal_cachectrl_cache_config(uint32_t ui32CacheConfig)
  409. {
  410. //
  411. // Clear the bitfield
  412. //
  413. AM_REG(CACHECTRL, CACHECFG) &= ~AM_REG_CACHECTRL_CACHECFG_CONFIG_M;
  414. //
  415. // Write the new value to the bitfield.
  416. //
  417. AM_REG(CACHECTRL, CACHECFG) |= ui32CacheConfig &
  418. AM_REG_CACHECTRL_CACHECFG_CONFIG_M;
  419. }
  420. //*****************************************************************************
  421. //
  422. //! @brief Invalidate the flash cache.
  423. //!
  424. //! This function is used to invalidate the flash cache.
  425. //!
  426. //! @return None.
  427. //
  428. //*****************************************************************************
  429. void
  430. am_hal_cachectrl_invalidate_flash_cache(void)
  431. {
  432. //
  433. // Write the bit to invalidate the flash cache.
  434. // Note - this bit is not sticky, no need to write it back to 0.
  435. //
  436. AM_REG(CACHECTRL, CACHECTRL) |= AM_REG_CACHECTRL_CACHECTRL_INVALIDATE_GO;
  437. }
  438. //*****************************************************************************
  439. //
  440. //! @brief Reset cache statistics.
  441. //!
  442. //! This function is used to reset cache statistics.
  443. //!
  444. //! @return None.
  445. //
  446. //*****************************************************************************
  447. void
  448. am_hal_cachectrl_reset_statistics(void)
  449. {
  450. //
  451. // Write the bit to reset flash statistics.
  452. // Note - this bit is not sticky, no need to write it back to 0.
  453. //
  454. AM_REG(CACHECTRL, CACHECTRL) |= AM_REG_CACHECTRL_CACHECTRL_RESET_STAT_CLEAR;
  455. }
  456. //*****************************************************************************
  457. //
  458. //! @brief Get flash cache sleep mode status.
  459. //!
  460. //! This function returns flash cache sleep mode statuses.
  461. //!
  462. //! @return
  463. //! bit0 indicates that flash0 flash sleep mode is enabled.
  464. //! bit1 indicates that flash1 flash sleep mode is enabled.
  465. //
  466. //*****************************************************************************
  467. uint32_t
  468. am_hal_cachectrl_sleep_mode_status(void)
  469. {
  470. uint32_t ui32Status, ui32Ret;
  471. //
  472. // Get the current sleep mode status bits.
  473. //
  474. ui32Status = AM_REG(CACHECTRL, CACHECTRL);
  475. ui32Ret = (ui32Status & \
  476. AM_REG_CACHECTRL_CACHECTRL_FLASH0_SLM_STATUS_M) >> \
  477. (AM_REG_CACHECTRL_CACHECTRL_FLASH0_SLM_STATUS_S - 0);
  478. ui32Ret |= (ui32Status & \
  479. AM_REG_CACHECTRL_CACHECTRL_FLASH1_SLM_STATUS_M) >> \
  480. (AM_REG_CACHECTRL_CACHECTRL_FLASH1_SLM_STATUS_S - 1);
  481. return ui32Ret;
  482. }
  483. //*****************************************************************************
  484. //
  485. //! @brief Enable or disable flash cache sleep mode.
  486. //!
  487. //! This function enables or disables flash cache sleep mode.
  488. //! @param ui32EnableMask - bit0 for flash0, bit1 for flash1.
  489. //! @param ui32DisableMask - bit0 for flash0, bit1 for flash1.
  490. //!
  491. //! Note that if both an enable and disable are provided in their respective
  492. //! masks, the enable will take precedence.
  493. //!
  494. //! @return Previous status.
  495. //! bit0 indicates that flash0 flash sleep mode was previously enabled.
  496. //! bit1 indicates that flash1 flash sleep mode was previously enabled.
  497. //
  498. //*****************************************************************************
  499. uint32_t
  500. am_hal_cachectrl_sleep_mode_enable(uint32_t ui32EnableMask,
  501. uint32_t ui32DisableMask)
  502. {
  503. uint32_t ui32Ret = am_hal_cachectrl_sleep_mode_status();
  504. if ( ui32DisableMask & 0x1 )
  505. {
  506. AM_REG(CACHECTRL, CACHECTRL) |= AM_REG_CACHECTRL_CACHECTRL_FLASH0_SLM_DISABLE_M;
  507. }
  508. if ( ui32DisableMask & 0x2 )
  509. {
  510. AM_REG(CACHECTRL, CACHECTRL) |= AM_REG_CACHECTRL_CACHECTRL_FLASH1_SLM_DISABLE_M;
  511. }
  512. if ( ui32EnableMask & 0x1 )
  513. {
  514. AM_REG(CACHECTRL, CACHECTRL) |= AM_REG_CACHECTRL_CACHECTRL_FLASH0_SLM_ENABLE_M;
  515. }
  516. if ( ui32EnableMask & 0x2 )
  517. {
  518. AM_REG(CACHECTRL, CACHECTRL) |= AM_REG_CACHECTRL_CACHECTRL_FLASH1_SLM_ENABLE_M;
  519. }
  520. return ui32Ret;
  521. }
  522. //*****************************************************************************
  523. //
  524. // End Doxygen group.
  525. //! @}
  526. //
  527. //*****************************************************************************