The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Wed Oct 29 11:02:04 2014 +0000
Revision:
91:031413cf7a89
Child:
110:165afa46840b
Release 91 of the mbed library

Changes:

- RBLAB_NANO - new target addition
- NRF51_DK - new target addition
- NRF51_DONGLE - new target addition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 91:031413cf7a89 1 /**************************************************************************//**
Kojto 91:031413cf7a89 2 * @file core_cmInstr.h
Kojto 91:031413cf7a89 3 * @brief CMSIS Cortex-M Core Instruction Access Header File
Kojto 91:031413cf7a89 4 * @version V3.20
Kojto 91:031413cf7a89 5 * @date 05. March 2013
Kojto 91:031413cf7a89 6 *
Kojto 91:031413cf7a89 7 * @note
Kojto 91:031413cf7a89 8 *
Kojto 91:031413cf7a89 9 ******************************************************************************/
Kojto 91:031413cf7a89 10 /* Copyright (c) 2009 - 2013 ARM LIMITED
Kojto 91:031413cf7a89 11
Kojto 91:031413cf7a89 12 All rights reserved.
Kojto 91:031413cf7a89 13 Redistribution and use in source and binary forms, with or without
Kojto 91:031413cf7a89 14 modification, are permitted provided that the following conditions are met:
Kojto 91:031413cf7a89 15 - Redistributions of source code must retain the above copyright
Kojto 91:031413cf7a89 16 notice, this list of conditions and the following disclaimer.
Kojto 91:031413cf7a89 17 - Redistributions in binary form must reproduce the above copyright
Kojto 91:031413cf7a89 18 notice, this list of conditions and the following disclaimer in the
Kojto 91:031413cf7a89 19 documentation and/or other materials provided with the distribution.
Kojto 91:031413cf7a89 20 - Neither the name of ARM nor the names of its contributors may be used
Kojto 91:031413cf7a89 21 to endorse or promote products derived from this software without
Kojto 91:031413cf7a89 22 specific prior written permission.
Kojto 91:031413cf7a89 23 *
Kojto 91:031413cf7a89 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 91:031413cf7a89 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 91:031413cf7a89 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Kojto 91:031413cf7a89 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
Kojto 91:031413cf7a89 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Kojto 91:031413cf7a89 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Kojto 91:031413cf7a89 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Kojto 91:031413cf7a89 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Kojto 91:031413cf7a89 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Kojto 91:031413cf7a89 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Kojto 91:031413cf7a89 34 POSSIBILITY OF SUCH DAMAGE.
Kojto 91:031413cf7a89 35 ---------------------------------------------------------------------------*/
Kojto 91:031413cf7a89 36
Kojto 91:031413cf7a89 37
Kojto 91:031413cf7a89 38 #ifndef __CORE_CMINSTR_H
Kojto 91:031413cf7a89 39 #define __CORE_CMINSTR_H
Kojto 91:031413cf7a89 40
Kojto 91:031413cf7a89 41
Kojto 91:031413cf7a89 42 /* ########################## Core Instruction Access ######################### */
Kojto 91:031413cf7a89 43 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
Kojto 91:031413cf7a89 44 Access to dedicated instructions
Kojto 91:031413cf7a89 45 @{
Kojto 91:031413cf7a89 46 */
Kojto 91:031413cf7a89 47
Kojto 91:031413cf7a89 48 #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
Kojto 91:031413cf7a89 49 /* ARM armcc specific functions */
Kojto 91:031413cf7a89 50
Kojto 91:031413cf7a89 51 #if (__ARMCC_VERSION < 400677)
Kojto 91:031413cf7a89 52 #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
Kojto 91:031413cf7a89 53 #endif
Kojto 91:031413cf7a89 54
Kojto 91:031413cf7a89 55
Kojto 91:031413cf7a89 56 /** \brief No Operation
Kojto 91:031413cf7a89 57
Kojto 91:031413cf7a89 58 No Operation does nothing. This instruction can be used for code alignment purposes.
Kojto 91:031413cf7a89 59 */
Kojto 91:031413cf7a89 60 #define __NOP __nop
Kojto 91:031413cf7a89 61
Kojto 91:031413cf7a89 62
Kojto 91:031413cf7a89 63 /** \brief Wait For Interrupt
Kojto 91:031413cf7a89 64
Kojto 91:031413cf7a89 65 Wait For Interrupt is a hint instruction that suspends execution
Kojto 91:031413cf7a89 66 until one of a number of events occurs.
Kojto 91:031413cf7a89 67 */
Kojto 91:031413cf7a89 68 #define __WFI __wfi
Kojto 91:031413cf7a89 69
Kojto 91:031413cf7a89 70
Kojto 91:031413cf7a89 71 /** \brief Wait For Event
Kojto 91:031413cf7a89 72
Kojto 91:031413cf7a89 73 Wait For Event is a hint instruction that permits the processor to enter
Kojto 91:031413cf7a89 74 a low-power state until one of a number of events occurs.
Kojto 91:031413cf7a89 75 */
Kojto 91:031413cf7a89 76 #define __WFE __wfe
Kojto 91:031413cf7a89 77
Kojto 91:031413cf7a89 78
Kojto 91:031413cf7a89 79 /** \brief Send Event
Kojto 91:031413cf7a89 80
Kojto 91:031413cf7a89 81 Send Event is a hint instruction. It causes an event to be signaled to the CPU.
Kojto 91:031413cf7a89 82 */
Kojto 91:031413cf7a89 83 #define __SEV __sev
Kojto 91:031413cf7a89 84
Kojto 91:031413cf7a89 85
Kojto 91:031413cf7a89 86 /** \brief Instruction Synchronization Barrier
Kojto 91:031413cf7a89 87
Kojto 91:031413cf7a89 88 Instruction Synchronization Barrier flushes the pipeline in the processor,
Kojto 91:031413cf7a89 89 so that all instructions following the ISB are fetched from cache or
Kojto 91:031413cf7a89 90 memory, after the instruction has been completed.
Kojto 91:031413cf7a89 91 */
Kojto 91:031413cf7a89 92 #define __ISB() __isb(0xF)
Kojto 91:031413cf7a89 93
Kojto 91:031413cf7a89 94
Kojto 91:031413cf7a89 95 /** \brief Data Synchronization Barrier
Kojto 91:031413cf7a89 96
Kojto 91:031413cf7a89 97 This function acts as a special kind of Data Memory Barrier.
Kojto 91:031413cf7a89 98 It completes when all explicit memory accesses before this instruction complete.
Kojto 91:031413cf7a89 99 */
Kojto 91:031413cf7a89 100 #define __DSB() __dsb(0xF)
Kojto 91:031413cf7a89 101
Kojto 91:031413cf7a89 102
Kojto 91:031413cf7a89 103 /** \brief Data Memory Barrier
Kojto 91:031413cf7a89 104
Kojto 91:031413cf7a89 105 This function ensures the apparent order of the explicit memory operations before
Kojto 91:031413cf7a89 106 and after the instruction, without ensuring their completion.
Kojto 91:031413cf7a89 107 */
Kojto 91:031413cf7a89 108 #define __DMB() __dmb(0xF)
Kojto 91:031413cf7a89 109
Kojto 91:031413cf7a89 110
Kojto 91:031413cf7a89 111 /** \brief Reverse byte order (32 bit)
Kojto 91:031413cf7a89 112
Kojto 91:031413cf7a89 113 This function reverses the byte order in integer value.
Kojto 91:031413cf7a89 114
Kojto 91:031413cf7a89 115 \param [in] value Value to reverse
Kojto 91:031413cf7a89 116 \return Reversed value
Kojto 91:031413cf7a89 117 */
Kojto 91:031413cf7a89 118 #define __REV __rev
Kojto 91:031413cf7a89 119
Kojto 91:031413cf7a89 120
Kojto 91:031413cf7a89 121 /** \brief Reverse byte order (16 bit)
Kojto 91:031413cf7a89 122
Kojto 91:031413cf7a89 123 This function reverses the byte order in two unsigned short values.
Kojto 91:031413cf7a89 124
Kojto 91:031413cf7a89 125 \param [in] value Value to reverse
Kojto 91:031413cf7a89 126 \return Reversed value
Kojto 91:031413cf7a89 127 */
Kojto 91:031413cf7a89 128 #ifndef __NO_EMBEDDED_ASM
Kojto 91:031413cf7a89 129 __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
Kojto 91:031413cf7a89 130 {
Kojto 91:031413cf7a89 131 rev16 r0, r0
Kojto 91:031413cf7a89 132 bx lr
Kojto 91:031413cf7a89 133 }
Kojto 91:031413cf7a89 134 #endif
Kojto 91:031413cf7a89 135
Kojto 91:031413cf7a89 136 /** \brief Reverse byte order in signed short value
Kojto 91:031413cf7a89 137
Kojto 91:031413cf7a89 138 This function reverses the byte order in a signed short value with sign extension to integer.
Kojto 91:031413cf7a89 139
Kojto 91:031413cf7a89 140 \param [in] value Value to reverse
Kojto 91:031413cf7a89 141 \return Reversed value
Kojto 91:031413cf7a89 142 */
Kojto 91:031413cf7a89 143 #ifndef __NO_EMBEDDED_ASM
Kojto 91:031413cf7a89 144 __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
Kojto 91:031413cf7a89 145 {
Kojto 91:031413cf7a89 146 revsh r0, r0
Kojto 91:031413cf7a89 147 bx lr
Kojto 91:031413cf7a89 148 }
Kojto 91:031413cf7a89 149 #endif
Kojto 91:031413cf7a89 150
Kojto 91:031413cf7a89 151
Kojto 91:031413cf7a89 152 /** \brief Rotate Right in unsigned value (32 bit)
Kojto 91:031413cf7a89 153
Kojto 91:031413cf7a89 154 This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
Kojto 91:031413cf7a89 155
Kojto 91:031413cf7a89 156 \param [in] value Value to rotate
Kojto 91:031413cf7a89 157 \param [in] value Number of Bits to rotate
Kojto 91:031413cf7a89 158 \return Rotated value
Kojto 91:031413cf7a89 159 */
Kojto 91:031413cf7a89 160 #define __ROR __ror
Kojto 91:031413cf7a89 161
Kojto 91:031413cf7a89 162
Kojto 91:031413cf7a89 163 /** \brief Breakpoint
Kojto 91:031413cf7a89 164
Kojto 91:031413cf7a89 165 This function causes the processor to enter Debug state.
Kojto 91:031413cf7a89 166 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
Kojto 91:031413cf7a89 167
Kojto 91:031413cf7a89 168 \param [in] value is ignored by the processor.
Kojto 91:031413cf7a89 169 If required, a debugger can use it to store additional information about the breakpoint.
Kojto 91:031413cf7a89 170 */
Kojto 91:031413cf7a89 171 #define __BKPT(value) __breakpoint(value)
Kojto 91:031413cf7a89 172
Kojto 91:031413cf7a89 173
Kojto 91:031413cf7a89 174 #if (__CORTEX_M >= 0x03)
Kojto 91:031413cf7a89 175
Kojto 91:031413cf7a89 176 /** \brief Reverse bit order of value
Kojto 91:031413cf7a89 177
Kojto 91:031413cf7a89 178 This function reverses the bit order of the given value.
Kojto 91:031413cf7a89 179
Kojto 91:031413cf7a89 180 \param [in] value Value to reverse
Kojto 91:031413cf7a89 181 \return Reversed value
Kojto 91:031413cf7a89 182 */
Kojto 91:031413cf7a89 183 #define __RBIT __rbit
Kojto 91:031413cf7a89 184
Kojto 91:031413cf7a89 185
Kojto 91:031413cf7a89 186 /** \brief LDR Exclusive (8 bit)
Kojto 91:031413cf7a89 187
Kojto 91:031413cf7a89 188 This function performs a exclusive LDR command for 8 bit value.
Kojto 91:031413cf7a89 189
Kojto 91:031413cf7a89 190 \param [in] ptr Pointer to data
Kojto 91:031413cf7a89 191 \return value of type uint8_t at (*ptr)
Kojto 91:031413cf7a89 192 */
Kojto 91:031413cf7a89 193 #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
Kojto 91:031413cf7a89 194
Kojto 91:031413cf7a89 195
Kojto 91:031413cf7a89 196 /** \brief LDR Exclusive (16 bit)
Kojto 91:031413cf7a89 197
Kojto 91:031413cf7a89 198 This function performs a exclusive LDR command for 16 bit values.
Kojto 91:031413cf7a89 199
Kojto 91:031413cf7a89 200 \param [in] ptr Pointer to data
Kojto 91:031413cf7a89 201 \return value of type uint16_t at (*ptr)
Kojto 91:031413cf7a89 202 */
Kojto 91:031413cf7a89 203 #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
Kojto 91:031413cf7a89 204
Kojto 91:031413cf7a89 205
Kojto 91:031413cf7a89 206 /** \brief LDR Exclusive (32 bit)
Kojto 91:031413cf7a89 207
Kojto 91:031413cf7a89 208 This function performs a exclusive LDR command for 32 bit values.
Kojto 91:031413cf7a89 209
Kojto 91:031413cf7a89 210 \param [in] ptr Pointer to data
Kojto 91:031413cf7a89 211 \return value of type uint32_t at (*ptr)
Kojto 91:031413cf7a89 212 */
Kojto 91:031413cf7a89 213 #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
Kojto 91:031413cf7a89 214
Kojto 91:031413cf7a89 215
Kojto 91:031413cf7a89 216 /** \brief STR Exclusive (8 bit)
Kojto 91:031413cf7a89 217
Kojto 91:031413cf7a89 218 This function performs a exclusive STR command for 8 bit values.
Kojto 91:031413cf7a89 219
Kojto 91:031413cf7a89 220 \param [in] value Value to store
Kojto 91:031413cf7a89 221 \param [in] ptr Pointer to location
Kojto 91:031413cf7a89 222 \return 0 Function succeeded
Kojto 91:031413cf7a89 223 \return 1 Function failed
Kojto 91:031413cf7a89 224 */
Kojto 91:031413cf7a89 225 #define __STREXB(value, ptr) __strex(value, ptr)
Kojto 91:031413cf7a89 226
Kojto 91:031413cf7a89 227
Kojto 91:031413cf7a89 228 /** \brief STR Exclusive (16 bit)
Kojto 91:031413cf7a89 229
Kojto 91:031413cf7a89 230 This function performs a exclusive STR command for 16 bit values.
Kojto 91:031413cf7a89 231
Kojto 91:031413cf7a89 232 \param [in] value Value to store
Kojto 91:031413cf7a89 233 \param [in] ptr Pointer to location
Kojto 91:031413cf7a89 234 \return 0 Function succeeded
Kojto 91:031413cf7a89 235 \return 1 Function failed
Kojto 91:031413cf7a89 236 */
Kojto 91:031413cf7a89 237 #define __STREXH(value, ptr) __strex(value, ptr)
Kojto 91:031413cf7a89 238
Kojto 91:031413cf7a89 239
Kojto 91:031413cf7a89 240 /** \brief STR Exclusive (32 bit)
Kojto 91:031413cf7a89 241
Kojto 91:031413cf7a89 242 This function performs a exclusive STR command for 32 bit values.
Kojto 91:031413cf7a89 243
Kojto 91:031413cf7a89 244 \param [in] value Value to store
Kojto 91:031413cf7a89 245 \param [in] ptr Pointer to location
Kojto 91:031413cf7a89 246 \return 0 Function succeeded
Kojto 91:031413cf7a89 247 \return 1 Function failed
Kojto 91:031413cf7a89 248 */
Kojto 91:031413cf7a89 249 #define __STREXW(value, ptr) __strex(value, ptr)
Kojto 91:031413cf7a89 250
Kojto 91:031413cf7a89 251
Kojto 91:031413cf7a89 252 /** \brief Remove the exclusive lock
Kojto 91:031413cf7a89 253
Kojto 91:031413cf7a89 254 This function removes the exclusive lock which is created by LDREX.
Kojto 91:031413cf7a89 255
Kojto 91:031413cf7a89 256 */
Kojto 91:031413cf7a89 257 #define __CLREX __clrex
Kojto 91:031413cf7a89 258
Kojto 91:031413cf7a89 259
Kojto 91:031413cf7a89 260 /** \brief Signed Saturate
Kojto 91:031413cf7a89 261
Kojto 91:031413cf7a89 262 This function saturates a signed value.
Kojto 91:031413cf7a89 263
Kojto 91:031413cf7a89 264 \param [in] value Value to be saturated
Kojto 91:031413cf7a89 265 \param [in] sat Bit position to saturate to (1..32)
Kojto 91:031413cf7a89 266 \return Saturated value
Kojto 91:031413cf7a89 267 */
Kojto 91:031413cf7a89 268 #define __SSAT __ssat
Kojto 91:031413cf7a89 269
Kojto 91:031413cf7a89 270
Kojto 91:031413cf7a89 271 /** \brief Unsigned Saturate
Kojto 91:031413cf7a89 272
Kojto 91:031413cf7a89 273 This function saturates an unsigned value.
Kojto 91:031413cf7a89 274
Kojto 91:031413cf7a89 275 \param [in] value Value to be saturated
Kojto 91:031413cf7a89 276 \param [in] sat Bit position to saturate to (0..31)
Kojto 91:031413cf7a89 277 \return Saturated value
Kojto 91:031413cf7a89 278 */
Kojto 91:031413cf7a89 279 #define __USAT __usat
Kojto 91:031413cf7a89 280
Kojto 91:031413cf7a89 281
Kojto 91:031413cf7a89 282 /** \brief Count leading zeros
Kojto 91:031413cf7a89 283
Kojto 91:031413cf7a89 284 This function counts the number of leading zeros of a data value.
Kojto 91:031413cf7a89 285
Kojto 91:031413cf7a89 286 \param [in] value Value to count the leading zeros
Kojto 91:031413cf7a89 287 \return number of leading zeros in value
Kojto 91:031413cf7a89 288 */
Kojto 91:031413cf7a89 289 #define __CLZ __clz
Kojto 91:031413cf7a89 290
Kojto 91:031413cf7a89 291 #endif /* (__CORTEX_M >= 0x03) */
Kojto 91:031413cf7a89 292
Kojto 91:031413cf7a89 293
Kojto 91:031413cf7a89 294
Kojto 91:031413cf7a89 295 #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
Kojto 91:031413cf7a89 296 /* IAR iccarm specific functions */
Kojto 91:031413cf7a89 297
Kojto 91:031413cf7a89 298 #include <cmsis_iar.h>
Kojto 91:031413cf7a89 299
Kojto 91:031413cf7a89 300
Kojto 91:031413cf7a89 301 #elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
Kojto 91:031413cf7a89 302 /* TI CCS specific functions */
Kojto 91:031413cf7a89 303
Kojto 91:031413cf7a89 304 #include <cmsis_ccs.h>
Kojto 91:031413cf7a89 305
Kojto 91:031413cf7a89 306
Kojto 91:031413cf7a89 307 #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
Kojto 91:031413cf7a89 308 /* GNU gcc specific functions */
Kojto 91:031413cf7a89 309
Kojto 91:031413cf7a89 310 /* Define macros for porting to both thumb1 and thumb2.
Kojto 91:031413cf7a89 311 * For thumb1, use low register (r0-r7), specified by constrant "l"
Kojto 91:031413cf7a89 312 * Otherwise, use general registers, specified by constrant "r" */
Kojto 91:031413cf7a89 313 #if defined (__thumb__) && !defined (__thumb2__)
Kojto 91:031413cf7a89 314 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
Kojto 91:031413cf7a89 315 #define __CMSIS_GCC_USE_REG(r) "l" (r)
Kojto 91:031413cf7a89 316 #else
Kojto 91:031413cf7a89 317 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
Kojto 91:031413cf7a89 318 #define __CMSIS_GCC_USE_REG(r) "r" (r)
Kojto 91:031413cf7a89 319 #endif
Kojto 91:031413cf7a89 320
Kojto 91:031413cf7a89 321 /** \brief No Operation
Kojto 91:031413cf7a89 322
Kojto 91:031413cf7a89 323 No Operation does nothing. This instruction can be used for code alignment purposes.
Kojto 91:031413cf7a89 324 */
Kojto 91:031413cf7a89 325 __attribute__( ( always_inline ) ) __STATIC_INLINE void __NOP(void)
Kojto 91:031413cf7a89 326 {
Kojto 91:031413cf7a89 327 __ASM volatile ("nop");
Kojto 91:031413cf7a89 328 }
Kojto 91:031413cf7a89 329
Kojto 91:031413cf7a89 330
Kojto 91:031413cf7a89 331 /** \brief Wait For Interrupt
Kojto 91:031413cf7a89 332
Kojto 91:031413cf7a89 333 Wait For Interrupt is a hint instruction that suspends execution
Kojto 91:031413cf7a89 334 until one of a number of events occurs.
Kojto 91:031413cf7a89 335 */
Kojto 91:031413cf7a89 336 __attribute__( ( always_inline ) ) __STATIC_INLINE void __WFI(void)
Kojto 91:031413cf7a89 337 {
Kojto 91:031413cf7a89 338 __ASM volatile ("wfi");
Kojto 91:031413cf7a89 339 }
Kojto 91:031413cf7a89 340
Kojto 91:031413cf7a89 341
Kojto 91:031413cf7a89 342 /** \brief Wait For Event
Kojto 91:031413cf7a89 343
Kojto 91:031413cf7a89 344 Wait For Event is a hint instruction that permits the processor to enter
Kojto 91:031413cf7a89 345 a low-power state until one of a number of events occurs.
Kojto 91:031413cf7a89 346 */
Kojto 91:031413cf7a89 347 __attribute__( ( always_inline ) ) __STATIC_INLINE void __WFE(void)
Kojto 91:031413cf7a89 348 {
Kojto 91:031413cf7a89 349 __ASM volatile ("wfe");
Kojto 91:031413cf7a89 350 }
Kojto 91:031413cf7a89 351
Kojto 91:031413cf7a89 352
Kojto 91:031413cf7a89 353 /** \brief Send Event
Kojto 91:031413cf7a89 354
Kojto 91:031413cf7a89 355 Send Event is a hint instruction. It causes an event to be signaled to the CPU.
Kojto 91:031413cf7a89 356 */
Kojto 91:031413cf7a89 357 __attribute__( ( always_inline ) ) __STATIC_INLINE void __SEV(void)
Kojto 91:031413cf7a89 358 {
Kojto 91:031413cf7a89 359 __ASM volatile ("sev");
Kojto 91:031413cf7a89 360 }
Kojto 91:031413cf7a89 361
Kojto 91:031413cf7a89 362
Kojto 91:031413cf7a89 363 /** \brief Instruction Synchronization Barrier
Kojto 91:031413cf7a89 364
Kojto 91:031413cf7a89 365 Instruction Synchronization Barrier flushes the pipeline in the processor,
Kojto 91:031413cf7a89 366 so that all instructions following the ISB are fetched from cache or
Kojto 91:031413cf7a89 367 memory, after the instruction has been completed.
Kojto 91:031413cf7a89 368 */
Kojto 91:031413cf7a89 369 __attribute__( ( always_inline ) ) __STATIC_INLINE void __ISB(void)
Kojto 91:031413cf7a89 370 {
Kojto 91:031413cf7a89 371 __ASM volatile ("isb");
Kojto 91:031413cf7a89 372 }
Kojto 91:031413cf7a89 373
Kojto 91:031413cf7a89 374
Kojto 91:031413cf7a89 375 /** \brief Data Synchronization Barrier
Kojto 91:031413cf7a89 376
Kojto 91:031413cf7a89 377 This function acts as a special kind of Data Memory Barrier.
Kojto 91:031413cf7a89 378 It completes when all explicit memory accesses before this instruction complete.
Kojto 91:031413cf7a89 379 */
Kojto 91:031413cf7a89 380 __attribute__( ( always_inline ) ) __STATIC_INLINE void __DSB(void)
Kojto 91:031413cf7a89 381 {
Kojto 91:031413cf7a89 382 __ASM volatile ("dsb");
Kojto 91:031413cf7a89 383 }
Kojto 91:031413cf7a89 384
Kojto 91:031413cf7a89 385
Kojto 91:031413cf7a89 386 /** \brief Data Memory Barrier
Kojto 91:031413cf7a89 387
Kojto 91:031413cf7a89 388 This function ensures the apparent order of the explicit memory operations before
Kojto 91:031413cf7a89 389 and after the instruction, without ensuring their completion.
Kojto 91:031413cf7a89 390 */
Kojto 91:031413cf7a89 391 __attribute__( ( always_inline ) ) __STATIC_INLINE void __DMB(void)
Kojto 91:031413cf7a89 392 {
Kojto 91:031413cf7a89 393 __ASM volatile ("dmb");
Kojto 91:031413cf7a89 394 }
Kojto 91:031413cf7a89 395
Kojto 91:031413cf7a89 396
Kojto 91:031413cf7a89 397 /** \brief Reverse byte order (32 bit)
Kojto 91:031413cf7a89 398
Kojto 91:031413cf7a89 399 This function reverses the byte order in integer value.
Kojto 91:031413cf7a89 400
Kojto 91:031413cf7a89 401 \param [in] value Value to reverse
Kojto 91:031413cf7a89 402 \return Reversed value
Kojto 91:031413cf7a89 403 */
Kojto 91:031413cf7a89 404 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV(uint32_t value)
Kojto 91:031413cf7a89 405 {
Kojto 91:031413cf7a89 406 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
Kojto 91:031413cf7a89 407 return __builtin_bswap32(value);
Kojto 91:031413cf7a89 408 #else
Kojto 91:031413cf7a89 409 uint32_t result;
Kojto 91:031413cf7a89 410
Kojto 91:031413cf7a89 411 __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
Kojto 91:031413cf7a89 412 return(result);
Kojto 91:031413cf7a89 413 #endif
Kojto 91:031413cf7a89 414 }
Kojto 91:031413cf7a89 415
Kojto 91:031413cf7a89 416
Kojto 91:031413cf7a89 417 /** \brief Reverse byte order (16 bit)
Kojto 91:031413cf7a89 418
Kojto 91:031413cf7a89 419 This function reverses the byte order in two unsigned short values.
Kojto 91:031413cf7a89 420
Kojto 91:031413cf7a89 421 \param [in] value Value to reverse
Kojto 91:031413cf7a89 422 \return Reversed value
Kojto 91:031413cf7a89 423 */
Kojto 91:031413cf7a89 424 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV16(uint32_t value)
Kojto 91:031413cf7a89 425 {
Kojto 91:031413cf7a89 426 uint32_t result;
Kojto 91:031413cf7a89 427
Kojto 91:031413cf7a89 428 __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
Kojto 91:031413cf7a89 429 return(result);
Kojto 91:031413cf7a89 430 }
Kojto 91:031413cf7a89 431
Kojto 91:031413cf7a89 432
Kojto 91:031413cf7a89 433 /** \brief Reverse byte order in signed short value
Kojto 91:031413cf7a89 434
Kojto 91:031413cf7a89 435 This function reverses the byte order in a signed short value with sign extension to integer.
Kojto 91:031413cf7a89 436
Kojto 91:031413cf7a89 437 \param [in] value Value to reverse
Kojto 91:031413cf7a89 438 \return Reversed value
Kojto 91:031413cf7a89 439 */
Kojto 91:031413cf7a89 440 __attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __REVSH(int32_t value)
Kojto 91:031413cf7a89 441 {
Kojto 91:031413cf7a89 442 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
Kojto 91:031413cf7a89 443 return (short)__builtin_bswap16(value);
Kojto 91:031413cf7a89 444 #else
Kojto 91:031413cf7a89 445 uint32_t result;
Kojto 91:031413cf7a89 446
Kojto 91:031413cf7a89 447 __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
Kojto 91:031413cf7a89 448 return(result);
Kojto 91:031413cf7a89 449 #endif
Kojto 91:031413cf7a89 450 }
Kojto 91:031413cf7a89 451
Kojto 91:031413cf7a89 452
Kojto 91:031413cf7a89 453 /** \brief Rotate Right in unsigned value (32 bit)
Kojto 91:031413cf7a89 454
Kojto 91:031413cf7a89 455 This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
Kojto 91:031413cf7a89 456
Kojto 91:031413cf7a89 457 \param [in] value Value to rotate
Kojto 91:031413cf7a89 458 \param [in] value Number of Bits to rotate
Kojto 91:031413cf7a89 459 \return Rotated value
Kojto 91:031413cf7a89 460 */
Kojto 91:031413cf7a89 461 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
Kojto 91:031413cf7a89 462 {
Kojto 91:031413cf7a89 463 return (op1 >> op2) | (op1 << (32 - op2));
Kojto 91:031413cf7a89 464 }
Kojto 91:031413cf7a89 465
Kojto 91:031413cf7a89 466
Kojto 91:031413cf7a89 467 /** \brief Breakpoint
Kojto 91:031413cf7a89 468
Kojto 91:031413cf7a89 469 This function causes the processor to enter Debug state.
Kojto 91:031413cf7a89 470 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
Kojto 91:031413cf7a89 471
Kojto 91:031413cf7a89 472 \param [in] value is ignored by the processor.
Kojto 91:031413cf7a89 473 If required, a debugger can use it to store additional information about the breakpoint.
Kojto 91:031413cf7a89 474 */
Kojto 91:031413cf7a89 475 #define __BKPT(value) __ASM volatile ("bkpt "#value)
Kojto 91:031413cf7a89 476
Kojto 91:031413cf7a89 477
Kojto 91:031413cf7a89 478 #if (__CORTEX_M >= 0x03)
Kojto 91:031413cf7a89 479
Kojto 91:031413cf7a89 480 /** \brief Reverse bit order of value
Kojto 91:031413cf7a89 481
Kojto 91:031413cf7a89 482 This function reverses the bit order of the given value.
Kojto 91:031413cf7a89 483
Kojto 91:031413cf7a89 484 \param [in] value Value to reverse
Kojto 91:031413cf7a89 485 \return Reversed value
Kojto 91:031413cf7a89 486 */
Kojto 91:031413cf7a89 487 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
Kojto 91:031413cf7a89 488 {
Kojto 91:031413cf7a89 489 uint32_t result;
Kojto 91:031413cf7a89 490
Kojto 91:031413cf7a89 491 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
Kojto 91:031413cf7a89 492 return(result);
Kojto 91:031413cf7a89 493 }
Kojto 91:031413cf7a89 494
Kojto 91:031413cf7a89 495
Kojto 91:031413cf7a89 496 /** \brief LDR Exclusive (8 bit)
Kojto 91:031413cf7a89 497
Kojto 91:031413cf7a89 498 This function performs a exclusive LDR command for 8 bit value.
Kojto 91:031413cf7a89 499
Kojto 91:031413cf7a89 500 \param [in] ptr Pointer to data
Kojto 91:031413cf7a89 501 \return value of type uint8_t at (*ptr)
Kojto 91:031413cf7a89 502 */
Kojto 91:031413cf7a89 503 __attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
Kojto 91:031413cf7a89 504 {
Kojto 91:031413cf7a89 505 uint32_t result;
Kojto 91:031413cf7a89 506
Kojto 91:031413cf7a89 507 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
Kojto 91:031413cf7a89 508 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
Kojto 91:031413cf7a89 509 #else
Kojto 91:031413cf7a89 510 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
Kojto 91:031413cf7a89 511 accepted by assembler. So has to use following less efficient pattern.
Kojto 91:031413cf7a89 512 */
Kojto 91:031413cf7a89 513 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
Kojto 91:031413cf7a89 514 #endif
Kojto 91:031413cf7a89 515 return(result);
Kojto 91:031413cf7a89 516 }
Kojto 91:031413cf7a89 517
Kojto 91:031413cf7a89 518
Kojto 91:031413cf7a89 519 /** \brief LDR Exclusive (16 bit)
Kojto 91:031413cf7a89 520
Kojto 91:031413cf7a89 521 This function performs a exclusive LDR command for 16 bit values.
Kojto 91:031413cf7a89 522
Kojto 91:031413cf7a89 523 \param [in] ptr Pointer to data
Kojto 91:031413cf7a89 524 \return value of type uint16_t at (*ptr)
Kojto 91:031413cf7a89 525 */
Kojto 91:031413cf7a89 526 __attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
Kojto 91:031413cf7a89 527 {
Kojto 91:031413cf7a89 528 uint32_t result;
Kojto 91:031413cf7a89 529
Kojto 91:031413cf7a89 530 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
Kojto 91:031413cf7a89 531 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
Kojto 91:031413cf7a89 532 #else
Kojto 91:031413cf7a89 533 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
Kojto 91:031413cf7a89 534 accepted by assembler. So has to use following less efficient pattern.
Kojto 91:031413cf7a89 535 */
Kojto 91:031413cf7a89 536 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
Kojto 91:031413cf7a89 537 #endif
Kojto 91:031413cf7a89 538 return(result);
Kojto 91:031413cf7a89 539 }
Kojto 91:031413cf7a89 540
Kojto 91:031413cf7a89 541
Kojto 91:031413cf7a89 542 /** \brief LDR Exclusive (32 bit)
Kojto 91:031413cf7a89 543
Kojto 91:031413cf7a89 544 This function performs a exclusive LDR command for 32 bit values.
Kojto 91:031413cf7a89 545
Kojto 91:031413cf7a89 546 \param [in] ptr Pointer to data
Kojto 91:031413cf7a89 547 \return value of type uint32_t at (*ptr)
Kojto 91:031413cf7a89 548 */
Kojto 91:031413cf7a89 549 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
Kojto 91:031413cf7a89 550 {
Kojto 91:031413cf7a89 551 uint32_t result;
Kojto 91:031413cf7a89 552
Kojto 91:031413cf7a89 553 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
Kojto 91:031413cf7a89 554 return(result);
Kojto 91:031413cf7a89 555 }
Kojto 91:031413cf7a89 556
Kojto 91:031413cf7a89 557
Kojto 91:031413cf7a89 558 /** \brief STR Exclusive (8 bit)
Kojto 91:031413cf7a89 559
Kojto 91:031413cf7a89 560 This function performs a exclusive STR command for 8 bit values.
Kojto 91:031413cf7a89 561
Kojto 91:031413cf7a89 562 \param [in] value Value to store
Kojto 91:031413cf7a89 563 \param [in] ptr Pointer to location
Kojto 91:031413cf7a89 564 \return 0 Function succeeded
Kojto 91:031413cf7a89 565 \return 1 Function failed
Kojto 91:031413cf7a89 566 */
Kojto 91:031413cf7a89 567 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
Kojto 91:031413cf7a89 568 {
Kojto 91:031413cf7a89 569 uint32_t result;
Kojto 91:031413cf7a89 570
Kojto 91:031413cf7a89 571 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
Kojto 91:031413cf7a89 572 return(result);
Kojto 91:031413cf7a89 573 }
Kojto 91:031413cf7a89 574
Kojto 91:031413cf7a89 575
Kojto 91:031413cf7a89 576 /** \brief STR Exclusive (16 bit)
Kojto 91:031413cf7a89 577
Kojto 91:031413cf7a89 578 This function performs a exclusive STR command for 16 bit values.
Kojto 91:031413cf7a89 579
Kojto 91:031413cf7a89 580 \param [in] value Value to store
Kojto 91:031413cf7a89 581 \param [in] ptr Pointer to location
Kojto 91:031413cf7a89 582 \return 0 Function succeeded
Kojto 91:031413cf7a89 583 \return 1 Function failed
Kojto 91:031413cf7a89 584 */
Kojto 91:031413cf7a89 585 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
Kojto 91:031413cf7a89 586 {
Kojto 91:031413cf7a89 587 uint32_t result;
Kojto 91:031413cf7a89 588
Kojto 91:031413cf7a89 589 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
Kojto 91:031413cf7a89 590 return(result);
Kojto 91:031413cf7a89 591 }
Kojto 91:031413cf7a89 592
Kojto 91:031413cf7a89 593
Kojto 91:031413cf7a89 594 /** \brief STR Exclusive (32 bit)
Kojto 91:031413cf7a89 595
Kojto 91:031413cf7a89 596 This function performs a exclusive STR command for 32 bit values.
Kojto 91:031413cf7a89 597
Kojto 91:031413cf7a89 598 \param [in] value Value to store
Kojto 91:031413cf7a89 599 \param [in] ptr Pointer to location
Kojto 91:031413cf7a89 600 \return 0 Function succeeded
Kojto 91:031413cf7a89 601 \return 1 Function failed
Kojto 91:031413cf7a89 602 */
Kojto 91:031413cf7a89 603 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
Kojto 91:031413cf7a89 604 {
Kojto 91:031413cf7a89 605 uint32_t result;
Kojto 91:031413cf7a89 606
Kojto 91:031413cf7a89 607 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
Kojto 91:031413cf7a89 608 return(result);
Kojto 91:031413cf7a89 609 }
Kojto 91:031413cf7a89 610
Kojto 91:031413cf7a89 611
Kojto 91:031413cf7a89 612 /** \brief Remove the exclusive lock
Kojto 91:031413cf7a89 613
Kojto 91:031413cf7a89 614 This function removes the exclusive lock which is created by LDREX.
Kojto 91:031413cf7a89 615
Kojto 91:031413cf7a89 616 */
Kojto 91:031413cf7a89 617 __attribute__( ( always_inline ) ) __STATIC_INLINE void __CLREX(void)
Kojto 91:031413cf7a89 618 {
Kojto 91:031413cf7a89 619 __ASM volatile ("clrex" ::: "memory");
Kojto 91:031413cf7a89 620 }
Kojto 91:031413cf7a89 621
Kojto 91:031413cf7a89 622
Kojto 91:031413cf7a89 623 /** \brief Signed Saturate
Kojto 91:031413cf7a89 624
Kojto 91:031413cf7a89 625 This function saturates a signed value.
Kojto 91:031413cf7a89 626
Kojto 91:031413cf7a89 627 \param [in] value Value to be saturated
Kojto 91:031413cf7a89 628 \param [in] sat Bit position to saturate to (1..32)
Kojto 91:031413cf7a89 629 \return Saturated value
Kojto 91:031413cf7a89 630 */
Kojto 91:031413cf7a89 631 #define __SSAT(ARG1,ARG2) \
Kojto 91:031413cf7a89 632 ({ \
Kojto 91:031413cf7a89 633 uint32_t __RES, __ARG1 = (ARG1); \
Kojto 91:031413cf7a89 634 __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
Kojto 91:031413cf7a89 635 __RES; \
Kojto 91:031413cf7a89 636 })
Kojto 91:031413cf7a89 637
Kojto 91:031413cf7a89 638
Kojto 91:031413cf7a89 639 /** \brief Unsigned Saturate
Kojto 91:031413cf7a89 640
Kojto 91:031413cf7a89 641 This function saturates an unsigned value.
Kojto 91:031413cf7a89 642
Kojto 91:031413cf7a89 643 \param [in] value Value to be saturated
Kojto 91:031413cf7a89 644 \param [in] sat Bit position to saturate to (0..31)
Kojto 91:031413cf7a89 645 \return Saturated value
Kojto 91:031413cf7a89 646 */
Kojto 91:031413cf7a89 647 #define __USAT(ARG1,ARG2) \
Kojto 91:031413cf7a89 648 ({ \
Kojto 91:031413cf7a89 649 uint32_t __RES, __ARG1 = (ARG1); \
Kojto 91:031413cf7a89 650 __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
Kojto 91:031413cf7a89 651 __RES; \
Kojto 91:031413cf7a89 652 })
Kojto 91:031413cf7a89 653
Kojto 91:031413cf7a89 654
Kojto 91:031413cf7a89 655 /** \brief Count leading zeros
Kojto 91:031413cf7a89 656
Kojto 91:031413cf7a89 657 This function counts the number of leading zeros of a data value.
Kojto 91:031413cf7a89 658
Kojto 91:031413cf7a89 659 \param [in] value Value to count the leading zeros
Kojto 91:031413cf7a89 660 \return number of leading zeros in value
Kojto 91:031413cf7a89 661 */
Kojto 91:031413cf7a89 662 __attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __CLZ(uint32_t value)
Kojto 91:031413cf7a89 663 {
Kojto 91:031413cf7a89 664 uint32_t result;
Kojto 91:031413cf7a89 665
Kojto 91:031413cf7a89 666 __ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) );
Kojto 91:031413cf7a89 667 return(result);
Kojto 91:031413cf7a89 668 }
Kojto 91:031413cf7a89 669
Kojto 91:031413cf7a89 670 #endif /* (__CORTEX_M >= 0x03) */
Kojto 91:031413cf7a89 671
Kojto 91:031413cf7a89 672
Kojto 91:031413cf7a89 673
Kojto 91:031413cf7a89 674
Kojto 91:031413cf7a89 675 #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
Kojto 91:031413cf7a89 676 /* TASKING carm specific functions */
Kojto 91:031413cf7a89 677
Kojto 91:031413cf7a89 678 /*
Kojto 91:031413cf7a89 679 * The CMSIS functions have been implemented as intrinsics in the compiler.
Kojto 91:031413cf7a89 680 * Please use "carm -?i" to get an up to date list of all intrinsics,
Kojto 91:031413cf7a89 681 * Including the CMSIS ones.
Kojto 91:031413cf7a89 682 */
Kojto 91:031413cf7a89 683
Kojto 91:031413cf7a89 684 #endif
Kojto 91:031413cf7a89 685
Kojto 91:031413cf7a89 686 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
Kojto 91:031413cf7a89 687
Kojto 91:031413cf7a89 688 #endif /* __CORE_CMINSTR_H */