cmsis_gcc.h 62 KB

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