mbed library sources. Supersedes mbed-src. Fixes analogIn and analogOut problems for TARGET_STM32F3. Tested on NUCLEO-F303K8, using 3 analogout and 7 analogin channels simultaneously. Added ability for STM32F334R8 and STM32F303K8 to use all three channels of DAC simultaneously. https://developer.mbed.org/users/StevieWray/code/mbed-dev/ Added ability for TARGET_STM32F3 to use more than one ADC simultaneously. https://developer.mbed.org/questions/67997/NUCLEO-F303K8ADC/

Fork of mbed-dev by mbed official

Committer:
neurofun
Date:
Tue Feb 23 21:59:35 2016 +0000
Revision:
70:b3a5af880266
Parent:
19:112740acecfa
Edited DAC routines to allow for the simultaneous use of three channels from two DACs as seen on the STM32F334R8 and STM32F303K8. Edited ADC routines to allow for the simultaneous use of more than one ADC.

Who changed what in which revision?

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