cmsis_armclang.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. /**************************************************************************//**
  2. * @file cmsis_armclang.h
  3. * @brief CMSIS compiler armclang (Arm Compiler 6) header file
  4. * @version V5.1.0
  5. * @date 14. March 2019
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2019 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. /*lint -esym(9058, IRQn)*/ /* disable MISRA 2012 Rule 2.4 for IRQn */
  25. #ifndef __CMSIS_ARMCLANG_H
  26. #define __CMSIS_ARMCLANG_H
  27. #pragma clang system_header /* treat file as system include file */
  28. #ifndef __ARM_COMPAT_H
  29. #include <arm_compat.h> /* Compatibility header for Arm Compiler 5 intrinsics */
  30. #endif
  31. /* CMSIS compiler specific defines */
  32. #ifndef __ASM
  33. #define __ASM __asm
  34. #endif
  35. #ifndef __INLINE
  36. #define __INLINE __inline
  37. #endif
  38. #ifndef __STATIC_INLINE
  39. #define __STATIC_INLINE static __inline
  40. #endif
  41. #ifndef __STATIC_FORCEINLINE
  42. #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline
  43. #endif
  44. #ifndef __NO_RETURN
  45. #define __NO_RETURN __attribute__((__noreturn__))
  46. #endif
  47. #ifndef __USED
  48. #define __USED __attribute__((used))
  49. #endif
  50. #ifndef __WEAK
  51. #define __WEAK __attribute__((weak))
  52. #endif
  53. #ifndef __PACKED
  54. #define __PACKED __attribute__((packed, aligned(1)))
  55. #endif
  56. #ifndef __PACKED_STRUCT
  57. #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
  58. #endif
  59. #ifndef __PACKED_UNION
  60. #define __PACKED_UNION union __attribute__((packed, aligned(1)))
  61. #endif
  62. #ifndef __UNALIGNED_UINT32 /* deprecated */
  63. #pragma clang diagnostic push
  64. #pragma clang diagnostic ignored "-Wpacked"
  65. /*lint -esym(9058, T_UINT32)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32 */
  66. struct __attribute__((packed)) T_UINT32
  67. {
  68. uint32_t v;
  69. };
  70. #pragma clang diagnostic pop
  71. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  72. #endif
  73. #ifndef __UNALIGNED_UINT16_WRITE
  74. #pragma clang diagnostic push
  75. #pragma clang diagnostic ignored "-Wpacked"
  76. /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
  77. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  78. #pragma clang diagnostic pop
  79. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  80. #endif
  81. #ifndef __UNALIGNED_UINT16_READ
  82. #pragma clang diagnostic push
  83. #pragma clang diagnostic ignored "-Wpacked"
  84. /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
  85. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  86. #pragma clang diagnostic pop
  87. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  88. #endif
  89. #ifndef __UNALIGNED_UINT32_WRITE
  90. #pragma clang diagnostic push
  91. #pragma clang diagnostic ignored "-Wpacked"
  92. /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
  93. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  94. #pragma clang diagnostic pop
  95. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  96. #endif
  97. #ifndef __UNALIGNED_UINT32_READ
  98. #pragma clang diagnostic push
  99. #pragma clang diagnostic ignored "-Wpacked"
  100. /*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */
  101. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  102. #pragma clang diagnostic pop
  103. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  104. #endif
  105. #ifndef __ALIGNED
  106. #define __ALIGNED(x) __attribute__((aligned(x)))
  107. #endif
  108. #ifndef __RESTRICT
  109. #define __RESTRICT __restrict
  110. #endif
  111. /* ########################### Core Function Access ########################### */
  112. /** \ingroup CMSIS_Core_FunctionInterface
  113. \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
  114. @{
  115. */
  116. /**
  117. \brief Enable IRQ Interrupts
  118. \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
  119. Can only be executed in Privileged modes.
  120. */
  121. /* intrinsic void __enable_irq(); see arm_compat.h */
  122. /**
  123. \brief Disable IRQ Interrupts
  124. \details Disables IRQ interrupts by setting the I-bit in the CPSR.
  125. Can only be executed in Privileged modes.
  126. */
  127. /* intrinsic void __disable_irq(); see arm_compat.h */
  128. /**
  129. \brief Get Control Register
  130. \details Returns the content of the Control Register.
  131. \return Control Register value
  132. */
  133. __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
  134. {
  135. uint32_t result;
  136. __ASM volatile("MRS %0, control" : "=r"(result));
  137. return (result);
  138. }
  139. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  140. /**
  141. \brief Get Control Register (non-secure)
  142. \details Returns the content of the non-secure Control Register when in secure mode.
  143. \return non-secure Control Register value
  144. */
  145. __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
  146. {
  147. uint32_t result;
  148. __ASM volatile("MRS %0, control_ns" : "=r"(result));
  149. return (result);
  150. }
  151. #endif
  152. /**
  153. \brief Set Control Register
  154. \details Writes the given value to the Control Register.
  155. \param [in] control Control Register value to set
  156. */
  157. __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
  158. {
  159. __ASM volatile("MSR control, %0" : : "r"(control) : "memory");
  160. }
  161. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  162. /**
  163. \brief Set Control Register (non-secure)
  164. \details Writes the given value to the non-secure Control Register when in secure state.
  165. \param [in] control Control Register value to set
  166. */
  167. __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
  168. {
  169. __ASM volatile("MSR control_ns, %0" : : "r"(control) : "memory");
  170. }
  171. #endif
  172. /**
  173. \brief Get IPSR Register
  174. \details Returns the content of the IPSR Register.
  175. \return IPSR Register value
  176. */
  177. __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
  178. {
  179. uint32_t result;
  180. __ASM volatile("MRS %0, ipsr" : "=r"(result));
  181. return (result);
  182. }
  183. /**
  184. \brief Get APSR Register
  185. \details Returns the content of the APSR Register.
  186. \return APSR Register value
  187. */
  188. __STATIC_FORCEINLINE uint32_t __get_APSR(void)
  189. {
  190. uint32_t result;
  191. __ASM volatile("MRS %0, apsr" : "=r"(result));
  192. return (result);
  193. }
  194. /**
  195. \brief Get xPSR Register
  196. \details Returns the content of the xPSR Register.
  197. \return xPSR Register value
  198. */
  199. __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
  200. {
  201. uint32_t result;
  202. __ASM volatile("MRS %0, xpsr" : "=r"(result));
  203. return (result);
  204. }
  205. /**
  206. \brief Get Process Stack Pointer
  207. \details Returns the current value of the Process Stack Pointer (PSP).
  208. \return PSP Register value
  209. */
  210. __STATIC_FORCEINLINE uint32_t __get_PSP(void)
  211. {
  212. uint32_t result;
  213. __ASM volatile("MRS %0, psp" : "=r"(result));
  214. return (result);
  215. }
  216. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  217. /**
  218. \brief Get Process Stack Pointer (non-secure)
  219. \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
  220. \return PSP Register value
  221. */
  222. __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
  223. {
  224. uint32_t result;
  225. __ASM volatile("MRS %0, psp_ns" : "=r"(result));
  226. return (result);
  227. }
  228. #endif
  229. /**
  230. \brief Set Process Stack Pointer
  231. \details Assigns the given value to the Process Stack Pointer (PSP).
  232. \param [in] topOfProcStack Process Stack Pointer value to set
  233. */
  234. __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
  235. {
  236. __ASM volatile("MSR psp, %0" : : "r"(topOfProcStack) :);
  237. }
  238. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  239. /**
  240. \brief Set Process Stack Pointer (non-secure)
  241. \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
  242. \param [in] topOfProcStack Process Stack Pointer value to set
  243. */
  244. __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
  245. {
  246. __ASM volatile("MSR psp_ns, %0" : : "r"(topOfProcStack) :);
  247. }
  248. #endif
  249. /**
  250. \brief Get Main Stack Pointer
  251. \details Returns the current value of the Main Stack Pointer (MSP).
  252. \return MSP Register value
  253. */
  254. __STATIC_FORCEINLINE uint32_t __get_MSP(void)
  255. {
  256. uint32_t result;
  257. __ASM volatile("MRS %0, msp" : "=r"(result));
  258. return (result);
  259. }
  260. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  261. /**
  262. \brief Get Main Stack Pointer (non-secure)
  263. \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
  264. \return MSP Register value
  265. */
  266. __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
  267. {
  268. uint32_t result;
  269. __ASM volatile("MRS %0, msp_ns" : "=r"(result));
  270. return (result);
  271. }
  272. #endif
  273. /**
  274. \brief Set Main Stack Pointer
  275. \details Assigns the given value to the Main Stack Pointer (MSP).
  276. \param [in] topOfMainStack Main Stack Pointer value to set
  277. */
  278. __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
  279. {
  280. __ASM volatile("MSR msp, %0" : : "r"(topOfMainStack) :);
  281. }
  282. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  283. /**
  284. \brief Set Main Stack Pointer (non-secure)
  285. \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
  286. \param [in] topOfMainStack Main Stack Pointer value to set
  287. */
  288. __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
  289. {
  290. __ASM volatile("MSR msp_ns, %0" : : "r"(topOfMainStack) :);
  291. }
  292. #endif
  293. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  294. /**
  295. \brief Get Stack Pointer (non-secure)
  296. \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
  297. \return SP Register value
  298. */
  299. __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
  300. {
  301. uint32_t result;
  302. __ASM volatile("MRS %0, sp_ns" : "=r"(result));
  303. return (result);
  304. }
  305. /**
  306. \brief Set Stack Pointer (non-secure)
  307. \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
  308. \param [in] topOfStack Stack Pointer value to set
  309. */
  310. __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
  311. {
  312. __ASM volatile("MSR sp_ns, %0" : : "r"(topOfStack) :);
  313. }
  314. #endif
  315. /**
  316. \brief Get Priority Mask
  317. \details Returns the current state of the priority mask bit from the Priority Mask Register.
  318. \return Priority Mask value
  319. */
  320. __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
  321. {
  322. uint32_t result;
  323. __ASM volatile("MRS %0, primask" : "=r"(result));
  324. return (result);
  325. }
  326. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  327. /**
  328. \brief Get Priority Mask (non-secure)
  329. \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
  330. \return Priority Mask value
  331. */
  332. __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
  333. {
  334. uint32_t result;
  335. __ASM volatile("MRS %0, primask_ns" : "=r"(result));
  336. return (result);
  337. }
  338. #endif
  339. /**
  340. \brief Set Priority Mask
  341. \details Assigns the given value to the Priority Mask Register.
  342. \param [in] priMask Priority Mask
  343. */
  344. __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
  345. {
  346. __ASM volatile("MSR primask, %0" : : "r"(priMask) : "memory");
  347. }
  348. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  349. /**
  350. \brief Set Priority Mask (non-secure)
  351. \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
  352. \param [in] priMask Priority Mask
  353. */
  354. __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
  355. {
  356. __ASM volatile("MSR primask_ns, %0" : : "r"(priMask) : "memory");
  357. }
  358. #endif
  359. #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  360. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  361. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
  362. /**
  363. \brief Enable FIQ
  364. \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
  365. Can only be executed in Privileged modes.
  366. */
  367. #define __enable_fault_irq __enable_fiq /* see arm_compat.h */
  368. /**
  369. \brief Disable FIQ
  370. \details Disables FIQ interrupts by setting the F-bit in the CPSR.
  371. Can only be executed in Privileged modes.
  372. */
  373. #define __disable_fault_irq __disable_fiq /* see arm_compat.h */
  374. /**
  375. \brief Get Base Priority
  376. \details Returns the current value of the Base Priority register.
  377. \return Base Priority register value
  378. */
  379. __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
  380. {
  381. uint32_t result;
  382. __ASM volatile("MRS %0, basepri" : "=r"(result));
  383. return (result);
  384. }
  385. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  386. /**
  387. \brief Get Base Priority (non-secure)
  388. \details Returns the current value of the non-secure Base Priority register when in secure state.
  389. \return Base Priority register value
  390. */
  391. __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
  392. {
  393. uint32_t result;
  394. __ASM volatile("MRS %0, basepri_ns" : "=r"(result));
  395. return (result);
  396. }
  397. #endif
  398. /**
  399. \brief Set Base Priority
  400. \details Assigns the given value to the Base Priority register.
  401. \param [in] basePri Base Priority value to set
  402. */
  403. __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
  404. {
  405. __ASM volatile("MSR basepri, %0" : : "r"(basePri) : "memory");
  406. }
  407. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  408. /**
  409. \brief Set Base Priority (non-secure)
  410. \details Assigns the given value to the non-secure Base Priority register when in secure state.
  411. \param [in] basePri Base Priority value to set
  412. */
  413. __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
  414. {
  415. __ASM volatile("MSR basepri_ns, %0" : : "r"(basePri) : "memory");
  416. }
  417. #endif
  418. /**
  419. \brief Set Base Priority with condition
  420. \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
  421. or the new value increases the BASEPRI priority level.
  422. \param [in] basePri Base Priority value to set
  423. */
  424. __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
  425. {
  426. __ASM volatile("MSR basepri_max, %0" : : "r"(basePri) : "memory");
  427. }
  428. /**
  429. \brief Get Fault Mask
  430. \details Returns the current value of the Fault Mask register.
  431. \return Fault Mask register value
  432. */
  433. __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
  434. {
  435. uint32_t result;
  436. __ASM volatile("MRS %0, faultmask" : "=r"(result));
  437. return (result);
  438. }
  439. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  440. /**
  441. \brief Get Fault Mask (non-secure)
  442. \details Returns the current value of the non-secure Fault Mask register when in secure state.
  443. \return Fault Mask register value
  444. */
  445. __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
  446. {
  447. uint32_t result;
  448. __ASM volatile("MRS %0, faultmask_ns" : "=r"(result));
  449. return (result);
  450. }
  451. #endif
  452. /**
  453. \brief Set Fault Mask
  454. \details Assigns the given value to the Fault Mask register.
  455. \param [in] faultMask Fault Mask value to set
  456. */
  457. __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
  458. {
  459. __ASM volatile("MSR faultmask, %0" : : "r"(faultMask) : "memory");
  460. }
  461. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  462. /**
  463. \brief Set Fault Mask (non-secure)
  464. \details Assigns the given value to the non-secure Fault Mask register when in secure state.
  465. \param [in] faultMask Fault Mask value to set
  466. */
  467. __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
  468. {
  469. __ASM volatile("MSR faultmask_ns, %0" : : "r"(faultMask) : "memory");
  470. }
  471. #endif
  472. #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  473. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  474. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
  475. #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  476. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
  477. /**
  478. \brief Get Process Stack Pointer Limit
  479. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  480. Stack Pointer Limit register hence zero is returned always in non-secure
  481. mode.
  482. \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
  483. \return PSPLIM Register value
  484. */
  485. __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
  486. {
  487. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  488. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  489. // without main extensions, the non-secure PSPLIM is RAZ/WI
  490. return 0U;
  491. #else
  492. uint32_t result;
  493. __ASM volatile("MRS %0, psplim" : "=r"(result));
  494. return result;
  495. #endif
  496. }
  497. #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
  498. /**
  499. \brief Get Process Stack Pointer Limit (non-secure)
  500. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  501. Stack Pointer Limit register hence zero is returned always in non-secure
  502. mode.
  503. \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
  504. \return PSPLIM Register value
  505. */
  506. __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
  507. {
  508. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
  509. // without main extensions, the non-secure PSPLIM is RAZ/WI
  510. return 0U;
  511. #else
  512. uint32_t result;
  513. __ASM volatile("MRS %0, psplim_ns" : "=r"(result));
  514. return result;
  515. #endif
  516. }
  517. #endif
  518. /**
  519. \brief Set Process Stack Pointer Limit
  520. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  521. Stack Pointer Limit register hence the write is silently ignored in non-secure
  522. mode.
  523. \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
  524. \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
  525. */
  526. __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
  527. {
  528. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  529. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  530. // without main extensions, the non-secure PSPLIM is RAZ/WI
  531. (void)ProcStackPtrLimit;
  532. #else
  533. __ASM volatile("MSR psplim, %0" : : "r"(ProcStackPtrLimit));
  534. #endif
  535. }
  536. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  537. /**
  538. \brief Set Process Stack Pointer (non-secure)
  539. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  540. Stack Pointer Limit register hence the write is silently ignored in non-secure
  541. mode.
  542. \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
  543. \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
  544. */
  545. __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
  546. {
  547. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
  548. // without main extensions, the non-secure PSPLIM is RAZ/WI
  549. (void)ProcStackPtrLimit;
  550. #else
  551. __ASM volatile("MSR psplim_ns, %0\n" : : "r"(ProcStackPtrLimit));
  552. #endif
  553. }
  554. #endif
  555. /**
  556. \brief Get Main Stack Pointer Limit
  557. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  558. Stack Pointer Limit register hence zero is returned always.
  559. \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
  560. \return MSPLIM Register value
  561. */
  562. __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
  563. {
  564. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  565. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  566. // without main extensions, the non-secure MSPLIM is RAZ/WI
  567. return 0U;
  568. #else
  569. uint32_t result;
  570. __ASM volatile("MRS %0, msplim" : "=r"(result));
  571. return result;
  572. #endif
  573. }
  574. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  575. /**
  576. \brief Get Main Stack Pointer Limit (non-secure)
  577. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  578. Stack Pointer Limit register hence zero is returned always.
  579. \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
  580. \return MSPLIM Register value
  581. */
  582. __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
  583. {
  584. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
  585. // without main extensions, the non-secure MSPLIM is RAZ/WI
  586. return 0U;
  587. #else
  588. uint32_t result;
  589. __ASM volatile("MRS %0, msplim_ns" : "=r"(result));
  590. return result;
  591. #endif
  592. }
  593. #endif
  594. /**
  595. \brief Set Main Stack Pointer Limit
  596. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  597. Stack Pointer Limit register hence the write is silently ignored.
  598. \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
  599. \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
  600. */
  601. __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
  602. {
  603. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  604. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  605. // without main extensions, the non-secure MSPLIM is RAZ/WI
  606. (void)MainStackPtrLimit;
  607. #else
  608. __ASM volatile("MSR msplim, %0" : : "r"(MainStackPtrLimit));
  609. #endif
  610. }
  611. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  612. /**
  613. \brief Set Main Stack Pointer Limit (non-secure)
  614. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  615. Stack Pointer Limit register hence the write is silently ignored.
  616. \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
  617. \param [in] MainStackPtrLimit Main Stack Pointer value to set
  618. */
  619. __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
  620. {
  621. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
  622. // without main extensions, the non-secure MSPLIM is RAZ/WI
  623. (void)MainStackPtrLimit;
  624. #else
  625. __ASM volatile("MSR msplim_ns, %0" : : "r"(MainStackPtrLimit));
  626. #endif
  627. }
  628. #endif
  629. #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  630. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
  631. /**
  632. \brief Get FPSCR
  633. \details Returns the current value of the Floating Point Status/Control register.
  634. \return Floating Point Status/Control register value
  635. */
  636. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
  637. (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
  638. #define __get_FPSCR (uint32_t)__builtin_arm_get_fpscr
  639. #else
  640. #define __get_FPSCR() ((uint32_t)0U)
  641. #endif
  642. /**
  643. \brief Set FPSCR
  644. \details Assigns the given value to the Floating Point Status/Control register.
  645. \param [in] fpscr Floating Point Status/Control value to set
  646. */
  647. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
  648. (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
  649. #define __set_FPSCR __builtin_arm_set_fpscr
  650. #else
  651. #define __set_FPSCR(x) ((void)(x))
  652. #endif
  653. /*@} end of CMSIS_Core_RegAccFunctions */
  654. /* ########################## Core Instruction Access ######################### */
  655. /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
  656. Access to dedicated instructions
  657. @{
  658. */
  659. /* Define macros for porting to both thumb1 and thumb2.
  660. * For thumb1, use low register (r0-r7), specified by constraint "l"
  661. * Otherwise, use general registers, specified by constraint "r" */
  662. #if defined (__thumb__) && !defined (__thumb2__)
  663. #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
  664. #define __CMSIS_GCC_RW_REG(r) "+l" (r)
  665. #define __CMSIS_GCC_USE_REG(r) "l" (r)
  666. #else
  667. #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
  668. #define __CMSIS_GCC_RW_REG(r) "+r" (r)
  669. #define __CMSIS_GCC_USE_REG(r) "r" (r)
  670. #endif
  671. /**
  672. \brief No Operation
  673. \details No Operation does nothing. This instruction can be used for code alignment purposes.
  674. */
  675. #define __NOP __builtin_arm_nop
  676. /**
  677. \brief Wait For Interrupt
  678. \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
  679. */
  680. #define __WFI __builtin_arm_wfi
  681. /**
  682. \brief Wait For Event
  683. \details Wait For Event is a hint instruction that permits the processor to enter
  684. a low-power state until one of a number of events occurs.
  685. */
  686. #define __WFE __builtin_arm_wfe
  687. /**
  688. \brief Send Event
  689. \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
  690. */
  691. #define __SEV __builtin_arm_sev
  692. /**
  693. \brief Instruction Synchronization Barrier
  694. \details Instruction Synchronization Barrier flushes the pipeline in the processor,
  695. so that all instructions following the ISB are fetched from cache or memory,
  696. after the instruction has been completed.
  697. */
  698. #define __ISB() __builtin_arm_isb(0xF)
  699. /**
  700. \brief Data Synchronization Barrier
  701. \details Acts as a special kind of Data Memory Barrier.
  702. It completes when all explicit memory accesses before this instruction complete.
  703. */
  704. #define __DSB() __builtin_arm_dsb(0xF)
  705. /**
  706. \brief Data Memory Barrier
  707. \details Ensures the apparent order of the explicit memory operations before
  708. and after the instruction, without ensuring their completion.
  709. */
  710. #define __DMB() __builtin_arm_dmb(0xF)
  711. /**
  712. \brief Reverse byte order (32 bit)
  713. \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
  714. \param [in] value Value to reverse
  715. \return Reversed value
  716. */
  717. #define __REV(value) __builtin_bswap32(value)
  718. /**
  719. \brief Reverse byte order (16 bit)
  720. \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
  721. \param [in] value Value to reverse
  722. \return Reversed value
  723. */
  724. #define __REV16(value) __ROR(__REV(value), 16)
  725. /**
  726. \brief Reverse byte order (16 bit)
  727. \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
  728. \param [in] value Value to reverse
  729. \return Reversed value
  730. */
  731. #define __REVSH(value) (int16_t)__builtin_bswap16(value)
  732. /**
  733. \brief Rotate Right in unsigned value (32 bit)
  734. \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
  735. \param [in] op1 Value to rotate
  736. \param [in] op2 Number of Bits to rotate
  737. \return Rotated value
  738. */
  739. __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
  740. {
  741. op2 %= 32U;
  742. if (op2 == 0U)
  743. {
  744. return op1;
  745. }
  746. return (op1 >> op2) | (op1 << (32U - op2));
  747. }
  748. /**
  749. \brief Breakpoint
  750. \details Causes the processor to enter Debug state.
  751. Debug tools can use this to investigate system state when the instruction at a particular address is reached.
  752. \param [in] value is ignored by the processor.
  753. If required, a debugger can use it to store additional information about the breakpoint.
  754. */
  755. #define __BKPT(value) __ASM volatile ("bkpt "#value)
  756. /**
  757. \brief Reverse bit order of value
  758. \details Reverses the bit order of the given value.
  759. \param [in] value Value to reverse
  760. \return Reversed value
  761. */
  762. #define __RBIT __builtin_arm_rbit
  763. /**
  764. \brief Count leading zeros
  765. \details Counts the number of leading zeros of a data value.
  766. \param [in] value Value to count the leading zeros
  767. \return number of leading zeros in value
  768. */
  769. __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
  770. {
  771. /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
  772. __builtin_clz(0) is undefined behaviour, so handle this case specially.
  773. This guarantees ARM-compatible results if happening to compile on a non-ARM
  774. target, and ensures the compiler doesn't decide to activate any
  775. optimisations using the logic "value was passed to __builtin_clz, so it
  776. is non-zero".
  777. ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a
  778. single CLZ instruction.
  779. */
  780. if (value == 0U)
  781. {
  782. return 32U;
  783. }
  784. return __builtin_clz(value);
  785. }
  786. #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  787. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  788. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  789. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
  790. /**
  791. \brief LDR Exclusive (8 bit)
  792. \details Executes a exclusive LDR instruction for 8 bit value.
  793. \param [in] ptr Pointer to data
  794. \return value of type uint8_t at (*ptr)
  795. */
  796. #define __LDREXB (uint8_t)__builtin_arm_ldrex
  797. /**
  798. \brief LDR Exclusive (16 bit)
  799. \details Executes a exclusive LDR instruction for 16 bit values.
  800. \param [in] ptr Pointer to data
  801. \return value of type uint16_t at (*ptr)
  802. */
  803. #define __LDREXH (uint16_t)__builtin_arm_ldrex
  804. /**
  805. \brief LDR Exclusive (32 bit)
  806. \details Executes a exclusive LDR instruction for 32 bit values.
  807. \param [in] ptr Pointer to data
  808. \return value of type uint32_t at (*ptr)
  809. */
  810. #define __LDREXW (uint32_t)__builtin_arm_ldrex
  811. /**
  812. \brief STR Exclusive (8 bit)
  813. \details Executes a exclusive STR instruction for 8 bit values.
  814. \param [in] value Value to store
  815. \param [in] ptr Pointer to location
  816. \return 0 Function succeeded
  817. \return 1 Function failed
  818. */
  819. #define __STREXB (uint32_t)__builtin_arm_strex
  820. /**
  821. \brief STR Exclusive (16 bit)
  822. \details Executes a exclusive STR instruction for 16 bit values.
  823. \param [in] value Value to store
  824. \param [in] ptr Pointer to location
  825. \return 0 Function succeeded
  826. \return 1 Function failed
  827. */
  828. #define __STREXH (uint32_t)__builtin_arm_strex
  829. /**
  830. \brief STR Exclusive (32 bit)
  831. \details Executes a exclusive STR instruction for 32 bit values.
  832. \param [in] value Value to store
  833. \param [in] ptr Pointer to location
  834. \return 0 Function succeeded
  835. \return 1 Function failed
  836. */
  837. #define __STREXW (uint32_t)__builtin_arm_strex
  838. /**
  839. \brief Remove the exclusive lock
  840. \details Removes the exclusive lock which is created by LDREX.
  841. */
  842. #define __CLREX __builtin_arm_clrex
  843. #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  844. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  845. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  846. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
  847. #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  848. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  849. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
  850. /**
  851. \brief Signed Saturate
  852. \details Saturates a signed value.
  853. \param [in] value Value to be saturated
  854. \param [in] sat Bit position to saturate to (1..32)
  855. \return Saturated value
  856. */
  857. #define __SSAT __builtin_arm_ssat
  858. /**
  859. \brief Unsigned Saturate
  860. \details Saturates an unsigned value.
  861. \param [in] value Value to be saturated
  862. \param [in] sat Bit position to saturate to (0..31)
  863. \return Saturated value
  864. */
  865. #define __USAT __builtin_arm_usat
  866. /**
  867. \brief Rotate Right with Extend (32 bit)
  868. \details Moves each bit of a bitstring right by one bit.
  869. The carry input is shifted in at the left end of the bitstring.
  870. \param [in] value Value to rotate
  871. \return Rotated value
  872. */
  873. __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
  874. {
  875. uint32_t result;
  876. __ASM volatile("rrx %0, %1" : __CMSIS_GCC_OUT_REG(result) : __CMSIS_GCC_USE_REG(value));
  877. return (result);
  878. }
  879. /**
  880. \brief LDRT Unprivileged (8 bit)
  881. \details Executes a Unprivileged LDRT instruction for 8 bit value.
  882. \param [in] ptr Pointer to data
  883. \return value of type uint8_t at (*ptr)
  884. */
  885. __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
  886. {
  887. uint32_t result;
  888. __ASM volatile("ldrbt %0, %1" : "=r"(result) : "Q"(*ptr));
  889. return ((uint8_t) result); /* Add explicit type cast here */
  890. }
  891. /**
  892. \brief LDRT Unprivileged (16 bit)
  893. \details Executes a Unprivileged LDRT instruction for 16 bit values.
  894. \param [in] ptr Pointer to data
  895. \return value of type uint16_t at (*ptr)
  896. */
  897. __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
  898. {
  899. uint32_t result;
  900. __ASM volatile("ldrht %0, %1" : "=r"(result) : "Q"(*ptr));
  901. return ((uint16_t) result); /* Add explicit type cast here */
  902. }
  903. /**
  904. \brief LDRT Unprivileged (32 bit)
  905. \details Executes a Unprivileged LDRT instruction for 32 bit values.
  906. \param [in] ptr Pointer to data
  907. \return value of type uint32_t at (*ptr)
  908. */
  909. __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
  910. {
  911. uint32_t result;
  912. __ASM volatile("ldrt %0, %1" : "=r"(result) : "Q"(*ptr));
  913. return (result);
  914. }
  915. /**
  916. \brief STRT Unprivileged (8 bit)
  917. \details Executes a Unprivileged STRT instruction for 8 bit values.
  918. \param [in] value Value to store
  919. \param [in] ptr Pointer to location
  920. */
  921. __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
  922. {
  923. __ASM volatile("strbt %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  924. }
  925. /**
  926. \brief STRT Unprivileged (16 bit)
  927. \details Executes a Unprivileged STRT instruction for 16 bit values.
  928. \param [in] value Value to store
  929. \param [in] ptr Pointer to location
  930. */
  931. __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
  932. {
  933. __ASM volatile("strht %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  934. }
  935. /**
  936. \brief STRT Unprivileged (32 bit)
  937. \details Executes a Unprivileged STRT instruction for 32 bit values.
  938. \param [in] value Value to store
  939. \param [in] ptr Pointer to location
  940. */
  941. __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
  942. {
  943. __ASM volatile("strt %1, %0" : "=Q"(*ptr) : "r"(value));
  944. }
  945. #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  946. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  947. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
  948. /**
  949. \brief Signed Saturate
  950. \details Saturates a signed value.
  951. \param [in] value Value to be saturated
  952. \param [in] sat Bit position to saturate to (1..32)
  953. \return Saturated value
  954. */
  955. __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
  956. {
  957. if ((sat >= 1U) && (sat <= 32U))
  958. {
  959. const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
  960. const int32_t min = -1 - max ;
  961. if (val > max)
  962. {
  963. return max;
  964. }
  965. else if (val < min)
  966. {
  967. return min;
  968. }
  969. }
  970. return val;
  971. }
  972. /**
  973. \brief Unsigned Saturate
  974. \details Saturates an unsigned value.
  975. \param [in] value Value to be saturated
  976. \param [in] sat Bit position to saturate to (0..31)
  977. \return Saturated value
  978. */
  979. __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
  980. {
  981. if (sat <= 31U)
  982. {
  983. const uint32_t max = ((1U << sat) - 1U);
  984. if (val > (int32_t)max)
  985. {
  986. return max;
  987. }
  988. else if (val < 0)
  989. {
  990. return 0U;
  991. }
  992. }
  993. return (uint32_t)val;
  994. }
  995. #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  996. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  997. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
  998. #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  999. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
  1000. /**
  1001. \brief Load-Acquire (8 bit)
  1002. \details Executes a LDAB instruction for 8 bit value.
  1003. \param [in] ptr Pointer to data
  1004. \return value of type uint8_t at (*ptr)
  1005. */
  1006. __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
  1007. {
  1008. uint32_t result;
  1009. __ASM volatile("ldab %0, %1" : "=r"(result) : "Q"(*ptr));
  1010. return ((uint8_t) result);
  1011. }
  1012. /**
  1013. \brief Load-Acquire (16 bit)
  1014. \details Executes a LDAH instruction for 16 bit values.
  1015. \param [in] ptr Pointer to data
  1016. \return value of type uint16_t at (*ptr)
  1017. */
  1018. __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
  1019. {
  1020. uint32_t result;
  1021. __ASM volatile("ldah %0, %1" : "=r"(result) : "Q"(*ptr));
  1022. return ((uint16_t) result);
  1023. }
  1024. /**
  1025. \brief Load-Acquire (32 bit)
  1026. \details Executes a LDA instruction for 32 bit values.
  1027. \param [in] ptr Pointer to data
  1028. \return value of type uint32_t at (*ptr)
  1029. */
  1030. __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
  1031. {
  1032. uint32_t result;
  1033. __ASM volatile("lda %0, %1" : "=r"(result) : "Q"(*ptr));
  1034. return (result);
  1035. }
  1036. /**
  1037. \brief Store-Release (8 bit)
  1038. \details Executes a STLB instruction for 8 bit values.
  1039. \param [in] value Value to store
  1040. \param [in] ptr Pointer to location
  1041. */
  1042. __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
  1043. {
  1044. __ASM volatile("stlb %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  1045. }
  1046. /**
  1047. \brief Store-Release (16 bit)
  1048. \details Executes a STLH instruction for 16 bit values.
  1049. \param [in] value Value to store
  1050. \param [in] ptr Pointer to location
  1051. */
  1052. __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
  1053. {
  1054. __ASM volatile("stlh %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  1055. }
  1056. /**
  1057. \brief Store-Release (32 bit)
  1058. \details Executes a STL instruction for 32 bit values.
  1059. \param [in] value Value to store
  1060. \param [in] ptr Pointer to location
  1061. */
  1062. __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
  1063. {
  1064. __ASM volatile("stl %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  1065. }
  1066. /**
  1067. \brief Load-Acquire Exclusive (8 bit)
  1068. \details Executes a LDAB exclusive instruction for 8 bit value.
  1069. \param [in] ptr Pointer to data
  1070. \return value of type uint8_t at (*ptr)
  1071. */
  1072. #define __LDAEXB (uint8_t)__builtin_arm_ldaex
  1073. /**
  1074. \brief Load-Acquire Exclusive (16 bit)
  1075. \details Executes a LDAH exclusive instruction for 16 bit values.
  1076. \param [in] ptr Pointer to data
  1077. \return value of type uint16_t at (*ptr)
  1078. */
  1079. #define __LDAEXH (uint16_t)__builtin_arm_ldaex
  1080. /**
  1081. \brief Load-Acquire Exclusive (32 bit)
  1082. \details Executes a LDA exclusive instruction for 32 bit values.
  1083. \param [in] ptr Pointer to data
  1084. \return value of type uint32_t at (*ptr)
  1085. */
  1086. #define __LDAEX (uint32_t)__builtin_arm_ldaex
  1087. /**
  1088. \brief Store-Release Exclusive (8 bit)
  1089. \details Executes a STLB exclusive instruction for 8 bit values.
  1090. \param [in] value Value to store
  1091. \param [in] ptr Pointer to location
  1092. \return 0 Function succeeded
  1093. \return 1 Function failed
  1094. */
  1095. #define __STLEXB (uint32_t)__builtin_arm_stlex
  1096. /**
  1097. \brief Store-Release Exclusive (16 bit)
  1098. \details Executes a STLH exclusive instruction for 16 bit values.
  1099. \param [in] value Value to store
  1100. \param [in] ptr Pointer to location
  1101. \return 0 Function succeeded
  1102. \return 1 Function failed
  1103. */
  1104. #define __STLEXH (uint32_t)__builtin_arm_stlex
  1105. /**
  1106. \brief Store-Release Exclusive (32 bit)
  1107. \details Executes a STL exclusive instruction for 32 bit values.
  1108. \param [in] value Value to store
  1109. \param [in] ptr Pointer to location
  1110. \return 0 Function succeeded
  1111. \return 1 Function failed
  1112. */
  1113. #define __STLEX (uint32_t)__builtin_arm_stlex
  1114. #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  1115. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
  1116. /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
  1117. /* ################### Compiler specific Intrinsics ########################### */
  1118. /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
  1119. Access to dedicated SIMD instructions
  1120. @{
  1121. */
  1122. #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
  1123. #define __SADD8 __builtin_arm_sadd8
  1124. #define __QADD8 __builtin_arm_qadd8
  1125. #define __SHADD8 __builtin_arm_shadd8
  1126. #define __UADD8 __builtin_arm_uadd8
  1127. #define __UQADD8 __builtin_arm_uqadd8
  1128. #define __UHADD8 __builtin_arm_uhadd8
  1129. #define __SSUB8 __builtin_arm_ssub8
  1130. #define __QSUB8 __builtin_arm_qsub8
  1131. #define __SHSUB8 __builtin_arm_shsub8
  1132. #define __USUB8 __builtin_arm_usub8
  1133. #define __UQSUB8 __builtin_arm_uqsub8
  1134. #define __UHSUB8 __builtin_arm_uhsub8
  1135. #define __SADD16 __builtin_arm_sadd16
  1136. #define __QADD16 __builtin_arm_qadd16
  1137. #define __SHADD16 __builtin_arm_shadd16
  1138. #define __UADD16 __builtin_arm_uadd16
  1139. #define __UQADD16 __builtin_arm_uqadd16
  1140. #define __UHADD16 __builtin_arm_uhadd16
  1141. #define __SSUB16 __builtin_arm_ssub16
  1142. #define __QSUB16 __builtin_arm_qsub16
  1143. #define __SHSUB16 __builtin_arm_shsub16
  1144. #define __USUB16 __builtin_arm_usub16
  1145. #define __UQSUB16 __builtin_arm_uqsub16
  1146. #define __UHSUB16 __builtin_arm_uhsub16
  1147. #define __SASX __builtin_arm_sasx
  1148. #define __QASX __builtin_arm_qasx
  1149. #define __SHASX __builtin_arm_shasx
  1150. #define __UASX __builtin_arm_uasx
  1151. #define __UQASX __builtin_arm_uqasx
  1152. #define __UHASX __builtin_arm_uhasx
  1153. #define __SSAX __builtin_arm_ssax
  1154. #define __QSAX __builtin_arm_qsax
  1155. #define __SHSAX __builtin_arm_shsax
  1156. #define __USAX __builtin_arm_usax
  1157. #define __UQSAX __builtin_arm_uqsax
  1158. #define __UHSAX __builtin_arm_uhsax
  1159. #define __USAD8 __builtin_arm_usad8
  1160. #define __USADA8 __builtin_arm_usada8
  1161. #define __SSAT16 __builtin_arm_ssat16
  1162. #define __USAT16 __builtin_arm_usat16
  1163. #define __UXTB16 __builtin_arm_uxtb16
  1164. #define __UXTAB16 __builtin_arm_uxtab16
  1165. #define __SXTB16 __builtin_arm_sxtb16
  1166. #define __SXTAB16 __builtin_arm_sxtab16
  1167. #define __SMUAD __builtin_arm_smuad
  1168. #define __SMUADX __builtin_arm_smuadx
  1169. #define __SMLAD __builtin_arm_smlad
  1170. #define __SMLADX __builtin_arm_smladx
  1171. #define __SMLALD __builtin_arm_smlald
  1172. #define __SMLALDX __builtin_arm_smlaldx
  1173. #define __SMUSD __builtin_arm_smusd
  1174. #define __SMUSDX __builtin_arm_smusdx
  1175. #define __SMLSD __builtin_arm_smlsd
  1176. #define __SMLSDX __builtin_arm_smlsdx
  1177. #define __SMLSLD __builtin_arm_smlsld
  1178. #define __SMLSLDX __builtin_arm_smlsldx
  1179. #define __SEL __builtin_arm_sel
  1180. #define __QADD __builtin_arm_qadd
  1181. #define __QSUB __builtin_arm_qsub
  1182. #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
  1183. ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
  1184. #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
  1185. ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
  1186. __STATIC_FORCEINLINE int32_t __SMMLA(int32_t op1, int32_t op2, int32_t op3)
  1187. {
  1188. int32_t result;
  1189. __ASM volatile("smmla %0, %1, %2, %3" : "=r"(result): "r"(op1), "r"(op2), "r"(op3));
  1190. return (result);
  1191. }
  1192. #endif /* (__ARM_FEATURE_DSP == 1) */
  1193. /*@} end of group CMSIS_SIMD_intrinsics */
  1194. #endif /* __CMSIS_ARMCLANG_H */