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