cmsis_armclang.h 54 KB

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