cmsis_armclang(2).h 46 KB

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