fsl_cache.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*
  2. * Copyright 2016-2021 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include "fsl_cache.h"
  8. /*******************************************************************************
  9. * Definitions
  10. ******************************************************************************/
  11. /* Component ID definition, used by tools. */
  12. #ifndef FSL_COMPONENT_ID
  13. #define FSL_COMPONENT_ID "platform.drivers.cache_lmem"
  14. #endif
  15. #define L1CACHE_ONEWAYSIZE_BYTE (4096U) /*!< Cache size is 4K-bytes one way. */
  16. #define L1CACHE_CODEBUSADDR_BOUNDARY (0x1FFFFFFFU) /*!< The processor code bus address boundary. */
  17. /*******************************************************************************
  18. * Code
  19. ******************************************************************************/
  20. #if (FSL_FEATURE_SOC_LMEM_COUNT == 1)
  21. /*!
  22. * brief Enables the processor code bus cache.
  23. *
  24. */
  25. void L1CACHE_EnableCodeCache(void)
  26. {
  27. if (0U == (LMEM->PCCCR & LMEM_PCCCR_ENCACHE_MASK))
  28. {
  29. /* First, invalidate the entire cache. */
  30. L1CACHE_InvalidateCodeCache();
  31. /* Now enable the cache. */
  32. LMEM->PCCCR |= LMEM_PCCCR_ENCACHE_MASK;
  33. }
  34. }
  35. /*!
  36. * brief Disables the processor code bus cache.
  37. *
  38. */
  39. void L1CACHE_DisableCodeCache(void)
  40. {
  41. /* First, push any modified contents. */
  42. L1CACHE_CleanCodeCache();
  43. /* Now disable the cache. */
  44. LMEM->PCCCR &= ~LMEM_PCCCR_ENCACHE_MASK;
  45. }
  46. /*!
  47. * brief Invalidates the processor code bus cache.
  48. *
  49. */
  50. void L1CACHE_InvalidateCodeCache(void)
  51. {
  52. /* Enables the processor code bus to invalidate all lines in both ways.
  53. and Initiate the processor code bus code cache command. */
  54. LMEM->PCCCR |= LMEM_PCCCR_INVW0_MASK | LMEM_PCCCR_INVW1_MASK | LMEM_PCCCR_GO_MASK;
  55. /* Wait until the cache command completes. */
  56. while ((LMEM->PCCCR & LMEM_PCCCR_GO_MASK) != 0U)
  57. {
  58. }
  59. /* As a precaution clear the bits to avoid inadvertently re-running this command. */
  60. LMEM->PCCCR &= ~(LMEM_PCCCR_INVW0_MASK | LMEM_PCCCR_INVW1_MASK);
  61. }
  62. /*!
  63. * brief Invalidates processor code bus cache by range.
  64. *
  65. * param address The physical address of cache.
  66. * param size_byte size of the memory to be invalidated.
  67. * note Address and size should be aligned to "L1CODCACHE_LINESIZE_BYTE".
  68. * The startAddr here will be forced to align to L1CODEBUSCACHE_LINESIZE_BYTE if
  69. * startAddr is not aligned. For the size_byte, application should make sure the
  70. * alignment or make sure the right operation order if the size_byte is not aligned.
  71. */
  72. void L1CACHE_InvalidateCodeCacheByRange(uint32_t address, uint32_t size_byte)
  73. {
  74. uint32_t endAddr = address + size_byte;
  75. uint32_t pccReg = 0;
  76. /* Align address to cache line size. */
  77. uint32_t startAddr = address & ~((uint32_t)L1CODEBUSCACHE_LINESIZE_BYTE - 1U);
  78. /* Set the invalidate by line command and use the physical address. */
  79. pccReg = (LMEM->PCCLCR & ~LMEM_PCCLCR_LCMD_MASK) | LMEM_PCCLCR_LCMD(1) | LMEM_PCCLCR_LADSEL_MASK;
  80. LMEM->PCCLCR = pccReg;
  81. while (startAddr < endAddr)
  82. {
  83. /* Set the address and initiate the command. */
  84. LMEM->PCCSAR = (startAddr & LMEM_PCCSAR_PHYADDR_MASK) | LMEM_PCCSAR_LGO_MASK;
  85. /* Wait until the cache command completes. */
  86. while ((LMEM->PCCSAR & LMEM_PCCSAR_LGO_MASK) != 0U)
  87. {
  88. }
  89. startAddr += (uint32_t)L1CODEBUSCACHE_LINESIZE_BYTE;
  90. }
  91. }
  92. /*!
  93. * brief Cleans the processor code bus cache.
  94. *
  95. */
  96. void L1CACHE_CleanCodeCache(void)
  97. {
  98. /* Enable the processor code bus to push all modified lines. */
  99. LMEM->PCCCR |= LMEM_PCCCR_PUSHW0_MASK | LMEM_PCCCR_PUSHW1_MASK | LMEM_PCCCR_GO_MASK;
  100. /* Wait until the cache command completes. */
  101. while ((LMEM->PCCCR & LMEM_PCCCR_GO_MASK) != 0U)
  102. {
  103. }
  104. /* As a precaution clear the bits to avoid inadvertently re-running this command. */
  105. LMEM->PCCCR &= ~(LMEM_PCCCR_PUSHW0_MASK | LMEM_PCCCR_PUSHW1_MASK);
  106. }
  107. /*!
  108. * brief Cleans processor code bus cache by range.
  109. *
  110. * param address The physical address of cache.
  111. * param size_byte size of the memory to be cleaned.
  112. * note Address and size should be aligned to "L1CODEBUSCACHE_LINESIZE_BYTE".
  113. * The startAddr here will be forced to align to L1CODEBUSCACHE_LINESIZE_BYTE if
  114. * startAddr is not aligned. For the size_byte, application should make sure the
  115. * alignment or make sure the right operation order if the size_byte is not aligned.
  116. */
  117. void L1CACHE_CleanCodeCacheByRange(uint32_t address, uint32_t size_byte)
  118. {
  119. uint32_t endAddr = address + size_byte;
  120. uint32_t pccReg = 0;
  121. /* Align address to cache line size. */
  122. uint32_t startAddr = address & ~((uint32_t)L1CODEBUSCACHE_LINESIZE_BYTE - 1U);
  123. /* Set the push by line command. */
  124. pccReg = (LMEM->PCCLCR & ~LMEM_PCCLCR_LCMD_MASK) | LMEM_PCCLCR_LCMD(2) | LMEM_PCCLCR_LADSEL_MASK;
  125. LMEM->PCCLCR = pccReg;
  126. while (startAddr < endAddr)
  127. {
  128. /* Set the address and initiate the command. */
  129. LMEM->PCCSAR = (startAddr & LMEM_PCCSAR_PHYADDR_MASK) | LMEM_PCCSAR_LGO_MASK;
  130. /* Wait until the cache command completes. */
  131. while ((LMEM->PCCSAR & LMEM_PCCSAR_LGO_MASK) != 0U)
  132. {
  133. }
  134. startAddr += (uint32_t)L1CODEBUSCACHE_LINESIZE_BYTE;
  135. }
  136. }
  137. /*!
  138. * brief Cleans and invalidates the processor code bus cache.
  139. *
  140. */
  141. void L1CACHE_CleanInvalidateCodeCache(void)
  142. {
  143. /* Push and invalidate all. */
  144. LMEM->PCCCR |= LMEM_PCCCR_PUSHW0_MASK | LMEM_PCCCR_PUSHW1_MASK | LMEM_PCCCR_INVW0_MASK | LMEM_PCCCR_INVW1_MASK |
  145. LMEM_PCCCR_GO_MASK;
  146. /* Wait until the cache command completes. */
  147. while ((LMEM->PCCCR & LMEM_PCCCR_GO_MASK) != 0U)
  148. {
  149. }
  150. /* As a precaution clear the bits to avoid inadvertently re-running this command. */
  151. LMEM->PCCCR &= ~(LMEM_PCCCR_PUSHW0_MASK | LMEM_PCCCR_PUSHW1_MASK | LMEM_PCCCR_INVW0_MASK | LMEM_PCCCR_INVW1_MASK);
  152. }
  153. /*!
  154. * brief Cleans and invalidate processor code bus cache by range.
  155. *
  156. * param address The physical address of cache.
  157. * param size_byte size of the memory to be Cleaned and Invalidated.
  158. * note Address and size should be aligned to "L1CODEBUSCACHE_LINESIZE_BYTE".
  159. * The startAddr here will be forced to align to L1CODEBUSCACHE_LINESIZE_BYTE if
  160. * startAddr is not aligned. For the size_byte, application should make sure the
  161. * alignment or make sure the right operation order if the size_byte is not aligned.
  162. */
  163. void L1CACHE_CleanInvalidateCodeCacheByRange(uint32_t address, uint32_t size_byte)
  164. {
  165. uint32_t endAddr = address + size_byte;
  166. uint32_t pccReg = 0;
  167. /* Align address to cache line size. */
  168. uint32_t startAddr = address & ~((uint32_t)L1CODEBUSCACHE_LINESIZE_BYTE - 1U);
  169. /* Set the push by line command. */
  170. pccReg = (LMEM->PCCLCR & ~LMEM_PCCLCR_LCMD_MASK) | LMEM_PCCLCR_LCMD(3) | LMEM_PCCLCR_LADSEL_MASK;
  171. LMEM->PCCLCR = pccReg;
  172. while (startAddr < endAddr)
  173. {
  174. /* Set the address and initiate the command. */
  175. LMEM->PCCSAR = (startAddr & LMEM_PCCSAR_PHYADDR_MASK) | LMEM_PCCSAR_LGO_MASK;
  176. /* Wait until the cache command completes. */
  177. while ((LMEM->PCCSAR & LMEM_PCCSAR_LGO_MASK) != 0U)
  178. {
  179. }
  180. startAddr += (uint32_t)L1CODEBUSCACHE_LINESIZE_BYTE;
  181. }
  182. }
  183. #if defined(FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE) && FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE
  184. /*!
  185. * brief Enables the processor system bus cache.
  186. *
  187. */
  188. void L1CACHE_EnableSystemCache(void)
  189. {
  190. /* Only enable when not enabled. */
  191. if (0U == (LMEM->PSCCR & LMEM_PSCCR_ENCACHE_MASK))
  192. {
  193. /* First, invalidate the entire cache. */
  194. L1CACHE_InvalidateSystemCache();
  195. /* Now enable the cache. */
  196. LMEM->PSCCR |= LMEM_PSCCR_ENCACHE_MASK;
  197. }
  198. }
  199. /*!
  200. * brief Disables the processor system bus cache.
  201. *
  202. */
  203. void L1CACHE_DisableSystemCache(void)
  204. {
  205. /* First, push any modified contents. */
  206. L1CACHE_CleanSystemCache();
  207. /* Now disable the cache. */
  208. LMEM->PSCCR &= ~LMEM_PSCCR_ENCACHE_MASK;
  209. }
  210. /*!
  211. * brief Invalidates the processor system bus cache.
  212. *
  213. */
  214. void L1CACHE_InvalidateSystemCache(void)
  215. {
  216. /* Enables the processor system bus to invalidate all lines in both ways.
  217. and Initiate the processor system bus cache command. */
  218. LMEM->PSCCR |= LMEM_PSCCR_INVW0_MASK | LMEM_PSCCR_INVW1_MASK | LMEM_PSCCR_GO_MASK;
  219. /* Wait until the cache command completes */
  220. while ((LMEM->PSCCR & LMEM_PSCCR_GO_MASK) != 0U)
  221. {
  222. }
  223. /* As a precaution clear the bits to avoid inadvertently re-running this command. */
  224. LMEM->PSCCR &= ~(LMEM_PSCCR_INVW0_MASK | LMEM_PSCCR_INVW1_MASK);
  225. }
  226. /*!
  227. * brief Invalidates processor system bus cache by range.
  228. *
  229. * param address The physical address of cache.
  230. * param size_byte size of the memory to be invalidated.
  231. * note Address and size should be aligned to "L1SYSTEMBUSCACHE_LINESIZE_BYTE".
  232. * The startAddr here will be forced to align to L1SYSTEMBUSCACHE_LINESIZE_BYTE if
  233. * startAddr is not aligned. For the size_byte, application should make sure the
  234. * alignment or make sure the right operation order if the size_byte is not aligned.
  235. */
  236. void L1CACHE_InvalidateSystemCacheByRange(uint32_t address, uint32_t size_byte)
  237. {
  238. uint32_t endAddr = address + size_byte;
  239. uint32_t pscReg = 0;
  240. uint32_t startAddr =
  241. address & ~((uint32_t)L1SYSTEMBUSCACHE_LINESIZE_BYTE - 1U); /* Align address to cache line size */
  242. /* Set the invalidate by line command and use the physical address. */
  243. pscReg = (LMEM->PSCLCR & ~LMEM_PSCLCR_LCMD_MASK) | LMEM_PSCLCR_LCMD(1) | LMEM_PSCLCR_LADSEL_MASK;
  244. LMEM->PSCLCR = pscReg;
  245. while (startAddr < endAddr)
  246. {
  247. /* Set the address and initiate the command. */
  248. LMEM->PSCSAR = (startAddr & LMEM_PSCSAR_PHYADDR_MASK) | LMEM_PSCSAR_LGO_MASK;
  249. /* Wait until the cache command completes. */
  250. while ((LMEM->PSCSAR & LMEM_PSCSAR_LGO_MASK) != 0U)
  251. {
  252. }
  253. startAddr += (uint32_t)L1SYSTEMBUSCACHE_LINESIZE_BYTE;
  254. }
  255. }
  256. /*!
  257. * brief Cleans the processor system bus cache.
  258. *
  259. */
  260. void L1CACHE_CleanSystemCache(void)
  261. {
  262. /* Enable the processor system bus to push all modified lines. */
  263. LMEM->PSCCR |= LMEM_PSCCR_PUSHW0_MASK | LMEM_PSCCR_PUSHW1_MASK | LMEM_PSCCR_GO_MASK;
  264. /* Wait until the cache command completes. */
  265. while ((LMEM->PSCCR & LMEM_PSCCR_GO_MASK) != 0U)
  266. {
  267. }
  268. /* As a precaution clear the bits to avoid inadvertently re-running this command. */
  269. LMEM->PSCCR &= ~(LMEM_PSCCR_PUSHW0_MASK | LMEM_PSCCR_PUSHW1_MASK);
  270. }
  271. /*!
  272. * brief Cleans processor system bus cache by range.
  273. *
  274. * param address The physical address of cache.
  275. * param size_byte size of the memory to be cleaned.
  276. * note Address and size should be aligned to "L1SYSTEMBUSCACHE_LINESIZE_BYTE".
  277. * The startAddr here will be forced to align to L1SYSTEMBUSCACHE_LINESIZE_BYTE if
  278. * startAddr is not aligned. For the size_byte, application should make sure the
  279. * alignment or make sure the right operation order if the size_byte is not aligned.
  280. */
  281. void L1CACHE_CleanSystemCacheByRange(uint32_t address, uint32_t size_byte)
  282. {
  283. uint32_t endAddr = address + size_byte;
  284. uint32_t pscReg = 0;
  285. uint32_t startAddr =
  286. address & ~((uint32_t)L1SYSTEMBUSCACHE_LINESIZE_BYTE - 1U); /* Align address to cache line size. */
  287. /* Set the push by line command. */
  288. pscReg = (LMEM->PSCLCR & ~LMEM_PSCLCR_LCMD_MASK) | LMEM_PSCLCR_LCMD(2) | LMEM_PSCLCR_LADSEL_MASK;
  289. LMEM->PSCLCR = pscReg;
  290. while (startAddr < endAddr)
  291. {
  292. /* Set the address and initiate the command. */
  293. LMEM->PSCSAR = (startAddr & LMEM_PSCSAR_PHYADDR_MASK) | LMEM_PSCSAR_LGO_MASK;
  294. /* Wait until the cache command completes. */
  295. while ((LMEM->PSCSAR & LMEM_PSCSAR_LGO_MASK) != 0U)
  296. {
  297. }
  298. startAddr += (uint32_t)L1SYSTEMBUSCACHE_LINESIZE_BYTE;
  299. }
  300. }
  301. /*!
  302. * brief Cleans and invalidates the processor system bus cache.
  303. *
  304. */
  305. void L1CACHE_CleanInvalidateSystemCache(void)
  306. {
  307. /* Push and invalidate all. */
  308. LMEM->PSCCR |= LMEM_PSCCR_PUSHW0_MASK | LMEM_PSCCR_PUSHW1_MASK | LMEM_PSCCR_INVW0_MASK | LMEM_PSCCR_INVW1_MASK |
  309. LMEM_PSCCR_GO_MASK;
  310. /* Wait until the cache command completes. */
  311. while ((LMEM->PSCCR & LMEM_PSCCR_GO_MASK) != 0U)
  312. {
  313. }
  314. /* As a precaution clear the bits to avoid inadvertently re-running this command. */
  315. LMEM->PSCCR &= ~(LMEM_PSCCR_PUSHW0_MASK | LMEM_PSCCR_PUSHW1_MASK | LMEM_PSCCR_INVW0_MASK | LMEM_PSCCR_INVW1_MASK);
  316. }
  317. /*!
  318. * brief Cleans and Invalidates processor system bus cache by range.
  319. *
  320. * param address The physical address of cache.
  321. * param size_byte size of the memory to be Clean and Invalidated.
  322. * note Address and size should be aligned to "L1SYSTEMBUSCACHE_LINESIZE_BYTE".
  323. * The startAddr here will be forced to align to L1SYSTEMBUSCACHE_LINESIZE_BYTE if
  324. * startAddr is not aligned. For the size_byte, application should make sure the
  325. * alignment or make sure the right operation order if the size_byte is not aligned.
  326. */
  327. void L1CACHE_CleanInvalidateSystemCacheByRange(uint32_t address, uint32_t size_byte)
  328. {
  329. uint32_t endAddr = address + size_byte;
  330. uint32_t pscReg = 0;
  331. uint32_t startAddr =
  332. address & ~((uint32_t)L1SYSTEMBUSCACHE_LINESIZE_BYTE - 1U); /* Align address to cache line size. */
  333. /* Set the push by line command. */
  334. pscReg = (LMEM->PSCLCR & ~LMEM_PSCLCR_LCMD_MASK) | LMEM_PSCLCR_LCMD(3) | LMEM_PSCLCR_LADSEL_MASK;
  335. LMEM->PSCLCR = pscReg;
  336. while (startAddr < endAddr)
  337. {
  338. /* Set the address and initiate the command. */
  339. LMEM->PSCSAR = (startAddr & LMEM_PSCSAR_PHYADDR_MASK) | LMEM_PSCSAR_LGO_MASK;
  340. /* Wait until the cache command completes. */
  341. while ((LMEM->PSCSAR & LMEM_PSCSAR_LGO_MASK) != 0U)
  342. {
  343. }
  344. startAddr += (uint32_t)L1SYSTEMBUSCACHE_LINESIZE_BYTE;
  345. }
  346. }
  347. #endif /* FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE */
  348. #endif /* FSL_FEATURE_SOC_LMEM_COUNT == 1 */
  349. /*!
  350. * brief Invalidates cortex-m4 L1 instrument cache by range.
  351. *
  352. * param address The start address of the memory to be invalidated.
  353. * param size_byte The memory size.
  354. * note The start address and size_byte should be 16-Byte(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE) aligned.
  355. */
  356. void L1CACHE_InvalidateICacheByRange(uint32_t address, uint32_t size_byte)
  357. {
  358. #if (FSL_FEATURE_SOC_LMEM_COUNT == 1)
  359. uint32_t endAddr = address + size_byte;
  360. uint32_t size = size_byte;
  361. if (endAddr <= L1CACHE_CODEBUSADDR_BOUNDARY)
  362. {
  363. L1CACHE_InvalidateCodeCacheByRange(address, size);
  364. }
  365. else if (address <= L1CACHE_CODEBUSADDR_BOUNDARY)
  366. {
  367. size = L1CACHE_CODEBUSADDR_BOUNDARY - address;
  368. L1CACHE_InvalidateCodeCacheByRange(address, size);
  369. #if defined(FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE) && FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE
  370. size = size_byte - size;
  371. L1CACHE_InvalidateSystemCacheByRange((L1CACHE_CODEBUSADDR_BOUNDARY + 1U), size);
  372. #endif /* FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE */
  373. }
  374. else
  375. {
  376. #if defined(FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE) && FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE
  377. L1CACHE_InvalidateSystemCacheByRange(address, size);
  378. #endif /* FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE */
  379. }
  380. #endif /* FSL_FEATURE_SOC_LMEM_COUNT == 1 */
  381. }
  382. /*!
  383. * brief Cleans cortex-m4 L1 data cache by range.
  384. *
  385. * param address The start address of the memory to be cleaned.
  386. * param size_byte The memory size.
  387. * note The start address and size_byte should be 16-Byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned.
  388. */
  389. void L1CACHE_CleanDCacheByRange(uint32_t address, uint32_t size_byte)
  390. {
  391. #if (FSL_FEATURE_SOC_LMEM_COUNT == 1)
  392. uint32_t endAddr = address + size_byte;
  393. uint32_t size = size_byte;
  394. if (endAddr <= L1CACHE_CODEBUSADDR_BOUNDARY)
  395. {
  396. L1CACHE_CleanCodeCacheByRange(address, size);
  397. }
  398. else if (address <= L1CACHE_CODEBUSADDR_BOUNDARY)
  399. {
  400. size = L1CACHE_CODEBUSADDR_BOUNDARY - address;
  401. L1CACHE_CleanCodeCacheByRange(address, size);
  402. #if defined(FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE) && FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE
  403. size = size_byte - size;
  404. L1CACHE_CleanSystemCacheByRange((L1CACHE_CODEBUSADDR_BOUNDARY + 1U), size);
  405. #endif /* FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE */
  406. }
  407. else
  408. {
  409. #if defined(FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE) && FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE
  410. L1CACHE_CleanSystemCacheByRange(address, size);
  411. #endif /* FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE */
  412. }
  413. #endif /* FSL_FEATURE_SOC_LMEM_COUNT == 1 */
  414. }
  415. /*!
  416. * brief Cleans and Invalidates cortex-m4 L1 data cache by range.
  417. *
  418. * param address The start address of the memory to be clean and invalidated.
  419. * param size_byte The memory size.
  420. * note The start address and size_byte should be 16-Byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned.
  421. */
  422. void L1CACHE_CleanInvalidateDCacheByRange(uint32_t address, uint32_t size_byte)
  423. {
  424. #if (FSL_FEATURE_SOC_LMEM_COUNT == 1)
  425. uint32_t endAddr = address + size_byte;
  426. uint32_t size = size_byte;
  427. if (endAddr <= L1CACHE_CODEBUSADDR_BOUNDARY)
  428. {
  429. L1CACHE_CleanInvalidateCodeCacheByRange(address, size);
  430. }
  431. else if (address <= L1CACHE_CODEBUSADDR_BOUNDARY)
  432. {
  433. size = L1CACHE_CODEBUSADDR_BOUNDARY - address;
  434. L1CACHE_CleanInvalidateCodeCacheByRange(address, size);
  435. #if defined(FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE) && FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE
  436. size = size_byte - size;
  437. L1CACHE_CleanInvalidateSystemCacheByRange((L1CACHE_CODEBUSADDR_BOUNDARY + 1U), size);
  438. #endif /* FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE */
  439. }
  440. else
  441. {
  442. #if defined(FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE) && FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE
  443. L1CACHE_CleanInvalidateSystemCacheByRange(address, size);
  444. #endif /* FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE */
  445. }
  446. #endif /* FSL_FEATURE_SOC_LMEM_COUNT == 1 */
  447. }