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:
bogdanm
Date:
Wed Jul 02 13:22:23 2014 +0100
Revision:
86:04dd9b1680ae
Child:
110:165afa46840b
Release 86 of the mbed library

Main changes:


- bug fixes in various backends
- mbed "error" replaced by assert logic (mbed_assert)
- new ST Nucleo targets

Who changed what in which revision?

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