Martin Johnson / STM32F3-Discovery-minimal

Dependents:   accelerometer_test neopixel_square accelerometer_test_minimal Colour_Video_Demo

Committer:
MartinJohnson
Date:
Wed May 02 02:01:13 2018 +0000
Revision:
0:c65854d98061
Initial Version

Who changed what in which revision?

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