Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

2182 lines
61KB

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