cmsis_gcc.h 63 KB

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