cmsis_gcc.h 59 KB

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