The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Fri May 26 12:30:20 2017 +0100
Revision:
143:86740a56073b
Parent:
122:f9eeca106725
Release 143 of the mbed library.

Who changed what in which revision?

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