cmsis_gcc.h 56 KB

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