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