Martin Johnson / STM32F3-Discovery

Dependents:   Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more

Committer:
MartinJohnson
Date:
Mon May 09 04:00:25 2016 +0000
Revision:
0:404f5a4f1385
Initial library for STM32F3 discovery board

Who changed what in which revision?

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