cmsis_gcc.h 59 KB

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