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:
Wed Apr 12 16:07:08 2017 +0100
Revision:
140:97feb9bacc10
Parent:
111:4336505e4b1c
Release 140 of the mbed library

Ports for Upcoming Targets

3841: Add nRf52840 target https://github.com/ARMmbed/mbed-os/pull/3841
3992: Introducing UBLOX_C030 platform. https://github.com/ARMmbed/mbed-os/pull/3992

Fixes and Changes

3951: [NUCLEO_F303ZE] Correct ARDUINO pin https://github.com/ARMmbed/mbed-os/pull/3951
4021: Fixing a macro to detect when RTOS was in use for the NRF52840_DK https://github.com/ARMmbed/mbed-os/pull/4021
3979: KW24D: Add missing SPI defines and Arduino connector definitions https://github.com/ARMmbed/mbed-os/pull/3979
3990: UBLOX_C027: construct a ticker-based wait, rather than calling wait_ms(), in the https://github.com/ARMmbed/mbed-os/pull/3990
4003: Fixed OBOE in async serial tx for NRF52 target, fixes #4002 https://github.com/ARMmbed/mbed-os/pull/4003
4012: STM32: Correct I2C master error handling https://github.com/ARMmbed/mbed-os/pull/4012
4020: NUCLEO_L011K4 remove unsupported tool chain files https://github.com/ARMmbed/mbed-os/pull/4020
4065: K66F: Move bss section to m_data_2 Section https://github.com/ARMmbed/mbed-os/pull/4065
4014: Issue 3763: Reduce heap allocation in the GCC linker file https://github.com/ARMmbed/mbed-os/pull/4014
4030: [STM32L0] reduce IAR heap and stack size for small targets https://github.com/ARMmbed/mbed-os/pull/4030
4109: NUCLEO_L476RG : minor serial pin update https://github.com/ARMmbed/mbed-os/pull/4109
3982: Ticker - kl25z bugfix for handling events in the past https://github.com/ARMmbed/mbed-os/pull/3982

Who changed what in which revision?

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