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:
Tue Mar 14 16:20:51 2017 +0000
Revision:
138:093f2bd7b9eb
Parent:
112:6f327212ef96
Release 138 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3716: fix for issue #3715: correction in startup files for ARM and IAR, alignment of system_stm32f429xx.c files https://github.com/ARMmbed/mbed-os/pull/3716
3741: STM32 remove warning in hal_tick_32b.c file https://github.com/ARMmbed/mbed-os/pull/3741
3780: STM32L4 : Fix GPIO G port compatibility https://github.com/ARMmbed/mbed-os/pull/3780
3831: NCS36510: SPISLAVE enabled (Conflict resolved) https://github.com/ARMmbed/mbed-os/pull/3831
3836: Allow to redefine nRF's PSTORAGE_NUM_OF_PAGES outside of the mbed-os https://github.com/ARMmbed/mbed-os/pull/3836
3840: STM32: gpio SPEED - always set High Speed by default https://github.com/ARMmbed/mbed-os/pull/3840
3844: STM32 GPIO: Typo correction. Update comment (GPIO_IP_WITHOUT_BRR) https://github.com/ARMmbed/mbed-os/pull/3844
3850: STM32: change spi error to debug warning https://github.com/ARMmbed/mbed-os/pull/3850
3860: Define GPIO_IP_WITHOUT_BRR for xDot platform https://github.com/ARMmbed/mbed-os/pull/3860
3880: DISCO_F469NI: allow the use of CAN2 instance when CAN1 is not activated https://github.com/ARMmbed/mbed-os/pull/3880
3795: Fix pwm period calc https://github.com/ARMmbed/mbed-os/pull/3795
3828: STM32 CAN API: correct format and type https://github.com/ARMmbed/mbed-os/pull/3828
3842: TARGET_NRF: corrected spi_init() to properly handle re-initialization https://github.com/ARMmbed/mbed-os/pull/3842
3843: STM32L476xG: set APB2 clock to 80MHz (instead of 40MHz) https://github.com/ARMmbed/mbed-os/pull/3843
3879: NUCLEO_F446ZE: Add missing AnalogIn pins on PF_3, PF_5 and PF_10. https://github.com/ARMmbed/mbed-os/pull/3879
3902: Fix heap and stack size for NUCLEO_F746ZG https://github.com/ARMmbed/mbed-os/pull/3902
3829: can_write(): return error code when no tx mailboxes are available https://github.com/ARMmbed/mbed-os/pull/3829

Who changed what in which revision?

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