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