Dataloger

Committer:
jhon309
Date:
Thu Aug 20 00:37:14 2015 +0000
Revision:
0:666850d06c9f
ok

Who changed what in which revision?

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