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:
<>
Date:
Mon Jan 16 12:05:23 2017 +0000
Revision:
134:ad3be0349dc5
Parent:
124:2241e3a39974
Release 134 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3488: Dev stm i2c v2 unitary functions https://github.com/ARMmbed/mbed-os/pull/3488
3492: Fix #3463 CAN read() return value https://github.com/ARMmbed/mbed-os/pull/3492
3503: [LPC15xx] Ensure that PWM=1 is resolved correctly https://github.com/ARMmbed/mbed-os/pull/3503
3504: [LPC15xx] CAN implementation improvements https://github.com/ARMmbed/mbed-os/pull/3504
3539: NUCLEO_F412ZG - Add support of TRNG peripheral https://github.com/ARMmbed/mbed-os/pull/3539
3540: STM: SPI: Initialize Rx in spi_master_write https://github.com/ARMmbed/mbed-os/pull/3540
3438: K64F: Add support for SERIAL ASYNCH API https://github.com/ARMmbed/mbed-os/pull/3438
3519: MCUXpresso: Fix ENET driver to enable interrupts after interrupt handler is set https://github.com/ARMmbed/mbed-os/pull/3519
3544: STM32L4 deepsleep improvement https://github.com/ARMmbed/mbed-os/pull/3544
3546: NUCLEO-F412ZG - Add CAN peripheral https://github.com/ARMmbed/mbed-os/pull/3546
3551: Fix I2C driver for RZ/A1H https://github.com/ARMmbed/mbed-os/pull/3551
3558: K64F UART Asynch API: Fix synchronization issue https://github.com/ARMmbed/mbed-os/pull/3558
3563: LPC4088 - Fix vector checksum https://github.com/ARMmbed/mbed-os/pull/3563
3567: Dev stm32 F0 v1.7.0 https://github.com/ARMmbed/mbed-os/pull/3567
3577: Fixes linking errors when building with debug profile https://github.com/ARMmbed/mbed-os/pull/3577

Who changed what in which revision?

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