cmsis_cp15.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /**************************************************************************//**
  2. * @file cmsis_cp15.h
  3. * @brief CMSIS compiler specific macros, functions, instructions
  4. * @version V1.0.1
  5. * @date 07. Sep 2017
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2017 ARM Limited. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #if defined ( __ICCARM__ )
  25. #pragma system_include /* treat file as system include file for MISRA check */
  26. #elif defined (__clang__)
  27. #pragma clang system_header /* treat file as system include file */
  28. #endif
  29. #ifndef __CMSIS_CP15_H
  30. #define __CMSIS_CP15_H
  31. /** \brief Get ACTLR
  32. \return Auxiliary Control register value
  33. */
  34. __STATIC_FORCEINLINE uint32_t __get_ACTLR(void)
  35. {
  36. uint32_t result;
  37. __get_CP(15, 0, result, 1, 0, 1);
  38. return(result);
  39. }
  40. /** \brief Set ACTLR
  41. \param [in] actlr Auxiliary Control value to set
  42. */
  43. __STATIC_FORCEINLINE void __set_ACTLR(uint32_t actlr)
  44. {
  45. __set_CP(15, 0, actlr, 1, 0, 1);
  46. }
  47. /** \brief Get CPACR
  48. \return Coprocessor Access Control register value
  49. */
  50. __STATIC_FORCEINLINE uint32_t __get_CPACR(void)
  51. {
  52. uint32_t result;
  53. __get_CP(15, 0, result, 1, 0, 2);
  54. return result;
  55. }
  56. /** \brief Set CPACR
  57. \param [in] cpacr Coprocessor Access Control value to set
  58. */
  59. __STATIC_FORCEINLINE void __set_CPACR(uint32_t cpacr)
  60. {
  61. __set_CP(15, 0, cpacr, 1, 0, 2);
  62. }
  63. /** \brief Get DFSR
  64. \return Data Fault Status Register value
  65. */
  66. __STATIC_FORCEINLINE uint32_t __get_DFSR(void)
  67. {
  68. uint32_t result;
  69. __get_CP(15, 0, result, 5, 0, 0);
  70. return result;
  71. }
  72. /** \brief Set DFSR
  73. \param [in] dfsr Data Fault Status value to set
  74. */
  75. __STATIC_FORCEINLINE void __set_DFSR(uint32_t dfsr)
  76. {
  77. __set_CP(15, 0, dfsr, 5, 0, 0);
  78. }
  79. /** \brief Get IFSR
  80. \return Instruction Fault Status Register value
  81. */
  82. __STATIC_FORCEINLINE uint32_t __get_IFSR(void)
  83. {
  84. uint32_t result;
  85. __get_CP(15, 0, result, 5, 0, 1);
  86. return result;
  87. }
  88. /** \brief Set IFSR
  89. \param [in] ifsr Instruction Fault Status value to set
  90. */
  91. __STATIC_FORCEINLINE void __set_IFSR(uint32_t ifsr)
  92. {
  93. __set_CP(15, 0, ifsr, 5, 0, 1);
  94. }
  95. /** \brief Get ISR
  96. \return Interrupt Status Register value
  97. */
  98. __STATIC_FORCEINLINE uint32_t __get_ISR(void)
  99. {
  100. uint32_t result;
  101. __get_CP(15, 0, result, 12, 1, 0);
  102. return result;
  103. }
  104. /** \brief Get CBAR
  105. \return Configuration Base Address register value
  106. */
  107. __STATIC_FORCEINLINE uint32_t __get_CBAR(void)
  108. {
  109. uint32_t result;
  110. __get_CP(15, 4, result, 15, 0, 0);
  111. return result;
  112. }
  113. /** \brief Get TTBR0
  114. This function returns the value of the Translation Table Base Register 0.
  115. \return Translation Table Base Register 0 value
  116. */
  117. __STATIC_FORCEINLINE uint32_t __get_TTBR0(void)
  118. {
  119. uint32_t result;
  120. __get_CP(15, 0, result, 2, 0, 0);
  121. return result;
  122. }
  123. /** \brief Set TTBR0
  124. This function assigns the given value to the Translation Table Base Register 0.
  125. \param [in] ttbr0 Translation Table Base Register 0 value to set
  126. */
  127. __STATIC_FORCEINLINE void __set_TTBR0(uint32_t ttbr0)
  128. {
  129. __set_CP(15, 0, ttbr0, 2, 0, 0);
  130. }
  131. /** \brief Get DACR
  132. This function returns the value of the Domain Access Control Register.
  133. \return Domain Access Control Register value
  134. */
  135. __STATIC_FORCEINLINE uint32_t __get_DACR(void)
  136. {
  137. uint32_t result;
  138. __get_CP(15, 0, result, 3, 0, 0);
  139. return result;
  140. }
  141. /** \brief Set DACR
  142. This function assigns the given value to the Domain Access Control Register.
  143. \param [in] dacr Domain Access Control Register value to set
  144. */
  145. __STATIC_FORCEINLINE void __set_DACR(uint32_t dacr)
  146. {
  147. __set_CP(15, 0, dacr, 3, 0, 0);
  148. }
  149. /** \brief Set SCTLR
  150. This function assigns the given value to the System Control Register.
  151. \param [in] sctlr System Control Register value to set
  152. */
  153. __STATIC_FORCEINLINE void __set_SCTLR(uint32_t sctlr)
  154. {
  155. __set_CP(15, 0, sctlr, 1, 0, 0);
  156. }
  157. /** \brief Get SCTLR
  158. \return System Control Register value
  159. */
  160. __STATIC_FORCEINLINE uint32_t __get_SCTLR(void)
  161. {
  162. uint32_t result;
  163. __get_CP(15, 0, result, 1, 0, 0);
  164. return result;
  165. }
  166. /** \brief Set ACTRL
  167. \param [in] actrl Auxiliary Control Register value to set
  168. */
  169. __STATIC_FORCEINLINE void __set_ACTRL(uint32_t actrl)
  170. {
  171. __set_CP(15, 0, actrl, 1, 0, 1);
  172. }
  173. /** \brief Get ACTRL
  174. \return Auxiliary Control Register value
  175. */
  176. __STATIC_FORCEINLINE uint32_t __get_ACTRL(void)
  177. {
  178. uint32_t result;
  179. __get_CP(15, 0, result, 1, 0, 1);
  180. return result;
  181. }
  182. /** \brief Get MPIDR
  183. This function returns the value of the Multiprocessor Affinity Register.
  184. \return Multiprocessor Affinity Register value
  185. */
  186. __STATIC_FORCEINLINE uint32_t __get_MPIDR(void)
  187. {
  188. uint32_t result;
  189. __get_CP(15, 0, result, 0, 0, 5);
  190. return result;
  191. }
  192. /** \brief Get VBAR
  193. This function returns the value of the Vector Base Address Register.
  194. \return Vector Base Address Register
  195. */
  196. __STATIC_FORCEINLINE uint32_t __get_VBAR(void)
  197. {
  198. uint32_t result;
  199. __get_CP(15, 0, result, 12, 0, 0);
  200. return result;
  201. }
  202. /** \brief Set VBAR
  203. This function assigns the given value to the Vector Base Address Register.
  204. \param [in] vbar Vector Base Address Register value to set
  205. */
  206. __STATIC_FORCEINLINE void __set_VBAR(uint32_t vbar)
  207. {
  208. __set_CP(15, 0, vbar, 12, 0, 0);
  209. }
  210. /** \brief Get MVBAR
  211. This function returns the value of the Monitor Vector Base Address Register.
  212. \return Monitor Vector Base Address Register
  213. */
  214. __STATIC_FORCEINLINE uint32_t __get_MVBAR(void)
  215. {
  216. uint32_t result;
  217. __get_CP(15, 0, result, 12, 0, 1);
  218. return result;
  219. }
  220. /** \brief Set MVBAR
  221. This function assigns the given value to the Monitor Vector Base Address Register.
  222. \param [in] mvbar Monitor Vector Base Address Register value to set
  223. */
  224. __STATIC_FORCEINLINE void __set_MVBAR(uint32_t mvbar)
  225. {
  226. __set_CP(15, 0, mvbar, 12, 0, 1);
  227. }
  228. #if (defined(__CORTEX_A) && (__CORTEX_A == 7U) && \
  229. defined(__TIM_PRESENT) && (__TIM_PRESENT == 1U)) || \
  230. defined(DOXYGEN)
  231. /** \brief Set CNTFRQ
  232. This function assigns the given value to PL1 Physical Timer Counter Frequency Register (CNTFRQ).
  233. \param [in] value CNTFRQ Register value to set
  234. */
  235. __STATIC_FORCEINLINE void __set_CNTFRQ(uint32_t value)
  236. {
  237. __set_CP(15, 0, value, 14, 0, 0);
  238. }
  239. /** \brief Get CNTFRQ
  240. This function returns the value of the PL1 Physical Timer Counter Frequency Register (CNTFRQ).
  241. \return CNTFRQ Register value
  242. */
  243. __STATIC_FORCEINLINE uint32_t __get_CNTFRQ(void)
  244. {
  245. uint32_t result;
  246. __get_CP(15, 0, result, 14, 0 , 0);
  247. return result;
  248. }
  249. /** \brief Set CNTP_TVAL
  250. This function assigns the given value to PL1 Physical Timer Value Register (CNTP_TVAL).
  251. \param [in] value CNTP_TVAL Register value to set
  252. */
  253. __STATIC_FORCEINLINE void __set_CNTP_TVAL(uint32_t value)
  254. {
  255. __set_CP(15, 0, value, 14, 2, 0);
  256. }
  257. /** \brief Get CNTP_TVAL
  258. This function returns the value of the PL1 Physical Timer Value Register (CNTP_TVAL).
  259. \return CNTP_TVAL Register value
  260. */
  261. __STATIC_FORCEINLINE uint32_t __get_CNTP_TVAL(void)
  262. {
  263. uint32_t result;
  264. __get_CP(15, 0, result, 14, 2, 0);
  265. return result;
  266. }
  267. /** \brief Get CNTPCT
  268. This function returns the value of the 64 bits PL1 Physical Count Register (CNTPCT).
  269. \return CNTPCT Register value
  270. */
  271. __STATIC_FORCEINLINE uint64_t __get_CNTPCT(void)
  272. {
  273. uint64_t result;
  274. __get_CP64(15, 0, result, 14);
  275. return result;
  276. }
  277. /** \brief Set CNTP_CVAL
  278. This function assigns the given value to 64bits PL1 Physical Timer CompareValue Register (CNTP_CVAL).
  279. \param [in] value CNTP_CVAL Register value to set
  280. */
  281. __STATIC_FORCEINLINE void __set_CNTP_CVAL(uint64_t value)
  282. {
  283. __set_CP64(15, 2, value, 14);
  284. }
  285. /** \brief Get CNTP_CVAL
  286. This function returns the value of the 64 bits PL1 Physical Timer CompareValue Register (CNTP_CVAL).
  287. \return CNTP_CVAL Register value
  288. */
  289. __STATIC_FORCEINLINE uint64_t __get_CNTP_CVAL(void)
  290. {
  291. uint64_t result;
  292. __get_CP64(15, 2, result, 14);
  293. return result;
  294. }
  295. /** \brief Set CNTP_CTL
  296. This function assigns the given value to PL1 Physical Timer Control Register (CNTP_CTL).
  297. \param [in] value CNTP_CTL Register value to set
  298. */
  299. __STATIC_FORCEINLINE void __set_CNTP_CTL(uint32_t value)
  300. {
  301. __set_CP(15, 0, value, 14, 2, 1);
  302. }
  303. /** \brief Get CNTP_CTL register
  304. \return CNTP_CTL Register value
  305. */
  306. __STATIC_FORCEINLINE uint32_t __get_CNTP_CTL(void)
  307. {
  308. uint32_t result;
  309. __get_CP(15, 0, result, 14, 2, 1);
  310. return result;
  311. }
  312. #endif
  313. /** \brief Set TLBIALL
  314. TLB Invalidate All
  315. */
  316. __STATIC_FORCEINLINE void __set_TLBIALL(uint32_t value)
  317. {
  318. __set_CP(15, 0, value, 8, 7, 0);
  319. }
  320. /** \brief Set BPIALL.
  321. Branch Predictor Invalidate All
  322. */
  323. __STATIC_FORCEINLINE void __set_BPIALL(uint32_t value)
  324. {
  325. __set_CP(15, 0, value, 7, 5, 6);
  326. }
  327. /** \brief Set ICIALLU
  328. Instruction Cache Invalidate All
  329. */
  330. __STATIC_FORCEINLINE void __set_ICIALLU(uint32_t value)
  331. {
  332. __set_CP(15, 0, value, 7, 5, 0);
  333. }
  334. /** \brief Set DCCMVAC
  335. Data cache clean
  336. */
  337. __STATIC_FORCEINLINE void __set_DCCMVAC(uint32_t value)
  338. {
  339. __set_CP(15, 0, value, 7, 10, 1);
  340. }
  341. /** \brief Set DCIMVAC
  342. Data cache invalidate
  343. */
  344. __STATIC_FORCEINLINE void __set_DCIMVAC(uint32_t value)
  345. {
  346. __set_CP(15, 0, value, 7, 6, 1);
  347. }
  348. /** \brief Set DCCIMVAC
  349. Data cache clean and invalidate
  350. */
  351. __STATIC_FORCEINLINE void __set_DCCIMVAC(uint32_t value)
  352. {
  353. __set_CP(15, 0, value, 7, 14, 1);
  354. }
  355. /** \brief Set CSSELR
  356. */
  357. __STATIC_FORCEINLINE void __set_CSSELR(uint32_t value)
  358. {
  359. // __ASM volatile("MCR p15, 2, %0, c0, c0, 0" : : "r"(value) : "memory");
  360. __set_CP(15, 2, value, 0, 0, 0);
  361. }
  362. /** \brief Get CSSELR
  363. \return CSSELR Register value
  364. */
  365. __STATIC_FORCEINLINE uint32_t __get_CSSELR(void)
  366. {
  367. uint32_t result;
  368. // __ASM volatile("MRC p15, 2, %0, c0, c0, 0" : "=r"(result) : : "memory");
  369. __get_CP(15, 2, result, 0, 0, 0);
  370. return result;
  371. }
  372. /** \brief Set CCSIDR
  373. \deprecated CCSIDR itself is read-only. Use __set_CSSELR to select cache level instead.
  374. */
  375. CMSIS_DEPRECATED
  376. __STATIC_FORCEINLINE void __set_CCSIDR(uint32_t value)
  377. {
  378. __set_CSSELR(value);
  379. }
  380. /** \brief Get CCSIDR
  381. \return CCSIDR Register value
  382. */
  383. __STATIC_FORCEINLINE uint32_t __get_CCSIDR(void)
  384. {
  385. uint32_t result;
  386. // __ASM volatile("MRC p15, 1, %0, c0, c0, 0" : "=r"(result) : : "memory");
  387. __get_CP(15, 1, result, 0, 0, 0);
  388. return result;
  389. }
  390. /** \brief Get CLIDR
  391. \return CLIDR Register value
  392. */
  393. __STATIC_FORCEINLINE uint32_t __get_CLIDR(void)
  394. {
  395. uint32_t result;
  396. // __ASM volatile("MRC p15, 1, %0, c0, c0, 1" : "=r"(result) : : "memory");
  397. __get_CP(15, 1, result, 0, 0, 1);
  398. return result;
  399. }
  400. /** \brief Set DCISW
  401. */
  402. __STATIC_FORCEINLINE void __set_DCISW(uint32_t value)
  403. {
  404. // __ASM volatile("MCR p15, 0, %0, c7, c6, 2" : : "r"(value) : "memory")
  405. __set_CP(15, 0, value, 7, 6, 2);
  406. }
  407. /** \brief Set DCCSW
  408. */
  409. __STATIC_FORCEINLINE void __set_DCCSW(uint32_t value)
  410. {
  411. // __ASM volatile("MCR p15, 0, %0, c7, c10, 2" : : "r"(value) : "memory")
  412. __set_CP(15, 0, value, 7, 10, 2);
  413. }
  414. /** \brief Set DCCISW
  415. */
  416. __STATIC_FORCEINLINE void __set_DCCISW(uint32_t value)
  417. {
  418. // __ASM volatile("MCR p15, 0, %0, c7, c14, 2" : : "r"(value) : "memory")
  419. __set_CP(15, 0, value, 7, 14, 2);
  420. }
  421. #endif