cmsis_armclang.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  1. /**************************************************************************//**
  2. * @file cmsis_armclang.h
  3. * @brief CMSIS compiler armclang (Arm Compiler 6) header file
  4. * @version V5.0.4
  5. * @date 10. January 2018
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. /*lint -esym(9058, IRQn)*/ /* disable MISRA 2012 Rule 2.4 for IRQn */
  25. #ifndef __CMSIS_ARMCLANG_H
  26. #define __CMSIS_ARMCLANG_H
  27. #pragma clang system_header /* treat file as system include file */
  28. #ifndef __ARM_COMPAT_H
  29. #include <arm_compat.h> /* Compatibility header for Arm Compiler 5 intrinsics */
  30. #endif
  31. /* CMSIS compiler specific defines */
  32. #ifndef __ASM
  33. #define __ASM __asm
  34. #endif
  35. #ifndef __INLINE
  36. #define __INLINE __inline
  37. #endif
  38. #ifndef __STATIC_INLINE
  39. #define __STATIC_INLINE static __inline
  40. #endif
  41. #ifndef __STATIC_FORCEINLINE
  42. #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline
  43. #endif
  44. #ifndef __NO_RETURN
  45. #define __NO_RETURN __attribute__((__noreturn__))
  46. #endif
  47. #ifndef __USED
  48. #define __USED __attribute__((used))
  49. #endif
  50. #ifndef __WEAK
  51. #define __WEAK __attribute__((weak))
  52. #endif
  53. #ifndef __PACKED
  54. #define __PACKED __attribute__((packed, aligned(1)))
  55. #endif
  56. #ifndef __PACKED_STRUCT
  57. #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
  58. #endif
  59. #ifndef __PACKED_UNION
  60. #define __PACKED_UNION union __attribute__((packed, aligned(1)))
  61. #endif
  62. #ifndef __UNALIGNED_UINT32 /* deprecated */
  63. #pragma clang diagnostic push
  64. #pragma clang diagnostic ignored "-Wpacked"
  65. /*lint -esym(9058, T_UINT32)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32 */
  66. struct __attribute__((packed)) T_UINT32
  67. {
  68. uint32_t v;
  69. };
  70. #pragma clang diagnostic pop
  71. #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
  72. #endif
  73. #ifndef __UNALIGNED_UINT16_WRITE
  74. #pragma clang diagnostic push
  75. #pragma clang diagnostic ignored "-Wpacked"
  76. /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
  77. __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
  78. #pragma clang diagnostic pop
  79. #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
  80. #endif
  81. #ifndef __UNALIGNED_UINT16_READ
  82. #pragma clang diagnostic push
  83. #pragma clang diagnostic ignored "-Wpacked"
  84. /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
  85. __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
  86. #pragma clang diagnostic pop
  87. #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
  88. #endif
  89. #ifndef __UNALIGNED_UINT32_WRITE
  90. #pragma clang diagnostic push
  91. #pragma clang diagnostic ignored "-Wpacked"
  92. /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
  93. __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
  94. #pragma clang diagnostic pop
  95. #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
  96. #endif
  97. #ifndef __UNALIGNED_UINT32_READ
  98. #pragma clang diagnostic push
  99. #pragma clang diagnostic ignored "-Wpacked"
  100. /*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */
  101. __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
  102. #pragma clang diagnostic pop
  103. #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
  104. #endif
  105. #ifndef __ALIGNED
  106. #define __ALIGNED(x) __attribute__((aligned(x)))
  107. #endif
  108. #ifndef __RESTRICT
  109. #define __RESTRICT __restrict
  110. #endif
  111. /* ########################### Core Function Access ########################### */
  112. /** \ingroup CMSIS_Core_FunctionInterface
  113. \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
  114. @{
  115. */
  116. /**
  117. \brief Enable IRQ Interrupts
  118. \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
  119. Can only be executed in Privileged modes.
  120. */
  121. /* intrinsic void __enable_irq(); see arm_compat.h */
  122. /**
  123. \brief Disable IRQ Interrupts
  124. \details Disables IRQ interrupts by setting the I-bit in the CPSR.
  125. Can only be executed in Privileged modes.
  126. */
  127. /* intrinsic void __disable_irq(); see arm_compat.h */
  128. /**
  129. \brief Get Control Register
  130. \details Returns the content of the Control Register.
  131. \return Control Register value
  132. */
  133. __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
  134. {
  135. uint32_t result;
  136. __ASM volatile("MRS %0, control" : "=r"(result));
  137. return (result);
  138. }
  139. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  140. /**
  141. \brief Get Control Register (non-secure)
  142. \details Returns the content of the non-secure Control Register when in secure mode.
  143. \return non-secure Control Register value
  144. */
  145. __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
  146. {
  147. uint32_t result;
  148. __ASM volatile("MRS %0, control_ns" : "=r"(result));
  149. return (result);
  150. }
  151. #endif
  152. /**
  153. \brief Set Control Register
  154. \details Writes the given value to the Control Register.
  155. \param [in] control Control Register value to set
  156. */
  157. __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
  158. {
  159. __ASM volatile("MSR control, %0" : : "r"(control) : "memory");
  160. }
  161. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  162. /**
  163. \brief Set Control Register (non-secure)
  164. \details Writes the given value to the non-secure Control Register when in secure state.
  165. \param [in] control Control Register value to set
  166. */
  167. __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
  168. {
  169. __ASM volatile("MSR control_ns, %0" : : "r"(control) : "memory");
  170. }
  171. #endif
  172. /**
  173. \brief Get IPSR Register
  174. \details Returns the content of the IPSR Register.
  175. \return IPSR Register value
  176. */
  177. __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
  178. {
  179. uint32_t result;
  180. __ASM volatile("MRS %0, ipsr" : "=r"(result));
  181. return (result);
  182. }
  183. /**
  184. \brief Get APSR Register
  185. \details Returns the content of the APSR Register.
  186. \return APSR Register value
  187. */
  188. __STATIC_FORCEINLINE uint32_t __get_APSR(void)
  189. {
  190. uint32_t result;
  191. __ASM volatile("MRS %0, apsr" : "=r"(result));
  192. return (result);
  193. }
  194. /**
  195. \brief Get xPSR Register
  196. \details Returns the content of the xPSR Register.
  197. \return xPSR Register value
  198. */
  199. __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
  200. {
  201. uint32_t result;
  202. __ASM volatile("MRS %0, xpsr" : "=r"(result));
  203. return (result);
  204. }
  205. /**
  206. \brief Get Process Stack Pointer
  207. \details Returns the current value of the Process Stack Pointer (PSP).
  208. \return PSP Register value
  209. */
  210. __STATIC_FORCEINLINE uint32_t __get_PSP(void)
  211. {
  212. uint32_t result;
  213. __ASM volatile("MRS %0, psp" : "=r"(result));
  214. return (result);
  215. }
  216. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  217. /**
  218. \brief Get Process Stack Pointer (non-secure)
  219. \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
  220. \return PSP Register value
  221. */
  222. __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
  223. {
  224. uint32_t result;
  225. __ASM volatile("MRS %0, psp_ns" : "=r"(result));
  226. return (result);
  227. }
  228. #endif
  229. /**
  230. \brief Set Process Stack Pointer
  231. \details Assigns the given value to the Process Stack Pointer (PSP).
  232. \param [in] topOfProcStack Process Stack Pointer value to set
  233. */
  234. __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
  235. {
  236. __ASM volatile("MSR psp, %0" : : "r"(topOfProcStack) :);
  237. }
  238. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  239. /**
  240. \brief Set Process Stack Pointer (non-secure)
  241. \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
  242. \param [in] topOfProcStack Process Stack Pointer value to set
  243. */
  244. __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
  245. {
  246. __ASM volatile("MSR psp_ns, %0" : : "r"(topOfProcStack) :);
  247. }
  248. #endif
  249. /**
  250. \brief Get Main Stack Pointer
  251. \details Returns the current value of the Main Stack Pointer (MSP).
  252. \return MSP Register value
  253. */
  254. __STATIC_FORCEINLINE uint32_t __get_MSP(void)
  255. {
  256. uint32_t result;
  257. __ASM volatile("MRS %0, msp" : "=r"(result));
  258. return (result);
  259. }
  260. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  261. /**
  262. \brief Get Main Stack Pointer (non-secure)
  263. \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
  264. \return MSP Register value
  265. */
  266. __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
  267. {
  268. uint32_t result;
  269. __ASM volatile("MRS %0, msp_ns" : "=r"(result));
  270. return (result);
  271. }
  272. #endif
  273. /**
  274. \brief Set Main Stack Pointer
  275. \details Assigns the given value to the Main Stack Pointer (MSP).
  276. \param [in] topOfMainStack Main Stack Pointer value to set
  277. */
  278. __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
  279. {
  280. __ASM volatile("MSR msp, %0" : : "r"(topOfMainStack) :);
  281. }
  282. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  283. /**
  284. \brief Set Main Stack Pointer (non-secure)
  285. \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
  286. \param [in] topOfMainStack Main Stack Pointer value to set
  287. */
  288. __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
  289. {
  290. __ASM volatile("MSR msp_ns, %0" : : "r"(topOfMainStack) :);
  291. }
  292. #endif
  293. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  294. /**
  295. \brief Get Stack Pointer (non-secure)
  296. \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
  297. \return SP Register value
  298. */
  299. __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
  300. {
  301. uint32_t result;
  302. __ASM volatile("MRS %0, sp_ns" : "=r"(result));
  303. return (result);
  304. }
  305. /**
  306. \brief Set Stack Pointer (non-secure)
  307. \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
  308. \param [in] topOfStack Stack Pointer value to set
  309. */
  310. __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
  311. {
  312. __ASM volatile("MSR sp_ns, %0" : : "r"(topOfStack) :);
  313. }
  314. #endif
  315. /**
  316. \brief Get Priority Mask
  317. \details Returns the current state of the priority mask bit from the Priority Mask Register.
  318. \return Priority Mask value
  319. */
  320. __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
  321. {
  322. uint32_t result;
  323. __ASM volatile("MRS %0, primask" : "=r"(result));
  324. return (result);
  325. }
  326. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  327. /**
  328. \brief Get Priority Mask (non-secure)
  329. \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
  330. \return Priority Mask value
  331. */
  332. __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
  333. {
  334. uint32_t result;
  335. __ASM volatile("MRS %0, primask_ns" : "=r"(result));
  336. return (result);
  337. }
  338. #endif
  339. /**
  340. \brief Set Priority Mask
  341. \details Assigns the given value to the Priority Mask Register.
  342. \param [in] priMask Priority Mask
  343. */
  344. __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
  345. {
  346. __ASM volatile("MSR primask, %0" : : "r"(priMask) : "memory");
  347. }
  348. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  349. /**
  350. \brief Set Priority Mask (non-secure)
  351. \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
  352. \param [in] priMask Priority Mask
  353. */
  354. __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
  355. {
  356. __ASM volatile("MSR primask_ns, %0" : : "r"(priMask) : "memory");
  357. }
  358. #endif
  359. #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  360. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  361. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
  362. /**
  363. \brief Enable FIQ
  364. \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
  365. Can only be executed in Privileged modes.
  366. */
  367. #define __enable_fault_irq __enable_fiq /* see arm_compat.h */
  368. /**
  369. \brief Disable FIQ
  370. \details Disables FIQ interrupts by setting the F-bit in the CPSR.
  371. Can only be executed in Privileged modes.
  372. */
  373. #define __disable_fault_irq __disable_fiq /* see arm_compat.h */
  374. /**
  375. \brief Get Base Priority
  376. \details Returns the current value of the Base Priority register.
  377. \return Base Priority register value
  378. */
  379. __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
  380. {
  381. uint32_t result;
  382. __ASM volatile("MRS %0, basepri" : "=r"(result));
  383. return (result);
  384. }
  385. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  386. /**
  387. \brief Get Base Priority (non-secure)
  388. \details Returns the current value of the non-secure Base Priority register when in secure state.
  389. \return Base Priority register value
  390. */
  391. __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
  392. {
  393. uint32_t result;
  394. __ASM volatile("MRS %0, basepri_ns" : "=r"(result));
  395. return (result);
  396. }
  397. #endif
  398. /**
  399. \brief Set Base Priority
  400. \details Assigns the given value to the Base Priority register.
  401. \param [in] basePri Base Priority value to set
  402. */
  403. __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
  404. {
  405. __ASM volatile("MSR basepri, %0" : : "r"(basePri) : "memory");
  406. }
  407. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  408. /**
  409. \brief Set Base Priority (non-secure)
  410. \details Assigns the given value to the non-secure Base Priority register when in secure state.
  411. \param [in] basePri Base Priority value to set
  412. */
  413. __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
  414. {
  415. __ASM volatile("MSR basepri_ns, %0" : : "r"(basePri) : "memory");
  416. }
  417. #endif
  418. /**
  419. \brief Set Base Priority with condition
  420. \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
  421. or the new value increases the BASEPRI priority level.
  422. \param [in] basePri Base Priority value to set
  423. */
  424. __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
  425. {
  426. __ASM volatile("MSR basepri_max, %0" : : "r"(basePri) : "memory");
  427. }
  428. /**
  429. \brief Get Fault Mask
  430. \details Returns the current value of the Fault Mask register.
  431. \return Fault Mask register value
  432. */
  433. __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
  434. {
  435. uint32_t result;
  436. __ASM volatile("MRS %0, faultmask" : "=r"(result));
  437. return (result);
  438. }
  439. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  440. /**
  441. \brief Get Fault Mask (non-secure)
  442. \details Returns the current value of the non-secure Fault Mask register when in secure state.
  443. \return Fault Mask register value
  444. */
  445. __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
  446. {
  447. uint32_t result;
  448. __ASM volatile("MRS %0, faultmask_ns" : "=r"(result));
  449. return (result);
  450. }
  451. #endif
  452. /**
  453. \brief Set Fault Mask
  454. \details Assigns the given value to the Fault Mask register.
  455. \param [in] faultMask Fault Mask value to set
  456. */
  457. __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
  458. {
  459. __ASM volatile("MSR faultmask, %0" : : "r"(faultMask) : "memory");
  460. }
  461. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  462. /**
  463. \brief Set Fault Mask (non-secure)
  464. \details Assigns the given value to the non-secure Fault Mask register when in secure state.
  465. \param [in] faultMask Fault Mask value to set
  466. */
  467. __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
  468. {
  469. __ASM volatile("MSR faultmask_ns, %0" : : "r"(faultMask) : "memory");
  470. }
  471. #endif
  472. #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  473. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  474. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
  475. #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  476. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
  477. /**
  478. \brief Get Process Stack Pointer Limit
  479. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  480. Stack Pointer Limit register hence zero is returned always in non-secure
  481. mode.
  482. \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
  483. \return PSPLIM Register value
  484. */
  485. __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
  486. {
  487. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  488. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  489. // without main extensions, the non-secure PSPLIM is RAZ/WI
  490. return 0U;
  491. #else
  492. uint32_t result;
  493. __ASM volatile("MRS %0, psplim" : "=r"(result));
  494. return result;
  495. #endif
  496. }
  497. #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
  498. /**
  499. \brief Get Process Stack Pointer Limit (non-secure)
  500. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  501. Stack Pointer Limit register hence zero is returned always in non-secure
  502. mode.
  503. \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
  504. \return PSPLIM Register value
  505. */
  506. __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
  507. {
  508. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
  509. // without main extensions, the non-secure PSPLIM is RAZ/WI
  510. return 0U;
  511. #else
  512. uint32_t result;
  513. __ASM volatile("MRS %0, psplim_ns" : "=r"(result));
  514. return result;
  515. #endif
  516. }
  517. #endif
  518. /**
  519. \brief Set Process Stack Pointer Limit
  520. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  521. Stack Pointer Limit register hence the write is silently ignored in non-secure
  522. mode.
  523. \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
  524. \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
  525. */
  526. __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
  527. {
  528. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  529. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  530. // without main extensions, the non-secure PSPLIM is RAZ/WI
  531. (void)ProcStackPtrLimit;
  532. #else
  533. __ASM volatile("MSR psplim, %0" : : "r"(ProcStackPtrLimit));
  534. #endif
  535. }
  536. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  537. /**
  538. \brief Set Process Stack Pointer (non-secure)
  539. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  540. Stack Pointer Limit register hence the write is silently ignored in non-secure
  541. mode.
  542. \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
  543. \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
  544. */
  545. __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
  546. {
  547. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
  548. // without main extensions, the non-secure PSPLIM is RAZ/WI
  549. (void)ProcStackPtrLimit;
  550. #else
  551. __ASM volatile("MSR psplim_ns, %0\n" : : "r"(ProcStackPtrLimit));
  552. #endif
  553. }
  554. #endif
  555. /**
  556. \brief Get Main Stack Pointer Limit
  557. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  558. Stack Pointer Limit register hence zero is returned always.
  559. \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
  560. \return MSPLIM Register value
  561. */
  562. __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
  563. {
  564. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  565. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  566. // without main extensions, the non-secure MSPLIM is RAZ/WI
  567. return 0U;
  568. #else
  569. uint32_t result;
  570. __ASM volatile("MRS %0, msplim" : "=r"(result));
  571. return result;
  572. #endif
  573. }
  574. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  575. /**
  576. \brief Get Main Stack Pointer Limit (non-secure)
  577. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  578. Stack Pointer Limit register hence zero is returned always.
  579. \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
  580. \return MSPLIM Register value
  581. */
  582. __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
  583. {
  584. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
  585. // without main extensions, the non-secure MSPLIM is RAZ/WI
  586. return 0U;
  587. #else
  588. uint32_t result;
  589. __ASM volatile("MRS %0, msplim_ns" : "=r"(result));
  590. return result;
  591. #endif
  592. }
  593. #endif
  594. /**
  595. \brief Set Main Stack Pointer Limit
  596. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  597. Stack Pointer Limit register hence the write is silently ignored.
  598. \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
  599. \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
  600. */
  601. __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
  602. {
  603. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
  604. (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
  605. // without main extensions, the non-secure MSPLIM is RAZ/WI
  606. (void)MainStackPtrLimit;
  607. #else
  608. __ASM volatile("MSR msplim, %0" : : "r"(MainStackPtrLimit));
  609. #endif
  610. }
  611. #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
  612. /**
  613. \brief Set Main Stack Pointer Limit (non-secure)
  614. Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
  615. Stack Pointer Limit register hence the write is silently ignored.
  616. \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
  617. \param [in] MainStackPtrLimit Main Stack Pointer value to set
  618. */
  619. __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
  620. {
  621. #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
  622. // without main extensions, the non-secure MSPLIM is RAZ/WI
  623. (void)MainStackPtrLimit;
  624. #else
  625. __ASM volatile("MSR msplim_ns, %0" : : "r"(MainStackPtrLimit));
  626. #endif
  627. }
  628. #endif
  629. #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  630. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
  631. /**
  632. \brief Get FPSCR
  633. \details Returns the current value of the Floating Point Status/Control register.
  634. \return Floating Point Status/Control register value
  635. */
  636. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
  637. (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
  638. #define __get_FPSCR (uint32_t)__builtin_arm_get_fpscr
  639. #else
  640. #define __get_FPSCR() ((uint32_t)0U)
  641. #endif
  642. /**
  643. \brief Set FPSCR
  644. \details Assigns the given value to the Floating Point Status/Control register.
  645. \param [in] fpscr Floating Point Status/Control value to set
  646. */
  647. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
  648. (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
  649. #define __set_FPSCR __builtin_arm_set_fpscr
  650. #else
  651. #define __set_FPSCR(x) ((void)(x))
  652. #endif
  653. /*@} end of CMSIS_Core_RegAccFunctions */
  654. /* ########################## Core Instruction Access ######################### */
  655. /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
  656. Access to dedicated instructions
  657. @{
  658. */
  659. /* Define macros for porting to both thumb1 and thumb2.
  660. * For thumb1, use low register (r0-r7), specified by constraint "l"
  661. * Otherwise, use general registers, specified by constraint "r" */
  662. #if defined (__thumb__) && !defined (__thumb2__)
  663. #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
  664. #define __CMSIS_GCC_USE_REG(r) "l" (r)
  665. #else
  666. #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
  667. #define __CMSIS_GCC_USE_REG(r) "r" (r)
  668. #endif
  669. /**
  670. \brief No Operation
  671. \details No Operation does nothing. This instruction can be used for code alignment purposes.
  672. */
  673. #define __NOP __builtin_arm_nop
  674. /**
  675. \brief Wait For Interrupt
  676. \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
  677. */
  678. #define __WFI __builtin_arm_wfi
  679. /**
  680. \brief Wait For Event
  681. \details Wait For Event is a hint instruction that permits the processor to enter
  682. a low-power state until one of a number of events occurs.
  683. */
  684. #define __WFE __builtin_arm_wfe
  685. /**
  686. \brief Send Event
  687. \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
  688. */
  689. #define __SEV __builtin_arm_sev
  690. /**
  691. \brief Instruction Synchronization Barrier
  692. \details Instruction Synchronization Barrier flushes the pipeline in the processor,
  693. so that all instructions following the ISB are fetched from cache or memory,
  694. after the instruction has been completed.
  695. */
  696. #define __ISB() __builtin_arm_isb(0xF);
  697. /**
  698. \brief Data Synchronization Barrier
  699. \details Acts as a special kind of Data Memory Barrier.
  700. It completes when all explicit memory accesses before this instruction complete.
  701. */
  702. #define __DSB() __builtin_arm_dsb(0xF);
  703. /**
  704. \brief Data Memory Barrier
  705. \details Ensures the apparent order of the explicit memory operations before
  706. and after the instruction, without ensuring their completion.
  707. */
  708. #define __DMB() __builtin_arm_dmb(0xF);
  709. /**
  710. \brief Reverse byte order (32 bit)
  711. \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
  712. \param [in] value Value to reverse
  713. \return Reversed value
  714. */
  715. #define __REV(value) __builtin_bswap32(value)
  716. /**
  717. \brief Reverse byte order (16 bit)
  718. \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
  719. \param [in] value Value to reverse
  720. \return Reversed value
  721. */
  722. #define __REV16(value) __ROR(__REV(value), 16)
  723. /**
  724. \brief Reverse byte order (16 bit)
  725. \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
  726. \param [in] value Value to reverse
  727. \return Reversed value
  728. */
  729. #define __REVSH(value) (int16_t)__builtin_bswap16(value)
  730. /**
  731. \brief Rotate Right in unsigned value (32 bit)
  732. \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
  733. \param [in] op1 Value to rotate
  734. \param [in] op2 Number of Bits to rotate
  735. \return Rotated value
  736. */
  737. __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
  738. {
  739. op2 %= 32U;
  740. if (op2 == 0U)
  741. {
  742. return op1;
  743. }
  744. return (op1 >> op2) | (op1 << (32U - op2));
  745. }
  746. /**
  747. \brief Breakpoint
  748. \details Causes the processor to enter Debug state.
  749. Debug tools can use this to investigate system state when the instruction at a particular address is reached.
  750. \param [in] value is ignored by the processor.
  751. If required, a debugger can use it to store additional information about the breakpoint.
  752. */
  753. #define __BKPT(value) __ASM volatile ("bkpt "#value)
  754. /**
  755. \brief Reverse bit order of value
  756. \details Reverses the bit order of the given value.
  757. \param [in] value Value to reverse
  758. \return Reversed value
  759. */
  760. #define __RBIT __builtin_arm_rbit
  761. /**
  762. \brief Count leading zeros
  763. \details Counts the number of leading zeros of a data value.
  764. \param [in] value Value to count the leading zeros
  765. \return number of leading zeros in value
  766. */
  767. #define __CLZ (uint8_t)__builtin_clz
  768. #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  769. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  770. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  771. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
  772. /**
  773. \brief LDR Exclusive (8 bit)
  774. \details Executes a exclusive LDR instruction for 8 bit value.
  775. \param [in] ptr Pointer to data
  776. \return value of type uint8_t at (*ptr)
  777. */
  778. #define __LDREXB (uint8_t)__builtin_arm_ldrex
  779. /**
  780. \brief LDR Exclusive (16 bit)
  781. \details Executes a exclusive LDR instruction for 16 bit values.
  782. \param [in] ptr Pointer to data
  783. \return value of type uint16_t at (*ptr)
  784. */
  785. #define __LDREXH (uint16_t)__builtin_arm_ldrex
  786. /**
  787. \brief LDR Exclusive (32 bit)
  788. \details Executes a exclusive LDR instruction for 32 bit values.
  789. \param [in] ptr Pointer to data
  790. \return value of type uint32_t at (*ptr)
  791. */
  792. #define __LDREXW (uint32_t)__builtin_arm_ldrex
  793. /**
  794. \brief STR Exclusive (8 bit)
  795. \details Executes a exclusive STR instruction for 8 bit values.
  796. \param [in] value Value to store
  797. \param [in] ptr Pointer to location
  798. \return 0 Function succeeded
  799. \return 1 Function failed
  800. */
  801. #define __STREXB (uint32_t)__builtin_arm_strex
  802. /**
  803. \brief STR Exclusive (16 bit)
  804. \details Executes a exclusive STR instruction for 16 bit values.
  805. \param [in] value Value to store
  806. \param [in] ptr Pointer to location
  807. \return 0 Function succeeded
  808. \return 1 Function failed
  809. */
  810. #define __STREXH (uint32_t)__builtin_arm_strex
  811. /**
  812. \brief STR Exclusive (32 bit)
  813. \details Executes a exclusive STR instruction for 32 bit values.
  814. \param [in] value Value to store
  815. \param [in] ptr Pointer to location
  816. \return 0 Function succeeded
  817. \return 1 Function failed
  818. */
  819. #define __STREXW (uint32_t)__builtin_arm_strex
  820. /**
  821. \brief Remove the exclusive lock
  822. \details Removes the exclusive lock which is created by LDREX.
  823. */
  824. #define __CLREX __builtin_arm_clrex
  825. #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  826. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  827. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  828. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
  829. #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  830. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  831. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
  832. /**
  833. \brief Signed Saturate
  834. \details Saturates a signed value.
  835. \param [in] value Value to be saturated
  836. \param [in] sat Bit position to saturate to (1..32)
  837. \return Saturated value
  838. */
  839. #define __SSAT __builtin_arm_ssat
  840. /**
  841. \brief Unsigned Saturate
  842. \details Saturates an unsigned value.
  843. \param [in] value Value to be saturated
  844. \param [in] sat Bit position to saturate to (0..31)
  845. \return Saturated value
  846. */
  847. #define __USAT __builtin_arm_usat
  848. /**
  849. \brief Rotate Right with Extend (32 bit)
  850. \details Moves each bit of a bitstring right by one bit.
  851. The carry input is shifted in at the left end of the bitstring.
  852. \param [in] value Value to rotate
  853. \return Rotated value
  854. */
  855. __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
  856. {
  857. uint32_t result;
  858. __ASM volatile("rrx %0, %1" : __CMSIS_GCC_OUT_REG(result) : __CMSIS_GCC_USE_REG(value));
  859. return (result);
  860. }
  861. /**
  862. \brief LDRT Unprivileged (8 bit)
  863. \details Executes a Unprivileged LDRT instruction for 8 bit value.
  864. \param [in] ptr Pointer to data
  865. \return value of type uint8_t at (*ptr)
  866. */
  867. __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
  868. {
  869. uint32_t result;
  870. __ASM volatile("ldrbt %0, %1" : "=r"(result) : "Q"(*ptr));
  871. return ((uint8_t) result); /* Add explicit type cast here */
  872. }
  873. /**
  874. \brief LDRT Unprivileged (16 bit)
  875. \details Executes a Unprivileged LDRT instruction for 16 bit values.
  876. \param [in] ptr Pointer to data
  877. \return value of type uint16_t at (*ptr)
  878. */
  879. __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
  880. {
  881. uint32_t result;
  882. __ASM volatile("ldrht %0, %1" : "=r"(result) : "Q"(*ptr));
  883. return ((uint16_t) result); /* Add explicit type cast here */
  884. }
  885. /**
  886. \brief LDRT Unprivileged (32 bit)
  887. \details Executes a Unprivileged LDRT instruction for 32 bit values.
  888. \param [in] ptr Pointer to data
  889. \return value of type uint32_t at (*ptr)
  890. */
  891. __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
  892. {
  893. uint32_t result;
  894. __ASM volatile("ldrt %0, %1" : "=r"(result) : "Q"(*ptr));
  895. return (result);
  896. }
  897. /**
  898. \brief STRT Unprivileged (8 bit)
  899. \details Executes a Unprivileged STRT instruction for 8 bit values.
  900. \param [in] value Value to store
  901. \param [in] ptr Pointer to location
  902. */
  903. __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
  904. {
  905. __ASM volatile("strbt %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  906. }
  907. /**
  908. \brief STRT Unprivileged (16 bit)
  909. \details Executes a Unprivileged STRT instruction for 16 bit values.
  910. \param [in] value Value to store
  911. \param [in] ptr Pointer to location
  912. */
  913. __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
  914. {
  915. __ASM volatile("strht %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  916. }
  917. /**
  918. \brief STRT Unprivileged (32 bit)
  919. \details Executes a Unprivileged STRT instruction for 32 bit values.
  920. \param [in] value Value to store
  921. \param [in] ptr Pointer to location
  922. */
  923. __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
  924. {
  925. __ASM volatile("strt %1, %0" : "=Q"(*ptr) : "r"(value));
  926. }
  927. #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  928. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  929. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
  930. /**
  931. \brief Signed Saturate
  932. \details Saturates a signed value.
  933. \param [in] value Value to be saturated
  934. \param [in] sat Bit position to saturate to (1..32)
  935. \return Saturated value
  936. */
  937. __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
  938. {
  939. if ((sat >= 1U) && (sat <= 32U))
  940. {
  941. const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
  942. const int32_t min = -1 - max ;
  943. if (val > max)
  944. {
  945. return max;
  946. }
  947. else if (val < min)
  948. {
  949. return min;
  950. }
  951. }
  952. return val;
  953. }
  954. /**
  955. \brief Unsigned Saturate
  956. \details Saturates an unsigned value.
  957. \param [in] value Value to be saturated
  958. \param [in] sat Bit position to saturate to (0..31)
  959. \return Saturated value
  960. */
  961. __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
  962. {
  963. if (sat <= 31U)
  964. {
  965. const uint32_t max = ((1U << sat) - 1U);
  966. if (val > (int32_t)max)
  967. {
  968. return max;
  969. }
  970. else if (val < 0)
  971. {
  972. return 0U;
  973. }
  974. }
  975. return (uint32_t)val;
  976. }
  977. #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  978. (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
  979. (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
  980. #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  981. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
  982. /**
  983. \brief Load-Acquire (8 bit)
  984. \details Executes a LDAB instruction for 8 bit value.
  985. \param [in] ptr Pointer to data
  986. \return value of type uint8_t at (*ptr)
  987. */
  988. __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
  989. {
  990. uint32_t result;
  991. __ASM volatile("ldab %0, %1" : "=r"(result) : "Q"(*ptr));
  992. return ((uint8_t) result);
  993. }
  994. /**
  995. \brief Load-Acquire (16 bit)
  996. \details Executes a LDAH instruction for 16 bit values.
  997. \param [in] ptr Pointer to data
  998. \return value of type uint16_t at (*ptr)
  999. */
  1000. __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
  1001. {
  1002. uint32_t result;
  1003. __ASM volatile("ldah %0, %1" : "=r"(result) : "Q"(*ptr));
  1004. return ((uint16_t) result);
  1005. }
  1006. /**
  1007. \brief Load-Acquire (32 bit)
  1008. \details Executes a LDA instruction for 32 bit values.
  1009. \param [in] ptr Pointer to data
  1010. \return value of type uint32_t at (*ptr)
  1011. */
  1012. __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
  1013. {
  1014. uint32_t result;
  1015. __ASM volatile("lda %0, %1" : "=r"(result) : "Q"(*ptr));
  1016. return (result);
  1017. }
  1018. /**
  1019. \brief Store-Release (8 bit)
  1020. \details Executes a STLB instruction for 8 bit values.
  1021. \param [in] value Value to store
  1022. \param [in] ptr Pointer to location
  1023. */
  1024. __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
  1025. {
  1026. __ASM volatile("stlb %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  1027. }
  1028. /**
  1029. \brief Store-Release (16 bit)
  1030. \details Executes a STLH instruction for 16 bit values.
  1031. \param [in] value Value to store
  1032. \param [in] ptr Pointer to location
  1033. */
  1034. __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
  1035. {
  1036. __ASM volatile("stlh %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  1037. }
  1038. /**
  1039. \brief Store-Release (32 bit)
  1040. \details Executes a STL instruction for 32 bit values.
  1041. \param [in] value Value to store
  1042. \param [in] ptr Pointer to location
  1043. */
  1044. __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
  1045. {
  1046. __ASM volatile("stl %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value));
  1047. }
  1048. /**
  1049. \brief Load-Acquire Exclusive (8 bit)
  1050. \details Executes a LDAB exclusive instruction for 8 bit value.
  1051. \param [in] ptr Pointer to data
  1052. \return value of type uint8_t at (*ptr)
  1053. */
  1054. #define __LDAEXB (uint8_t)__builtin_arm_ldaex
  1055. /**
  1056. \brief Load-Acquire Exclusive (16 bit)
  1057. \details Executes a LDAH exclusive instruction for 16 bit values.
  1058. \param [in] ptr Pointer to data
  1059. \return value of type uint16_t at (*ptr)
  1060. */
  1061. #define __LDAEXH (uint16_t)__builtin_arm_ldaex
  1062. /**
  1063. \brief Load-Acquire Exclusive (32 bit)
  1064. \details Executes a LDA exclusive instruction for 32 bit values.
  1065. \param [in] ptr Pointer to data
  1066. \return value of type uint32_t at (*ptr)
  1067. */
  1068. #define __LDAEX (uint32_t)__builtin_arm_ldaex
  1069. /**
  1070. \brief Store-Release Exclusive (8 bit)
  1071. \details Executes a STLB exclusive instruction for 8 bit values.
  1072. \param [in] value Value to store
  1073. \param [in] ptr Pointer to location
  1074. \return 0 Function succeeded
  1075. \return 1 Function failed
  1076. */
  1077. #define __STLEXB (uint32_t)__builtin_arm_stlex
  1078. /**
  1079. \brief Store-Release Exclusive (16 bit)
  1080. \details Executes a STLH exclusive instruction for 16 bit values.
  1081. \param [in] value Value to store
  1082. \param [in] ptr Pointer to location
  1083. \return 0 Function succeeded
  1084. \return 1 Function failed
  1085. */
  1086. #define __STLEXH (uint32_t)__builtin_arm_stlex
  1087. /**
  1088. \brief Store-Release Exclusive (32 bit)
  1089. \details Executes a STL exclusive instruction for 32 bit values.
  1090. \param [in] value Value to store
  1091. \param [in] ptr Pointer to location
  1092. \return 0 Function succeeded
  1093. \return 1 Function failed
  1094. */
  1095. #define __STLEX (uint32_t)__builtin_arm_stlex
  1096. #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
  1097. (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
  1098. /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
  1099. /* ################### Compiler specific Intrinsics ########################### */
  1100. /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
  1101. Access to dedicated SIMD instructions
  1102. @{
  1103. */
  1104. #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
  1105. __STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
  1106. {
  1107. uint32_t result;
  1108. __ASM volatile("sadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1109. return (result);
  1110. }
  1111. __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
  1112. {
  1113. uint32_t result;
  1114. __ASM volatile("qadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1115. return (result);
  1116. }
  1117. __STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
  1118. {
  1119. uint32_t result;
  1120. __ASM volatile("shadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1121. return (result);
  1122. }
  1123. __STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
  1124. {
  1125. uint32_t result;
  1126. __ASM volatile("uadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1127. return (result);
  1128. }
  1129. __STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
  1130. {
  1131. uint32_t result;
  1132. __ASM volatile("uqadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1133. return (result);
  1134. }
  1135. __STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
  1136. {
  1137. uint32_t result;
  1138. __ASM volatile("uhadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1139. return (result);
  1140. }
  1141. __STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
  1142. {
  1143. uint32_t result;
  1144. __ASM volatile("ssub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1145. return (result);
  1146. }
  1147. __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
  1148. {
  1149. uint32_t result;
  1150. __ASM volatile("qsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1151. return (result);
  1152. }
  1153. __STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
  1154. {
  1155. uint32_t result;
  1156. __ASM volatile("shsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1157. return (result);
  1158. }
  1159. __STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
  1160. {
  1161. uint32_t result;
  1162. __ASM volatile("usub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1163. return (result);
  1164. }
  1165. __STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
  1166. {
  1167. uint32_t result;
  1168. __ASM volatile("uqsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1169. return (result);
  1170. }
  1171. __STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
  1172. {
  1173. uint32_t result;
  1174. __ASM volatile("uhsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1175. return (result);
  1176. }
  1177. __STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
  1178. {
  1179. uint32_t result;
  1180. __ASM volatile("sadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1181. return (result);
  1182. }
  1183. __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
  1184. {
  1185. uint32_t result;
  1186. __ASM volatile("qadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1187. return (result);
  1188. }
  1189. __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
  1190. {
  1191. uint32_t result;
  1192. __ASM volatile("shadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1193. return (result);
  1194. }
  1195. __STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
  1196. {
  1197. uint32_t result;
  1198. __ASM volatile("uadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1199. return (result);
  1200. }
  1201. __STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
  1202. {
  1203. uint32_t result;
  1204. __ASM volatile("uqadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1205. return (result);
  1206. }
  1207. __STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
  1208. {
  1209. uint32_t result;
  1210. __ASM volatile("uhadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1211. return (result);
  1212. }
  1213. __STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
  1214. {
  1215. uint32_t result;
  1216. __ASM volatile("ssub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1217. return (result);
  1218. }
  1219. __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
  1220. {
  1221. uint32_t result;
  1222. __ASM volatile("qsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1223. return (result);
  1224. }
  1225. __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
  1226. {
  1227. uint32_t result;
  1228. __ASM volatile("shsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1229. return (result);
  1230. }
  1231. __STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
  1232. {
  1233. uint32_t result;
  1234. __ASM volatile("usub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1235. return (result);
  1236. }
  1237. __STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
  1238. {
  1239. uint32_t result;
  1240. __ASM volatile("uqsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1241. return (result);
  1242. }
  1243. __STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
  1244. {
  1245. uint32_t result;
  1246. __ASM volatile("uhsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1247. return (result);
  1248. }
  1249. __STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
  1250. {
  1251. uint32_t result;
  1252. __ASM volatile("sasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1253. return (result);
  1254. }
  1255. __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
  1256. {
  1257. uint32_t result;
  1258. __ASM volatile("qasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1259. return (result);
  1260. }
  1261. __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
  1262. {
  1263. uint32_t result;
  1264. __ASM volatile("shasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1265. return (result);
  1266. }
  1267. __STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
  1268. {
  1269. uint32_t result;
  1270. __ASM volatile("uasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1271. return (result);
  1272. }
  1273. __STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
  1274. {
  1275. uint32_t result;
  1276. __ASM volatile("uqasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1277. return (result);
  1278. }
  1279. __STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
  1280. {
  1281. uint32_t result;
  1282. __ASM volatile("uhasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1283. return (result);
  1284. }
  1285. __STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
  1286. {
  1287. uint32_t result;
  1288. __ASM volatile("ssax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1289. return (result);
  1290. }
  1291. __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
  1292. {
  1293. uint32_t result;
  1294. __ASM volatile("qsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1295. return (result);
  1296. }
  1297. __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
  1298. {
  1299. uint32_t result;
  1300. __ASM volatile("shsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1301. return (result);
  1302. }
  1303. __STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
  1304. {
  1305. uint32_t result;
  1306. __ASM volatile("usax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1307. return (result);
  1308. }
  1309. __STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
  1310. {
  1311. uint32_t result;
  1312. __ASM volatile("uqsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1313. return (result);
  1314. }
  1315. __STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
  1316. {
  1317. uint32_t result;
  1318. __ASM volatile("uhsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1319. return (result);
  1320. }
  1321. __STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
  1322. {
  1323. uint32_t result;
  1324. __ASM volatile("usad8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1325. return (result);
  1326. }
  1327. __STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
  1328. {
  1329. uint32_t result;
  1330. __ASM volatile("usada8 %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3));
  1331. return (result);
  1332. }
  1333. #define __SSAT16(ARG1,ARG2) \
  1334. ({ \
  1335. int32_t __RES, __ARG1 = (ARG1); \
  1336. __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
  1337. __RES; \
  1338. })
  1339. #define __USAT16(ARG1,ARG2) \
  1340. ({ \
  1341. uint32_t __RES, __ARG1 = (ARG1); \
  1342. __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
  1343. __RES; \
  1344. })
  1345. __STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1)
  1346. {
  1347. uint32_t result;
  1348. __ASM volatile("uxtb16 %0, %1" : "=r"(result) : "r"(op1));
  1349. return (result);
  1350. }
  1351. __STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
  1352. {
  1353. uint32_t result;
  1354. __ASM volatile("uxtab16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1355. return (result);
  1356. }
  1357. __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
  1358. {
  1359. uint32_t result;
  1360. __ASM volatile("sxtb16 %0, %1" : "=r"(result) : "r"(op1));
  1361. return (result);
  1362. }
  1363. __STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
  1364. {
  1365. uint32_t result;
  1366. __ASM volatile("sxtab16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1367. return (result);
  1368. }
  1369. __STATIC_FORCEINLINE uint32_t __SMUAD(uint32_t op1, uint32_t op2)
  1370. {
  1371. uint32_t result;
  1372. __ASM volatile("smuad %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1373. return (result);
  1374. }
  1375. __STATIC_FORCEINLINE uint32_t __SMUADX(uint32_t op1, uint32_t op2)
  1376. {
  1377. uint32_t result;
  1378. __ASM volatile("smuadx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1379. return (result);
  1380. }
  1381. __STATIC_FORCEINLINE uint32_t __SMLAD(uint32_t op1, uint32_t op2, uint32_t op3)
  1382. {
  1383. uint32_t result;
  1384. __ASM volatile("smlad %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3));
  1385. return (result);
  1386. }
  1387. __STATIC_FORCEINLINE uint32_t __SMLADX(uint32_t op1, uint32_t op2, uint32_t op3)
  1388. {
  1389. uint32_t result;
  1390. __ASM volatile("smladx %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3));
  1391. return (result);
  1392. }
  1393. __STATIC_FORCEINLINE uint64_t __SMLALD(uint32_t op1, uint32_t op2, uint64_t acc)
  1394. {
  1395. union llreg_u
  1396. {
  1397. uint32_t w32[2];
  1398. uint64_t w64;
  1399. } llr;
  1400. llr.w64 = acc;
  1401. #ifndef __ARMEB__ /* Little endian */
  1402. __ASM volatile("smlald %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1]));
  1403. #else /* Big endian */
  1404. __ASM volatile("smlald %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0]));
  1405. #endif
  1406. return (llr.w64);
  1407. }
  1408. __STATIC_FORCEINLINE uint64_t __SMLALDX(uint32_t op1, uint32_t op2, uint64_t acc)
  1409. {
  1410. union llreg_u
  1411. {
  1412. uint32_t w32[2];
  1413. uint64_t w64;
  1414. } llr;
  1415. llr.w64 = acc;
  1416. #ifndef __ARMEB__ /* Little endian */
  1417. __ASM volatile("smlaldx %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1]));
  1418. #else /* Big endian */
  1419. __ASM volatile("smlaldx %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0]));
  1420. #endif
  1421. return (llr.w64);
  1422. }
  1423. __STATIC_FORCEINLINE uint32_t __SMUSD(uint32_t op1, uint32_t op2)
  1424. {
  1425. uint32_t result;
  1426. __ASM volatile("smusd %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1427. return (result);
  1428. }
  1429. __STATIC_FORCEINLINE uint32_t __SMUSDX(uint32_t op1, uint32_t op2)
  1430. {
  1431. uint32_t result;
  1432. __ASM volatile("smusdx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1433. return (result);
  1434. }
  1435. __STATIC_FORCEINLINE uint32_t __SMLSD(uint32_t op1, uint32_t op2, uint32_t op3)
  1436. {
  1437. uint32_t result;
  1438. __ASM volatile("smlsd %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3));
  1439. return (result);
  1440. }
  1441. __STATIC_FORCEINLINE uint32_t __SMLSDX(uint32_t op1, uint32_t op2, uint32_t op3)
  1442. {
  1443. uint32_t result;
  1444. __ASM volatile("smlsdx %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3));
  1445. return (result);
  1446. }
  1447. __STATIC_FORCEINLINE uint64_t __SMLSLD(uint32_t op1, uint32_t op2, uint64_t acc)
  1448. {
  1449. union llreg_u
  1450. {
  1451. uint32_t w32[2];
  1452. uint64_t w64;
  1453. } llr;
  1454. llr.w64 = acc;
  1455. #ifndef __ARMEB__ /* Little endian */
  1456. __ASM volatile("smlsld %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1]));
  1457. #else /* Big endian */
  1458. __ASM volatile("smlsld %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0]));
  1459. #endif
  1460. return (llr.w64);
  1461. }
  1462. __STATIC_FORCEINLINE uint64_t __SMLSLDX(uint32_t op1, uint32_t op2, uint64_t acc)
  1463. {
  1464. union llreg_u
  1465. {
  1466. uint32_t w32[2];
  1467. uint64_t w64;
  1468. } llr;
  1469. llr.w64 = acc;
  1470. #ifndef __ARMEB__ /* Little endian */
  1471. __ASM volatile("smlsldx %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1]));
  1472. #else /* Big endian */
  1473. __ASM volatile("smlsldx %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0]));
  1474. #endif
  1475. return (llr.w64);
  1476. }
  1477. __STATIC_FORCEINLINE uint32_t __SEL(uint32_t op1, uint32_t op2)
  1478. {
  1479. uint32_t result;
  1480. __ASM volatile("sel %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1481. return (result);
  1482. }
  1483. __STATIC_FORCEINLINE int32_t __QADD(int32_t op1, int32_t op2)
  1484. {
  1485. int32_t result;
  1486. __ASM volatile("qadd %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1487. return (result);
  1488. }
  1489. __STATIC_FORCEINLINE int32_t __QSUB(int32_t op1, int32_t op2)
  1490. {
  1491. int32_t result;
  1492. __ASM volatile("qsub %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2));
  1493. return (result);
  1494. }
  1495. #if 0
  1496. #define __PKHBT(ARG1,ARG2,ARG3) \
  1497. ({ \
  1498. uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
  1499. __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
  1500. __RES; \
  1501. })
  1502. #define __PKHTB(ARG1,ARG2,ARG3) \
  1503. ({ \
  1504. uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
  1505. if (ARG3 == 0) \
  1506. __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
  1507. else \
  1508. __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
  1509. __RES; \
  1510. })
  1511. #endif
  1512. #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
  1513. ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
  1514. #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
  1515. ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
  1516. __STATIC_FORCEINLINE int32_t __SMMLA(int32_t op1, int32_t op2, int32_t op3)
  1517. {
  1518. int32_t result;
  1519. __ASM volatile("smmla %0, %1, %2, %3" : "=r"(result): "r"(op1), "r"(op2), "r"(op3));
  1520. return (result);
  1521. }
  1522. #endif /* (__ARM_FEATURE_DSP == 1) */
  1523. /*@} end of group CMSIS_SIMD_intrinsics */
  1524. #endif /* __CMSIS_ARMCLANG_H */