.

Dependents:   RTC

Committer:
jhon309
Date:
Thu Aug 13 00:20:09 2015 +0000
Revision:
0:88e313c910d0
RTC Example

Who changed what in which revision?

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