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 Apr 29 10:16:23 2015 +0100
Revision:
98:8ab26030e058
Child:
110:165afa46840b
Release 98 of the mbed library

Changes:
- Silabs new targets (Giant, Zero, Happy, Leopard, Wonder Geckos)
- Asynchronous SPI, I2C, Serial
- LowPower classes
- Nordic - nordic SDK v8.0 update
- Teensy - gcc arm fix for startup
- Nucleo F411 - usb freq fix

Who changed what in which revision?

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