cmsis_gcc.h 61 KB

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