cmsis_armclang.h 47 KB

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