cmsis_gcc.h 59 KB

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