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