cmsis_gcc.h 61 KB

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