cmsis_armcc(2).h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. /**************************************************************************//**
  2. * @file cmsis_armcc.h
  3. * @brief CMSIS compiler ARMCC (Arm Compiler 5) header file
  4. * @version V5.0.5
  5. * @date 14. December 2018
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2009-2018 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_ARMCC_H
  25. #define __CMSIS_ARMCC_H
  26. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
  27. #error "Please use Arm Compiler Toolchain V4.0.677 or later!"
  28. #endif
  29. /* CMSIS compiler control architecture macros */
  30. #if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \
  31. (defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) )
  32. #define __ARM_ARCH_6M__ 1
  33. #endif
  34. #if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1))
  35. #define __ARM_ARCH_7M__ 1
  36. #endif
  37. #if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1))
  38. #define __ARM_ARCH_7EM__ 1
  39. #endif
  40. /* __ARM_ARCH_8M_BASE__ not applicable */
  41. /* __ARM_ARCH_8M_MAIN__ not applicable */
  42. /* CMSIS compiler control DSP macros */
  43. #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
  44. #define __ARM_FEATURE_DSP 1
  45. #endif
  46. /* CMSIS compiler specific defines */
  47. #ifndef __ASM
  48. #define __ASM __asm
  49. #endif
  50. #ifndef __INLINE
  51. #define __INLINE __inline
  52. #endif
  53. #ifndef __STATIC_INLINE
  54. #define __STATIC_INLINE static __inline
  55. #endif
  56. #ifndef __STATIC_FORCEINLINE
  57. #define __STATIC_FORCEINLINE static __forceinline
  58. #endif
  59. #ifndef __NO_RETURN
  60. #define __NO_RETURN __declspec(noreturn)
  61. #endif
  62. #ifndef __USED
  63. #define __USED __attribute__((used))
  64. #endif
  65. #ifndef __WEAK
  66. #define __WEAK __attribute__((weak))
  67. #endif
  68. #ifndef __PACKED
  69. #define __PACKED __attribute__((packed))
  70. #endif
  71. #ifndef __PACKED_STRUCT
  72. #define __PACKED_STRUCT __packed struct
  73. #endif
  74. #ifndef __PACKED_UNION
  75. #define __PACKED_UNION __packed union
  76. #endif
  77. #ifndef __UNALIGNED_UINT32 /* deprecated */
  78. #define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x)))
  79. #endif
  80. #ifndef __UNALIGNED_UINT16_WRITE
  81. #define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val))
  82. #endif
  83. #ifndef __UNALIGNED_UINT16_READ
  84. #define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr)))
  85. #endif
  86. #ifndef __UNALIGNED_UINT32_WRITE
  87. #define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val))
  88. #endif
  89. #ifndef __UNALIGNED_UINT32_READ
  90. #define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr)))
  91. #endif
  92. #ifndef __ALIGNED
  93. #define __ALIGNED(x) __attribute__((aligned(x)))
  94. #endif
  95. #ifndef __RESTRICT
  96. #define __RESTRICT __restrict
  97. #endif
  98. /* ########################### Core Function Access ########################### */
  99. /** \ingroup CMSIS_Core_FunctionInterface
  100. \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
  101. @{
  102. */
  103. /**
  104. \brief Enable IRQ Interrupts
  105. \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
  106. Can only be executed in Privileged modes.
  107. */
  108. /* intrinsic void __enable_irq(); */
  109. /**
  110. \brief Disable IRQ Interrupts
  111. \details Disables IRQ interrupts by setting the I-bit in the CPSR.
  112. Can only be executed in Privileged modes.
  113. */
  114. /* intrinsic void __disable_irq(); */
  115. /**
  116. \brief Get Control Register
  117. \details Returns the content of the Control Register.
  118. \return Control Register value
  119. */
  120. __STATIC_INLINE uint32_t __get_CONTROL(void)
  121. {
  122. register uint32_t __regControl __ASM("control");
  123. return(__regControl);
  124. }
  125. /**
  126. \brief Set Control Register
  127. \details Writes the given value to the Control Register.
  128. \param [in] control Control Register value to set
  129. */
  130. __STATIC_INLINE void __set_CONTROL(uint32_t control)
  131. {
  132. register uint32_t __regControl __ASM("control");
  133. __regControl = control;
  134. }
  135. /**
  136. \brief Get IPSR Register
  137. \details Returns the content of the IPSR Register.
  138. \return IPSR Register value
  139. */
  140. __STATIC_INLINE uint32_t __get_IPSR(void)
  141. {
  142. register uint32_t __regIPSR __ASM("ipsr");
  143. return(__regIPSR);
  144. }
  145. /**
  146. \brief Get APSR Register
  147. \details Returns the content of the APSR Register.
  148. \return APSR Register value
  149. */
  150. __STATIC_INLINE uint32_t __get_APSR(void)
  151. {
  152. register uint32_t __regAPSR __ASM("apsr");
  153. return(__regAPSR);
  154. }
  155. /**
  156. \brief Get xPSR Register
  157. \details Returns the content of the xPSR Register.
  158. \return xPSR Register value
  159. */
  160. __STATIC_INLINE uint32_t __get_xPSR(void)
  161. {
  162. register uint32_t __regXPSR __ASM("xpsr");
  163. return(__regXPSR);
  164. }
  165. /**
  166. \brief Get Process Stack Pointer
  167. \details Returns the current value of the Process Stack Pointer (PSP).
  168. \return PSP Register value
  169. */
  170. __STATIC_INLINE uint32_t __get_PSP(void)
  171. {
  172. register uint32_t __regProcessStackPointer __ASM("psp");
  173. return(__regProcessStackPointer);
  174. }
  175. /**
  176. \brief Set Process Stack Pointer
  177. \details Assigns the given value to the Process Stack Pointer (PSP).
  178. \param [in] topOfProcStack Process Stack Pointer value to set
  179. */
  180. __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
  181. {
  182. register uint32_t __regProcessStackPointer __ASM("psp");
  183. __regProcessStackPointer = topOfProcStack;
  184. }
  185. /**
  186. \brief Get Main Stack Pointer
  187. \details Returns the current value of the Main Stack Pointer (MSP).
  188. \return MSP Register value
  189. */
  190. __STATIC_INLINE uint32_t __get_MSP(void)
  191. {
  192. register uint32_t __regMainStackPointer __ASM("msp");
  193. return(__regMainStackPointer);
  194. }
  195. /**
  196. \brief Set Main Stack Pointer
  197. \details Assigns the given value to the Main Stack Pointer (MSP).
  198. \param [in] topOfMainStack Main Stack Pointer value to set
  199. */
  200. __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
  201. {
  202. register uint32_t __regMainStackPointer __ASM("msp");
  203. __regMainStackPointer = topOfMainStack;
  204. }
  205. /**
  206. \brief Get Priority Mask
  207. \details Returns the current state of the priority mask bit from the Priority Mask Register.
  208. \return Priority Mask value
  209. */
  210. __STATIC_INLINE uint32_t __get_PRIMASK(void)
  211. {
  212. register uint32_t __regPriMask __ASM("primask");
  213. return(__regPriMask);
  214. }
  215. /**
  216. \brief Set Priority Mask
  217. \details Assigns the given value to the Priority Mask Register.
  218. \param [in] priMask Priority Mask
  219. */
  220. __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
  221. {
  222. register uint32_t __regPriMask __ASM("primask");
  223. __regPriMask = (priMask);
  224. }
  225. #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  226. (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
  227. /**
  228. \brief Enable FIQ
  229. \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
  230. Can only be executed in Privileged modes.
  231. */
  232. #define __enable_fault_irq __enable_fiq
  233. /**
  234. \brief Disable FIQ
  235. \details Disables FIQ interrupts by setting the F-bit in the CPSR.
  236. Can only be executed in Privileged modes.
  237. */
  238. #define __disable_fault_irq __disable_fiq
  239. /**
  240. \brief Get Base Priority
  241. \details Returns the current value of the Base Priority register.
  242. \return Base Priority register value
  243. */
  244. __STATIC_INLINE uint32_t __get_BASEPRI(void)
  245. {
  246. register uint32_t __regBasePri __ASM("basepri");
  247. return(__regBasePri);
  248. }
  249. /**
  250. \brief Set Base Priority
  251. \details Assigns the given value to the Base Priority register.
  252. \param [in] basePri Base Priority value to set
  253. */
  254. __STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
  255. {
  256. register uint32_t __regBasePri __ASM("basepri");
  257. __regBasePri = (basePri & 0xFFU);
  258. }
  259. /**
  260. \brief Set Base Priority with condition
  261. \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
  262. or the new value increases the BASEPRI priority level.
  263. \param [in] basePri Base Priority value to set
  264. */
  265. __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
  266. {
  267. register uint32_t __regBasePriMax __ASM("basepri_max");
  268. __regBasePriMax = (basePri & 0xFFU);
  269. }
  270. /**
  271. \brief Get Fault Mask
  272. \details Returns the current value of the Fault Mask register.
  273. \return Fault Mask register value
  274. */
  275. __STATIC_INLINE uint32_t __get_FAULTMASK(void)
  276. {
  277. register uint32_t __regFaultMask __ASM("faultmask");
  278. return(__regFaultMask);
  279. }
  280. /**
  281. \brief Set Fault Mask
  282. \details Assigns the given value to the Fault Mask register.
  283. \param [in] faultMask Fault Mask value to set
  284. */
  285. __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
  286. {
  287. register uint32_t __regFaultMask __ASM("faultmask");
  288. __regFaultMask = (faultMask & (uint32_t)1U);
  289. }
  290. #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  291. (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
  292. /**
  293. \brief Get FPSCR
  294. \details Returns the current value of the Floating Point Status/Control register.
  295. \return Floating Point Status/Control register value
  296. */
  297. __STATIC_INLINE uint32_t __get_FPSCR(void)
  298. {
  299. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
  300. (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
  301. register uint32_t __regfpscr __ASM("fpscr");
  302. return(__regfpscr);
  303. #else
  304. return(0U);
  305. #endif
  306. }
  307. /**
  308. \brief Set FPSCR
  309. \details Assigns the given value to the Floating Point Status/Control register.
  310. \param [in] fpscr Floating Point Status/Control value to set
  311. */
  312. __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
  313. {
  314. #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
  315. (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
  316. register uint32_t __regfpscr __ASM("fpscr");
  317. __regfpscr = (fpscr);
  318. #else
  319. (void)fpscr;
  320. #endif
  321. }
  322. /*@} end of CMSIS_Core_RegAccFunctions */
  323. /* ########################## Core Instruction Access ######################### */
  324. /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
  325. Access to dedicated instructions
  326. @{
  327. */
  328. /**
  329. \brief No Operation
  330. \details No Operation does nothing. This instruction can be used for code alignment purposes.
  331. */
  332. #define __NOP __nop
  333. /**
  334. \brief Wait For Interrupt
  335. \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
  336. */
  337. #define __WFI __wfi
  338. /**
  339. \brief Wait For Event
  340. \details Wait For Event is a hint instruction that permits the processor to enter
  341. a low-power state until one of a number of events occurs.
  342. */
  343. #define __WFE __wfe
  344. /**
  345. \brief Send Event
  346. \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
  347. */
  348. #define __SEV __sev
  349. /**
  350. \brief Instruction Synchronization Barrier
  351. \details Instruction Synchronization Barrier flushes the pipeline in the processor,
  352. so that all instructions following the ISB are fetched from cache or memory,
  353. after the instruction has been completed.
  354. */
  355. #define __ISB() do {\
  356. __schedule_barrier();\
  357. __isb(0xF);\
  358. __schedule_barrier();\
  359. } while (0U)
  360. /**
  361. \brief Data Synchronization Barrier
  362. \details Acts as a special kind of Data Memory Barrier.
  363. It completes when all explicit memory accesses before this instruction complete.
  364. */
  365. #define __DSB() do {\
  366. __schedule_barrier();\
  367. __dsb(0xF);\
  368. __schedule_barrier();\
  369. } while (0U)
  370. /**
  371. \brief Data Memory Barrier
  372. \details Ensures the apparent order of the explicit memory operations before
  373. and after the instruction, without ensuring their completion.
  374. */
  375. #define __DMB() do {\
  376. __schedule_barrier();\
  377. __dmb(0xF);\
  378. __schedule_barrier();\
  379. } while (0U)
  380. /**
  381. \brief Reverse byte order (32 bit)
  382. \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
  383. \param [in] value Value to reverse
  384. \return Reversed value
  385. */
  386. #define __REV __rev
  387. /**
  388. \brief Reverse byte order (16 bit)
  389. \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
  390. \param [in] value Value to reverse
  391. \return Reversed value
  392. */
  393. #ifndef __NO_EMBEDDED_ASM
  394. __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
  395. {
  396. rev16 r0, r0
  397. bx lr
  398. }
  399. #endif
  400. /**
  401. \brief Reverse byte order (16 bit)
  402. \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
  403. \param [in] value Value to reverse
  404. \return Reversed value
  405. */
  406. #ifndef __NO_EMBEDDED_ASM
  407. __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value)
  408. {
  409. revsh r0, r0
  410. bx lr
  411. }
  412. #endif
  413. /**
  414. \brief Rotate Right in unsigned value (32 bit)
  415. \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
  416. \param [in] op1 Value to rotate
  417. \param [in] op2 Number of Bits to rotate
  418. \return Rotated value
  419. */
  420. #define __ROR __ror
  421. /**
  422. \brief Breakpoint
  423. \details Causes the processor to enter Debug state.
  424. Debug tools can use this to investigate system state when the instruction at a particular address is reached.
  425. \param [in] value is ignored by the processor.
  426. If required, a debugger can use it to store additional information about the breakpoint.
  427. */
  428. #define __BKPT(value) __breakpoint(value)
  429. /**
  430. \brief Reverse bit order of value
  431. \details Reverses the bit order of the given value.
  432. \param [in] value Value to reverse
  433. \return Reversed value
  434. */
  435. #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  436. (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
  437. #define __RBIT __rbit
  438. #else
  439. __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
  440. {
  441. uint32_t result;
  442. uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
  443. result = value; /* r will be reversed bits of v; first get LSB of v */
  444. for (value >>= 1U; value != 0U; value >>= 1U)
  445. {
  446. result <<= 1U;
  447. result |= value & 1U;
  448. s--;
  449. }
  450. result <<= s; /* shift when v's highest bits are zero */
  451. return result;
  452. }
  453. #endif
  454. /**
  455. \brief Count leading zeros
  456. \details Counts the number of leading zeros of a data value.
  457. \param [in] value Value to count the leading zeros
  458. \return number of leading zeros in value
  459. */
  460. #define __CLZ __clz
  461. #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  462. (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
  463. /**
  464. \brief LDR Exclusive (8 bit)
  465. \details Executes a exclusive LDR instruction for 8 bit value.
  466. \param [in] ptr Pointer to data
  467. \return value of type uint8_t at (*ptr)
  468. */
  469. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
  470. #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
  471. #else
  472. #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop")
  473. #endif
  474. /**
  475. \brief LDR Exclusive (16 bit)
  476. \details Executes a exclusive LDR instruction for 16 bit values.
  477. \param [in] ptr Pointer to data
  478. \return value of type uint16_t at (*ptr)
  479. */
  480. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
  481. #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
  482. #else
  483. #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop")
  484. #endif
  485. /**
  486. \brief LDR Exclusive (32 bit)
  487. \details Executes a exclusive LDR instruction for 32 bit values.
  488. \param [in] ptr Pointer to data
  489. \return value of type uint32_t at (*ptr)
  490. */
  491. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
  492. #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
  493. #else
  494. #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop")
  495. #endif
  496. /**
  497. \brief STR Exclusive (8 bit)
  498. \details Executes a exclusive STR instruction for 8 bit values.
  499. \param [in] value Value to store
  500. \param [in] ptr Pointer to location
  501. \return 0 Function succeeded
  502. \return 1 Function failed
  503. */
  504. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
  505. #define __STREXB(value, ptr) __strex(value, ptr)
  506. #else
  507. #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
  508. #endif
  509. /**
  510. \brief STR Exclusive (16 bit)
  511. \details Executes a exclusive STR instruction for 16 bit values.
  512. \param [in] value Value to store
  513. \param [in] ptr Pointer to location
  514. \return 0 Function succeeded
  515. \return 1 Function failed
  516. */
  517. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
  518. #define __STREXH(value, ptr) __strex(value, ptr)
  519. #else
  520. #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
  521. #endif
  522. /**
  523. \brief STR Exclusive (32 bit)
  524. \details Executes a exclusive STR instruction for 32 bit values.
  525. \param [in] value Value to store
  526. \param [in] ptr Pointer to location
  527. \return 0 Function succeeded
  528. \return 1 Function failed
  529. */
  530. #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
  531. #define __STREXW(value, ptr) __strex(value, ptr)
  532. #else
  533. #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
  534. #endif
  535. /**
  536. \brief Remove the exclusive lock
  537. \details Removes the exclusive lock which is created by LDREX.
  538. */
  539. #define __CLREX __clrex
  540. /**
  541. \brief Signed Saturate
  542. \details Saturates a signed value.
  543. \param [in] value Value to be saturated
  544. \param [in] sat Bit position to saturate to (1..32)
  545. \return Saturated value
  546. */
  547. #define __SSAT __ssat
  548. /**
  549. \brief Unsigned Saturate
  550. \details Saturates an unsigned value.
  551. \param [in] value Value to be saturated
  552. \param [in] sat Bit position to saturate to (0..31)
  553. \return Saturated value
  554. */
  555. #define __USAT __usat
  556. /**
  557. \brief Rotate Right with Extend (32 bit)
  558. \details Moves each bit of a bitstring right by one bit.
  559. The carry input is shifted in at the left end of the bitstring.
  560. \param [in] value Value to rotate
  561. \return Rotated value
  562. */
  563. #ifndef __NO_EMBEDDED_ASM
  564. __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
  565. {
  566. rrx r0, r0
  567. bx lr
  568. }
  569. #endif
  570. /**
  571. \brief LDRT Unprivileged (8 bit)
  572. \details Executes a Unprivileged LDRT instruction for 8 bit value.
  573. \param [in] ptr Pointer to data
  574. \return value of type uint8_t at (*ptr)
  575. */
  576. #define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
  577. /**
  578. \brief LDRT Unprivileged (16 bit)
  579. \details Executes a Unprivileged LDRT instruction for 16 bit values.
  580. \param [in] ptr Pointer to data
  581. \return value of type uint16_t at (*ptr)
  582. */
  583. #define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
  584. /**
  585. \brief LDRT Unprivileged (32 bit)
  586. \details Executes a Unprivileged LDRT instruction for 32 bit values.
  587. \param [in] ptr Pointer to data
  588. \return value of type uint32_t at (*ptr)
  589. */
  590. #define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
  591. /**
  592. \brief STRT Unprivileged (8 bit)
  593. \details Executes a Unprivileged STRT instruction for 8 bit values.
  594. \param [in] value Value to store
  595. \param [in] ptr Pointer to location
  596. */
  597. #define __STRBT(value, ptr) __strt(value, ptr)
  598. /**
  599. \brief STRT Unprivileged (16 bit)
  600. \details Executes a Unprivileged STRT instruction for 16 bit values.
  601. \param [in] value Value to store
  602. \param [in] ptr Pointer to location
  603. */
  604. #define __STRHT(value, ptr) __strt(value, ptr)
  605. /**
  606. \brief STRT Unprivileged (32 bit)
  607. \details Executes a Unprivileged STRT instruction for 32 bit values.
  608. \param [in] value Value to store
  609. \param [in] ptr Pointer to location
  610. */
  611. #define __STRT(value, ptr) __strt(value, ptr)
  612. #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  613. (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
  614. /**
  615. \brief Signed Saturate
  616. \details Saturates a signed value.
  617. \param [in] value Value to be saturated
  618. \param [in] sat Bit position to saturate to (1..32)
  619. \return Saturated value
  620. */
  621. __attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
  622. {
  623. if ((sat >= 1U) && (sat <= 32U))
  624. {
  625. const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
  626. const int32_t min = -1 - max ;
  627. if (val > max)
  628. {
  629. return max;
  630. }
  631. else if (val < min)
  632. {
  633. return min;
  634. }
  635. }
  636. return val;
  637. }
  638. /**
  639. \brief Unsigned Saturate
  640. \details Saturates an unsigned value.
  641. \param [in] value Value to be saturated
  642. \param [in] sat Bit position to saturate to (0..31)
  643. \return Saturated value
  644. */
  645. __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
  646. {
  647. if (sat <= 31U)
  648. {
  649. const uint32_t max = ((1U << sat) - 1U);
  650. if (val > (int32_t)max)
  651. {
  652. return max;
  653. }
  654. else if (val < 0)
  655. {
  656. return 0U;
  657. }
  658. }
  659. return (uint32_t)val;
  660. }
  661. #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
  662. (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
  663. /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
  664. /* ################### Compiler specific Intrinsics ########################### */
  665. /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
  666. Access to dedicated SIMD instructions
  667. @{
  668. */
  669. #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
  670. #define __SADD8 __sadd8
  671. #define __QADD8 __qadd8
  672. #define __SHADD8 __shadd8
  673. #define __UADD8 __uadd8
  674. #define __UQADD8 __uqadd8
  675. #define __UHADD8 __uhadd8
  676. #define __SSUB8 __ssub8
  677. #define __QSUB8 __qsub8
  678. #define __SHSUB8 __shsub8
  679. #define __USUB8 __usub8
  680. #define __UQSUB8 __uqsub8
  681. #define __UHSUB8 __uhsub8
  682. #define __SADD16 __sadd16
  683. #define __QADD16 __qadd16
  684. #define __SHADD16 __shadd16
  685. #define __UADD16 __uadd16
  686. #define __UQADD16 __uqadd16
  687. #define __UHADD16 __uhadd16
  688. #define __SSUB16 __ssub16
  689. #define __QSUB16 __qsub16
  690. #define __SHSUB16 __shsub16
  691. #define __USUB16 __usub16
  692. #define __UQSUB16 __uqsub16
  693. #define __UHSUB16 __uhsub16
  694. #define __SASX __sasx
  695. #define __QASX __qasx
  696. #define __SHASX __shasx
  697. #define __UASX __uasx
  698. #define __UQASX __uqasx
  699. #define __UHASX __uhasx
  700. #define __SSAX __ssax
  701. #define __QSAX __qsax
  702. #define __SHSAX __shsax
  703. #define __USAX __usax
  704. #define __UQSAX __uqsax
  705. #define __UHSAX __uhsax
  706. #define __USAD8 __usad8
  707. #define __USADA8 __usada8
  708. #define __SSAT16 __ssat16
  709. #define __USAT16 __usat16
  710. #define __UXTB16 __uxtb16
  711. #define __UXTAB16 __uxtab16
  712. #define __SXTB16 __sxtb16
  713. #define __SXTAB16 __sxtab16
  714. #define __SMUAD __smuad
  715. #define __SMUADX __smuadx
  716. #define __SMLAD __smlad
  717. #define __SMLADX __smladx
  718. #define __SMLALD __smlald
  719. #define __SMLALDX __smlaldx
  720. #define __SMUSD __smusd
  721. #define __SMUSDX __smusdx
  722. #define __SMLSD __smlsd
  723. #define __SMLSDX __smlsdx
  724. #define __SMLSLD __smlsld
  725. #define __SMLSLDX __smlsldx
  726. #define __SEL __sel
  727. #define __QADD __qadd
  728. #define __QSUB __qsub
  729. #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
  730. ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
  731. #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
  732. ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
  733. #define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
  734. ((int64_t)(ARG3) << 32U) ) >> 32U))
  735. #endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
  736. /*@} end of group CMSIS_SIMD_intrinsics */
  737. #endif /* __CMSIS_ARMCC_H */