My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

core_cmInstr.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /**************************************************************************//**
  2. * @file core_cmInstr.h
  3. * @brief CMSIS Cortex-M Core Instruction Access Header File
  4. * @version V2.10
  5. * @date 19. July 2011
  6. *
  7. * @note
  8. * Copyright (C) 2009-2011 ARM Limited. All rights reserved.
  9. *
  10. * @par
  11. * ARM Limited (ARM) is supplying this software for use with Cortex-M
  12. * processor based microcontrollers. This file can be freely distributed
  13. * within development tools that are supporting such ARM based processors.
  14. *
  15. * @par
  16. * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  17. * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  19. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  20. * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  21. *
  22. ******************************************************************************/
  23. #ifndef __CORE_CMINSTR_H
  24. #define __CORE_CMINSTR_H
  25. /* ########################## Core Instruction Access ######################### */
  26. /** \ingroup CMSIS_Core
  27. \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
  28. Access to dedicated instructions
  29. @{
  30. */
  31. #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
  32. /* ARM armcc specific functions */
  33. #if (__ARMCC_VERSION < 400677)
  34. #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
  35. #endif
  36. /** \brief No Operation
  37. No Operation does nothing. This instruction can be used for code alignment purposes.
  38. */
  39. #define __NOP __nop
  40. /** \brief Wait For Interrupt
  41. Wait For Interrupt is a hint instruction that suspends execution
  42. until one of a number of events occurs.
  43. */
  44. #define __WFI __wfi
  45. /** \brief Wait For Event
  46. Wait For Event is a hint instruction that permits the processor to enter
  47. a low-power state until one of a number of events occurs.
  48. */
  49. #define __WFE __wfe
  50. /** \brief Send Event
  51. Send Event is a hint instruction. It causes an event to be signaled to the CPU.
  52. */
  53. #define __SEV __sev
  54. /** \brief Instruction Synchronization Barrier
  55. Instruction Synchronization Barrier flushes the pipeline in the processor,
  56. so that all instructions following the ISB are fetched from cache or
  57. memory, after the instruction has been completed.
  58. */
  59. #define __ISB() __isb(0xF)
  60. /** \brief Data Synchronization Barrier
  61. This function acts as a special kind of Data Memory Barrier.
  62. It completes when all explicit memory accesses before this instruction complete.
  63. */
  64. #define __DSB() __dsb(0xF)
  65. /** \brief Data Memory Barrier
  66. This function ensures the apparent order of the explicit memory operations before
  67. and after the instruction, without ensuring their completion.
  68. */
  69. #define __DMB() __dmb(0xF)
  70. /** \brief Reverse byte order (32 bit)
  71. This function reverses the byte order in integer value.
  72. \param [in] value Value to reverse
  73. \return Reversed value
  74. */
  75. #define __REV __rev
  76. /** \brief Reverse byte order (16 bit)
  77. This function reverses the byte order in two unsigned short values.
  78. \param [in] value Value to reverse
  79. \return Reversed value
  80. */
  81. static __INLINE __ASM uint32_t __REV16(uint32_t value)
  82. {
  83. rev16 r0, r0
  84. bx lr
  85. }
  86. /** \brief Reverse byte order in signed short value
  87. This function reverses the byte order in a signed short value with sign extension to integer.
  88. \param [in] value Value to reverse
  89. \return Reversed value
  90. */
  91. static __INLINE __ASM int32_t __REVSH(int32_t value)
  92. {
  93. revsh r0, r0
  94. bx lr
  95. }
  96. #if (__CORTEX_M >= 0x03)
  97. /** \brief Reverse bit order of value
  98. This function reverses the bit order of the given value.
  99. \param [in] value Value to reverse
  100. \return Reversed value
  101. */
  102. #define __RBIT __rbit
  103. /** \brief LDR Exclusive (8 bit)
  104. This function performs a exclusive LDR command for 8 bit value.
  105. \param [in] ptr Pointer to data
  106. \return value of type uint8_t at (*ptr)
  107. */
  108. #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
  109. /** \brief LDR Exclusive (16 bit)
  110. This function performs a exclusive LDR command for 16 bit values.
  111. \param [in] ptr Pointer to data
  112. \return value of type uint16_t at (*ptr)
  113. */
  114. #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
  115. /** \brief LDR Exclusive (32 bit)
  116. This function performs a exclusive LDR command for 32 bit values.
  117. \param [in] ptr Pointer to data
  118. \return value of type uint32_t at (*ptr)
  119. */
  120. #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
  121. /** \brief STR Exclusive (8 bit)
  122. This function performs a exclusive STR command for 8 bit values.
  123. \param [in] value Value to store
  124. \param [in] ptr Pointer to location
  125. \return 0 Function succeeded
  126. \return 1 Function failed
  127. */
  128. #define __STREXB(value, ptr) __strex(value, ptr)
  129. /** \brief STR Exclusive (16 bit)
  130. This function performs a exclusive STR command for 16 bit values.
  131. \param [in] value Value to store
  132. \param [in] ptr Pointer to location
  133. \return 0 Function succeeded
  134. \return 1 Function failed
  135. */
  136. #define __STREXH(value, ptr) __strex(value, ptr)
  137. /** \brief STR Exclusive (32 bit)
  138. This function performs a exclusive STR command for 32 bit values.
  139. \param [in] value Value to store
  140. \param [in] ptr Pointer to location
  141. \return 0 Function succeeded
  142. \return 1 Function failed
  143. */
  144. #define __STREXW(value, ptr) __strex(value, ptr)
  145. /** \brief Remove the exclusive lock
  146. This function removes the exclusive lock which is created by LDREX.
  147. */
  148. #define __CLREX __clrex
  149. /** \brief Signed Saturate
  150. This function saturates a signed value.
  151. \param [in] value Value to be saturated
  152. \param [in] sat Bit position to saturate to (1..32)
  153. \return Saturated value
  154. */
  155. #define __SSAT __ssat
  156. /** \brief Unsigned Saturate
  157. This function saturates an unsigned value.
  158. \param [in] value Value to be saturated
  159. \param [in] sat Bit position to saturate to (0..31)
  160. \return Saturated value
  161. */
  162. #define __USAT __usat
  163. /** \brief Count leading zeros
  164. This function counts the number of leading zeros of a data value.
  165. \param [in] value Value to count the leading zeros
  166. \return number of leading zeros in value
  167. */
  168. #define __CLZ __clz
  169. #endif /* (__CORTEX_M >= 0x03) */
  170. #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
  171. /* IAR iccarm specific functions */
  172. #include <cmsis_iar.h>
  173. #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
  174. /* GNU gcc specific functions */
  175. /** \brief No Operation
  176. No Operation does nothing. This instruction can be used for code alignment purposes.
  177. */
  178. __attribute__( ( always_inline ) ) static __INLINE void __NOP(void)
  179. {
  180. __ASM volatile ("nop");
  181. }
  182. /** \brief Wait For Interrupt
  183. Wait For Interrupt is a hint instruction that suspends execution
  184. until one of a number of events occurs.
  185. */
  186. __attribute__( ( always_inline ) ) static __INLINE void __WFI(void)
  187. {
  188. __ASM volatile ("wfi");
  189. }
  190. /** \brief Wait For Event
  191. Wait For Event is a hint instruction that permits the processor to enter
  192. a low-power state until one of a number of events occurs.
  193. */
  194. __attribute__( ( always_inline ) ) static __INLINE void __WFE(void)
  195. {
  196. __ASM volatile ("wfe");
  197. }
  198. /** \brief Send Event
  199. Send Event is a hint instruction. It causes an event to be signaled to the CPU.
  200. */
  201. __attribute__( ( always_inline ) ) static __INLINE void __SEV(void)
  202. {
  203. __ASM volatile ("sev");
  204. }
  205. /** \brief Instruction Synchronization Barrier
  206. Instruction Synchronization Barrier flushes the pipeline in the processor,
  207. so that all instructions following the ISB are fetched from cache or
  208. memory, after the instruction has been completed.
  209. */
  210. __attribute__( ( always_inline ) ) static __INLINE void __ISB(void)
  211. {
  212. __ASM volatile ("isb");
  213. }
  214. /** \brief Data Synchronization Barrier
  215. This function acts as a special kind of Data Memory Barrier.
  216. It completes when all explicit memory accesses before this instruction complete.
  217. */
  218. __attribute__( ( always_inline ) ) static __INLINE void __DSB(void)
  219. {
  220. __ASM volatile ("dsb");
  221. }
  222. /** \brief Data Memory Barrier
  223. This function ensures the apparent order of the explicit memory operations before
  224. and after the instruction, without ensuring their completion.
  225. */
  226. __attribute__( ( always_inline ) ) static __INLINE void __DMB(void)
  227. {
  228. __ASM volatile ("dmb");
  229. }
  230. /** \brief Reverse byte order (32 bit)
  231. This function reverses the byte order in integer value.
  232. \param [in] value Value to reverse
  233. \return Reversed value
  234. */
  235. __attribute__( ( always_inline ) ) static __INLINE uint32_t __REV(uint32_t value)
  236. {
  237. uint32_t result;
  238. __ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) );
  239. return(result);
  240. }
  241. /** \brief Reverse byte order (16 bit)
  242. This function reverses the byte order in two unsigned short values.
  243. \param [in] value Value to reverse
  244. \return Reversed value
  245. */
  246. __attribute__( ( always_inline ) ) static __INLINE uint32_t __REV16(uint32_t value)
  247. {
  248. uint32_t result;
  249. __ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) );
  250. return(result);
  251. }
  252. /** \brief Reverse byte order in signed short value
  253. This function reverses the byte order in a signed short value with sign extension to integer.
  254. \param [in] value Value to reverse
  255. \return Reversed value
  256. */
  257. __attribute__( ( always_inline ) ) static __INLINE int32_t __REVSH(int32_t value)
  258. {
  259. uint32_t result;
  260. __ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) );
  261. return(result);
  262. }
  263. #if (__CORTEX_M >= 0x03)
  264. /** \brief Reverse bit order of value
  265. This function reverses the bit order of the given value.
  266. \param [in] value Value to reverse
  267. \return Reversed value
  268. */
  269. __attribute__( ( always_inline ) ) static __INLINE uint32_t __RBIT(uint32_t value)
  270. {
  271. uint32_t result;
  272. __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
  273. return(result);
  274. }
  275. /** \brief LDR Exclusive (8 bit)
  276. This function performs a exclusive LDR command for 8 bit value.
  277. \param [in] ptr Pointer to data
  278. \return value of type uint8_t at (*ptr)
  279. */
  280. __attribute__( ( always_inline ) ) static __INLINE uint8_t __LDREXB(volatile uint8_t *addr)
  281. {
  282. uint8_t result;
  283. __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) );
  284. return(result);
  285. }
  286. /** \brief LDR Exclusive (16 bit)
  287. This function performs a exclusive LDR command for 16 bit values.
  288. \param [in] ptr Pointer to data
  289. \return value of type uint16_t at (*ptr)
  290. */
  291. __attribute__( ( always_inline ) ) static __INLINE uint16_t __LDREXH(volatile uint16_t *addr)
  292. {
  293. uint16_t result;
  294. __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) );
  295. return(result);
  296. }
  297. /** \brief LDR Exclusive (32 bit)
  298. This function performs a exclusive LDR command for 32 bit values.
  299. \param [in] ptr Pointer to data
  300. \return value of type uint32_t at (*ptr)
  301. */
  302. __attribute__( ( always_inline ) ) static __INLINE uint32_t __LDREXW(volatile uint32_t *addr)
  303. {
  304. uint32_t result;
  305. __ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) );
  306. return(result);
  307. }
  308. /** \brief STR Exclusive (8 bit)
  309. This function performs a exclusive STR command for 8 bit values.
  310. \param [in] value Value to store
  311. \param [in] ptr Pointer to location
  312. \return 0 Function succeeded
  313. \return 1 Function failed
  314. */
  315. __attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
  316. {
  317. uint32_t result;
  318. __ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
  319. return(result);
  320. }
  321. /** \brief STR Exclusive (16 bit)
  322. This function performs a exclusive STR command for 16 bit values.
  323. \param [in] value Value to store
  324. \param [in] ptr Pointer to location
  325. \return 0 Function succeeded
  326. \return 1 Function failed
  327. */
  328. __attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
  329. {
  330. uint32_t result;
  331. __ASM volatile ("strexh %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
  332. return(result);
  333. }
  334. /** \brief STR Exclusive (32 bit)
  335. This function performs a exclusive STR command for 32 bit values.
  336. \param [in] value Value to store
  337. \param [in] ptr Pointer to location
  338. \return 0 Function succeeded
  339. \return 1 Function failed
  340. */
  341. __attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
  342. {
  343. uint32_t result;
  344. __ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
  345. return(result);
  346. }
  347. /** \brief Remove the exclusive lock
  348. This function removes the exclusive lock which is created by LDREX.
  349. */
  350. __attribute__( ( always_inline ) ) static __INLINE void __CLREX(void)
  351. {
  352. __ASM volatile ("clrex");
  353. }
  354. /** \brief Signed Saturate
  355. This function saturates a signed value.
  356. \param [in] value Value to be saturated
  357. \param [in] sat Bit position to saturate to (1..32)
  358. \return Saturated value
  359. */
  360. #define __SSAT(ARG1,ARG2) \
  361. ({ \
  362. uint32_t __RES, __ARG1 = (ARG1); \
  363. __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
  364. __RES; \
  365. })
  366. /** \brief Unsigned Saturate
  367. This function saturates an unsigned value.
  368. \param [in] value Value to be saturated
  369. \param [in] sat Bit position to saturate to (0..31)
  370. \return Saturated value
  371. */
  372. #define __USAT(ARG1,ARG2) \
  373. ({ \
  374. uint32_t __RES, __ARG1 = (ARG1); \
  375. __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
  376. __RES; \
  377. })
  378. /** \brief Count leading zeros
  379. This function counts the number of leading zeros of a data value.
  380. \param [in] value Value to count the leading zeros
  381. \return number of leading zeros in value
  382. */
  383. __attribute__( ( always_inline ) ) static __INLINE uint8_t __CLZ(uint32_t value)
  384. {
  385. uint8_t result;
  386. __ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) );
  387. return(result);
  388. }
  389. #endif /* (__CORTEX_M >= 0x03) */
  390. #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
  391. /* TASKING carm specific functions */
  392. /*
  393. * The CMSIS functions have been implemented as intrinsics in the compiler.
  394. * Please use "carm -?i" to get an up to date list of all intrinsics,
  395. * Including the CMSIS ones.
  396. */
  397. #endif
  398. /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
  399. #endif /* __CORE_CMINSTR_H */