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:
Kojto
Date:
Tue Feb 14 11:24:20 2017 +0000
Revision:
136:ef9c61f8c49f
Parent:
110:165afa46840b
Release 136 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3432: Target STM USBHOST support https://github.com/ARMmbed/mbed-os/pull/3432
3181: NUCLEO_F207ZG extending PeripheralPins.c: all available alternate functions can be used now https://github.com/ARMmbed/mbed-os/pull/3181
3626: NUCLEO_F412ZG : Add USB Device +Host https://github.com/ARMmbed/mbed-os/pull/3626
3628: Fix warnings https://github.com/ARMmbed/mbed-os/pull/3628
3629: STM32: L0 LL layer https://github.com/ARMmbed/mbed-os/pull/3629
3632: IDE Export support for platform VK_RZ_A1H https://github.com/ARMmbed/mbed-os/pull/3632
3642: Missing IRQ pin fix for platform VK_RZ_A1H https://github.com/ARMmbed/mbed-os/pull/3642
3664: Fix ncs36510 sleep definitions https://github.com/ARMmbed/mbed-os/pull/3664
3655: [STM32F4] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3655
3657: [STM32L4] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3657
3658: [STM32F3] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3658
3685: STM32: I2C: reset state machine https://github.com/ARMmbed/mbed-os/pull/3685
3692: uVisor: Standardize available legacy heap and stack https://github.com/ARMmbed/mbed-os/pull/3692
3621: Fix for #2884, LPC824: export to LPCXpresso, target running with wron https://github.com/ARMmbed/mbed-os/pull/3621
3649: [STM32F7] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3649
3695: Enforce device_name is valid in targets.json https://github.com/ARMmbed/mbed-os/pull/3695
3723: NCS36510: spi_format function bug fix https://github.com/ARMmbed/mbed-os/pull/3723

Who changed what in which revision?

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