Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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