The official mbed C/C SDK provides the software platform and libraries to build your applications.
Fork of mbed by
TARGET_K22F/core_cmInstr.h@99:7f6c6de930c0, 2015-05-03 (annotated)
- Committer:
- Mikchel
- Date:
- Sun May 03 16:04:42 2015 +0000
- Revision:
- 99:7f6c6de930c0
- Parent:
- 90:cb3d968589d8
12
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 90:cb3d968589d8 | 1 | /**************************************************************************//** |
Kojto | 90:cb3d968589d8 | 2 | * @file core_cmInstr.h |
Kojto | 90:cb3d968589d8 | 3 | * @brief CMSIS Cortex-M Core Instruction Access Header File |
Kojto | 90:cb3d968589d8 | 4 | * @version V3.20 |
Kojto | 90:cb3d968589d8 | 5 | * @date 05. March 2013 |
Kojto | 90:cb3d968589d8 | 6 | * |
Kojto | 90:cb3d968589d8 | 7 | * @note |
Kojto | 90:cb3d968589d8 | 8 | * |
Kojto | 90:cb3d968589d8 | 9 | ******************************************************************************/ |
Kojto | 90:cb3d968589d8 | 10 | /* Copyright (c) 2009 - 2013 ARM LIMITED |
Kojto | 90:cb3d968589d8 | 11 | |
Kojto | 90:cb3d968589d8 | 12 | All rights reserved. |
Kojto | 90:cb3d968589d8 | 13 | Redistribution and use in source and binary forms, with or without |
Kojto | 90:cb3d968589d8 | 14 | modification, are permitted provided that the following conditions are met: |
Kojto | 90:cb3d968589d8 | 15 | - Redistributions of source code must retain the above copyright |
Kojto | 90:cb3d968589d8 | 16 | notice, this list of conditions and the following disclaimer. |
Kojto | 90:cb3d968589d8 | 17 | - Redistributions in binary form must reproduce the above copyright |
Kojto | 90:cb3d968589d8 | 18 | notice, this list of conditions and the following disclaimer in the |
Kojto | 90:cb3d968589d8 | 19 | documentation and/or other materials provided with the distribution. |
Kojto | 90:cb3d968589d8 | 20 | - Neither the name of ARM nor the names of its contributors may be used |
Kojto | 90:cb3d968589d8 | 21 | to endorse or promote products derived from this software without |
Kojto | 90:cb3d968589d8 | 22 | specific prior written permission. |
Kojto | 90:cb3d968589d8 | 23 | * |
Kojto | 90:cb3d968589d8 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Kojto | 90:cb3d968589d8 | 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Kojto | 90:cb3d968589d8 | 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
Kojto | 90:cb3d968589d8 | 27 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
Kojto | 90:cb3d968589d8 | 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
Kojto | 90:cb3d968589d8 | 29 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
Kojto | 90:cb3d968589d8 | 30 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
Kojto | 90:cb3d968589d8 | 31 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
Kojto | 90:cb3d968589d8 | 32 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
Kojto | 90:cb3d968589d8 | 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
Kojto | 90:cb3d968589d8 | 34 | POSSIBILITY OF SUCH DAMAGE. |
Kojto | 90:cb3d968589d8 | 35 | ---------------------------------------------------------------------------*/ |
Kojto | 90:cb3d968589d8 | 36 | |
Kojto | 90:cb3d968589d8 | 37 | |
Kojto | 90:cb3d968589d8 | 38 | #ifndef __CORE_CMINSTR_H |
Kojto | 90:cb3d968589d8 | 39 | #define __CORE_CMINSTR_H |
Kojto | 90:cb3d968589d8 | 40 | |
Kojto | 90:cb3d968589d8 | 41 | |
Kojto | 90:cb3d968589d8 | 42 | /* ########################## Core Instruction Access ######################### */ |
Kojto | 90:cb3d968589d8 | 43 | /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface |
Kojto | 90:cb3d968589d8 | 44 | Access to dedicated instructions |
Kojto | 90:cb3d968589d8 | 45 | @{ |
Kojto | 90:cb3d968589d8 | 46 | */ |
Kojto | 90:cb3d968589d8 | 47 | |
Kojto | 90:cb3d968589d8 | 48 | #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ |
Kojto | 90:cb3d968589d8 | 49 | /* ARM armcc specific functions */ |
Kojto | 90:cb3d968589d8 | 50 | |
Kojto | 90:cb3d968589d8 | 51 | #if (__ARMCC_VERSION < 400677) |
Kojto | 90:cb3d968589d8 | 52 | #error "Please use ARM Compiler Toolchain V4.0.677 or later!" |
Kojto | 90:cb3d968589d8 | 53 | #endif |
Kojto | 90:cb3d968589d8 | 54 | |
Kojto | 90:cb3d968589d8 | 55 | |
Kojto | 90:cb3d968589d8 | 56 | /** \brief No Operation |
Kojto | 90:cb3d968589d8 | 57 | |
Kojto | 90:cb3d968589d8 | 58 | No Operation does nothing. This instruction can be used for code alignment purposes. |
Kojto | 90:cb3d968589d8 | 59 | */ |
Kojto | 90:cb3d968589d8 | 60 | #define __NOP __nop |
Kojto | 90:cb3d968589d8 | 61 | |
Kojto | 90:cb3d968589d8 | 62 | |
Kojto | 90:cb3d968589d8 | 63 | /** \brief Wait For Interrupt |
Kojto | 90:cb3d968589d8 | 64 | |
Kojto | 90:cb3d968589d8 | 65 | Wait For Interrupt is a hint instruction that suspends execution |
Kojto | 90:cb3d968589d8 | 66 | until one of a number of events occurs. |
Kojto | 90:cb3d968589d8 | 67 | */ |
Kojto | 90:cb3d968589d8 | 68 | #define __WFI __wfi |
Kojto | 90:cb3d968589d8 | 69 | |
Kojto | 90:cb3d968589d8 | 70 | |
Kojto | 90:cb3d968589d8 | 71 | /** \brief Wait For Event |
Kojto | 90:cb3d968589d8 | 72 | |
Kojto | 90:cb3d968589d8 | 73 | Wait For Event is a hint instruction that permits the processor to enter |
Kojto | 90:cb3d968589d8 | 74 | a low-power state until one of a number of events occurs. |
Kojto | 90:cb3d968589d8 | 75 | */ |
Kojto | 90:cb3d968589d8 | 76 | #define __WFE __wfe |
Kojto | 90:cb3d968589d8 | 77 | |
Kojto | 90:cb3d968589d8 | 78 | |
Kojto | 90:cb3d968589d8 | 79 | /** \brief Send Event |
Kojto | 90:cb3d968589d8 | 80 | |
Kojto | 90:cb3d968589d8 | 81 | Send Event is a hint instruction. It causes an event to be signaled to the CPU. |
Kojto | 90:cb3d968589d8 | 82 | */ |
Kojto | 90:cb3d968589d8 | 83 | #define __SEV __sev |
Kojto | 90:cb3d968589d8 | 84 | |
Kojto | 90:cb3d968589d8 | 85 | |
Kojto | 90:cb3d968589d8 | 86 | /** \brief Instruction Synchronization Barrier |
Kojto | 90:cb3d968589d8 | 87 | |
Kojto | 90:cb3d968589d8 | 88 | Instruction Synchronization Barrier flushes the pipeline in the processor, |
Kojto | 90:cb3d968589d8 | 89 | so that all instructions following the ISB are fetched from cache or |
Kojto | 90:cb3d968589d8 | 90 | memory, after the instruction has been completed. |
Kojto | 90:cb3d968589d8 | 91 | */ |
Kojto | 90:cb3d968589d8 | 92 | #define __ISB() __isb(0xF) |
Kojto | 90:cb3d968589d8 | 93 | |
Kojto | 90:cb3d968589d8 | 94 | |
Kojto | 90:cb3d968589d8 | 95 | /** \brief Data Synchronization Barrier |
Kojto | 90:cb3d968589d8 | 96 | |
Kojto | 90:cb3d968589d8 | 97 | This function acts as a special kind of Data Memory Barrier. |
Kojto | 90:cb3d968589d8 | 98 | It completes when all explicit memory accesses before this instruction complete. |
Kojto | 90:cb3d968589d8 | 99 | */ |
Kojto | 90:cb3d968589d8 | 100 | #define __DSB() __dsb(0xF) |
Kojto | 90:cb3d968589d8 | 101 | |
Kojto | 90:cb3d968589d8 | 102 | |
Kojto | 90:cb3d968589d8 | 103 | /** \brief Data Memory Barrier |
Kojto | 90:cb3d968589d8 | 104 | |
Kojto | 90:cb3d968589d8 | 105 | This function ensures the apparent order of the explicit memory operations before |
Kojto | 90:cb3d968589d8 | 106 | and after the instruction, without ensuring their completion. |
Kojto | 90:cb3d968589d8 | 107 | */ |
Kojto | 90:cb3d968589d8 | 108 | #define __DMB() __dmb(0xF) |
Kojto | 90:cb3d968589d8 | 109 | |
Kojto | 90:cb3d968589d8 | 110 | |
Kojto | 90:cb3d968589d8 | 111 | /** \brief Reverse byte order (32 bit) |
Kojto | 90:cb3d968589d8 | 112 | |
Kojto | 90:cb3d968589d8 | 113 | This function reverses the byte order in integer value. |
Kojto | 90:cb3d968589d8 | 114 | |
Kojto | 90:cb3d968589d8 | 115 | \param [in] value Value to reverse |
Kojto | 90:cb3d968589d8 | 116 | \return Reversed value |
Kojto | 90:cb3d968589d8 | 117 | */ |
Kojto | 90:cb3d968589d8 | 118 | #define __REV __rev |
Kojto | 90:cb3d968589d8 | 119 | |
Kojto | 90:cb3d968589d8 | 120 | |
Kojto | 90:cb3d968589d8 | 121 | /** \brief Reverse byte order (16 bit) |
Kojto | 90:cb3d968589d8 | 122 | |
Kojto | 90:cb3d968589d8 | 123 | This function reverses the byte order in two unsigned short values. |
Kojto | 90:cb3d968589d8 | 124 | |
Kojto | 90:cb3d968589d8 | 125 | \param [in] value Value to reverse |
Kojto | 90:cb3d968589d8 | 126 | \return Reversed value |
Kojto | 90:cb3d968589d8 | 127 | */ |
Kojto | 90:cb3d968589d8 | 128 | #ifndef __NO_EMBEDDED_ASM |
Kojto | 90:cb3d968589d8 | 129 | __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) |
Kojto | 90:cb3d968589d8 | 130 | { |
Kojto | 90:cb3d968589d8 | 131 | rev16 r0, r0 |
Kojto | 90:cb3d968589d8 | 132 | bx lr |
Kojto | 90:cb3d968589d8 | 133 | } |
Kojto | 90:cb3d968589d8 | 134 | #endif |
Kojto | 90:cb3d968589d8 | 135 | |
Kojto | 90:cb3d968589d8 | 136 | /** \brief Reverse byte order in signed short value |
Kojto | 90:cb3d968589d8 | 137 | |
Kojto | 90:cb3d968589d8 | 138 | This function reverses the byte order in a signed short value with sign extension to integer. |
Kojto | 90:cb3d968589d8 | 139 | |
Kojto | 90:cb3d968589d8 | 140 | \param [in] value Value to reverse |
Kojto | 90:cb3d968589d8 | 141 | \return Reversed value |
Kojto | 90:cb3d968589d8 | 142 | */ |
Kojto | 90:cb3d968589d8 | 143 | #ifndef __NO_EMBEDDED_ASM |
Kojto | 90:cb3d968589d8 | 144 | __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value) |
Kojto | 90:cb3d968589d8 | 145 | { |
Kojto | 90:cb3d968589d8 | 146 | revsh r0, r0 |
Kojto | 90:cb3d968589d8 | 147 | bx lr |
Kojto | 90:cb3d968589d8 | 148 | } |
Kojto | 90:cb3d968589d8 | 149 | #endif |
Kojto | 90:cb3d968589d8 | 150 | |
Kojto | 90:cb3d968589d8 | 151 | |
Kojto | 90:cb3d968589d8 | 152 | /** \brief Rotate Right in unsigned value (32 bit) |
Kojto | 90:cb3d968589d8 | 153 | |
Kojto | 90:cb3d968589d8 | 154 | This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. |
Kojto | 90:cb3d968589d8 | 155 | |
Kojto | 90:cb3d968589d8 | 156 | \param [in] value Value to rotate |
Kojto | 90:cb3d968589d8 | 157 | \param [in] value Number of Bits to rotate |
Kojto | 90:cb3d968589d8 | 158 | \return Rotated value |
Kojto | 90:cb3d968589d8 | 159 | */ |
Kojto | 90:cb3d968589d8 | 160 | #define __ROR __ror |
Kojto | 90:cb3d968589d8 | 161 | |
Kojto | 90:cb3d968589d8 | 162 | |
Kojto | 90:cb3d968589d8 | 163 | /** \brief Breakpoint |
Kojto | 90:cb3d968589d8 | 164 | |
Kojto | 90:cb3d968589d8 | 165 | This function causes the processor to enter Debug state. |
Kojto | 90:cb3d968589d8 | 166 | Debug tools can use this to investigate system state when the instruction at a particular address is reached. |
Kojto | 90:cb3d968589d8 | 167 | |
Kojto | 90:cb3d968589d8 | 168 | \param [in] value is ignored by the processor. |
Kojto | 90:cb3d968589d8 | 169 | If required, a debugger can use it to store additional information about the breakpoint. |
Kojto | 90:cb3d968589d8 | 170 | */ |
Kojto | 90:cb3d968589d8 | 171 | #define __BKPT(value) __breakpoint(value) |
Kojto | 90:cb3d968589d8 | 172 | |
Kojto | 90:cb3d968589d8 | 173 | |
Kojto | 90:cb3d968589d8 | 174 | #if (__CORTEX_M >= 0x03) |
Kojto | 90:cb3d968589d8 | 175 | |
Kojto | 90:cb3d968589d8 | 176 | /** \brief Reverse bit order of value |
Kojto | 90:cb3d968589d8 | 177 | |
Kojto | 90:cb3d968589d8 | 178 | This function reverses the bit order of the given value. |
Kojto | 90:cb3d968589d8 | 179 | |
Kojto | 90:cb3d968589d8 | 180 | \param [in] value Value to reverse |
Kojto | 90:cb3d968589d8 | 181 | \return Reversed value |
Kojto | 90:cb3d968589d8 | 182 | */ |
Kojto | 90:cb3d968589d8 | 183 | #define __RBIT __rbit |
Kojto | 90:cb3d968589d8 | 184 | |
Kojto | 90:cb3d968589d8 | 185 | |
Kojto | 90:cb3d968589d8 | 186 | /** \brief LDR Exclusive (8 bit) |
Kojto | 90:cb3d968589d8 | 187 | |
Kojto | 90:cb3d968589d8 | 188 | This function performs a exclusive LDR command for 8 bit value. |
Kojto | 90:cb3d968589d8 | 189 | |
Kojto | 90:cb3d968589d8 | 190 | \param [in] ptr Pointer to data |
Kojto | 90:cb3d968589d8 | 191 | \return value of type uint8_t at (*ptr) |
Kojto | 90:cb3d968589d8 | 192 | */ |
Kojto | 90:cb3d968589d8 | 193 | #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) |
Kojto | 90:cb3d968589d8 | 194 | |
Kojto | 90:cb3d968589d8 | 195 | |
Kojto | 90:cb3d968589d8 | 196 | /** \brief LDR Exclusive (16 bit) |
Kojto | 90:cb3d968589d8 | 197 | |
Kojto | 90:cb3d968589d8 | 198 | This function performs a exclusive LDR command for 16 bit values. |
Kojto | 90:cb3d968589d8 | 199 | |
Kojto | 90:cb3d968589d8 | 200 | \param [in] ptr Pointer to data |
Kojto | 90:cb3d968589d8 | 201 | \return value of type uint16_t at (*ptr) |
Kojto | 90:cb3d968589d8 | 202 | */ |
Kojto | 90:cb3d968589d8 | 203 | #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) |
Kojto | 90:cb3d968589d8 | 204 | |
Kojto | 90:cb3d968589d8 | 205 | |
Kojto | 90:cb3d968589d8 | 206 | /** \brief LDR Exclusive (32 bit) |
Kojto | 90:cb3d968589d8 | 207 | |
Kojto | 90:cb3d968589d8 | 208 | This function performs a exclusive LDR command for 32 bit values. |
Kojto | 90:cb3d968589d8 | 209 | |
Kojto | 90:cb3d968589d8 | 210 | \param [in] ptr Pointer to data |
Kojto | 90:cb3d968589d8 | 211 | \return value of type uint32_t at (*ptr) |
Kojto | 90:cb3d968589d8 | 212 | */ |
Kojto | 90:cb3d968589d8 | 213 | #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) |
Kojto | 90:cb3d968589d8 | 214 | |
Kojto | 90:cb3d968589d8 | 215 | |
Kojto | 90:cb3d968589d8 | 216 | /** \brief STR Exclusive (8 bit) |
Kojto | 90:cb3d968589d8 | 217 | |
Kojto | 90:cb3d968589d8 | 218 | This function performs a exclusive STR command for 8 bit values. |
Kojto | 90:cb3d968589d8 | 219 | |
Kojto | 90:cb3d968589d8 | 220 | \param [in] value Value to store |
Kojto | 90:cb3d968589d8 | 221 | \param [in] ptr Pointer to location |
Kojto | 90:cb3d968589d8 | 222 | \return 0 Function succeeded |
Kojto | 90:cb3d968589d8 | 223 | \return 1 Function failed |
Kojto | 90:cb3d968589d8 | 224 | */ |
Kojto | 90:cb3d968589d8 | 225 | #define __STREXB(value, ptr) __strex(value, ptr) |
Kojto | 90:cb3d968589d8 | 226 | |
Kojto | 90:cb3d968589d8 | 227 | |
Kojto | 90:cb3d968589d8 | 228 | /** \brief STR Exclusive (16 bit) |
Kojto | 90:cb3d968589d8 | 229 | |
Kojto | 90:cb3d968589d8 | 230 | This function performs a exclusive STR command for 16 bit values. |
Kojto | 90:cb3d968589d8 | 231 | |
Kojto | 90:cb3d968589d8 | 232 | \param [in] value Value to store |
Kojto | 90:cb3d968589d8 | 233 | \param [in] ptr Pointer to location |
Kojto | 90:cb3d968589d8 | 234 | \return 0 Function succeeded |
Kojto | 90:cb3d968589d8 | 235 | \return 1 Function failed |
Kojto | 90:cb3d968589d8 | 236 | */ |
Kojto | 90:cb3d968589d8 | 237 | #define __STREXH(value, ptr) __strex(value, ptr) |
Kojto | 90:cb3d968589d8 | 238 | |
Kojto | 90:cb3d968589d8 | 239 | |
Kojto | 90:cb3d968589d8 | 240 | /** \brief STR Exclusive (32 bit) |
Kojto | 90:cb3d968589d8 | 241 | |
Kojto | 90:cb3d968589d8 | 242 | This function performs a exclusive STR command for 32 bit values. |
Kojto | 90:cb3d968589d8 | 243 | |
Kojto | 90:cb3d968589d8 | 244 | \param [in] value Value to store |
Kojto | 90:cb3d968589d8 | 245 | \param [in] ptr Pointer to location |
Kojto | 90:cb3d968589d8 | 246 | \return 0 Function succeeded |
Kojto | 90:cb3d968589d8 | 247 | \return 1 Function failed |
Kojto | 90:cb3d968589d8 | 248 | */ |
Kojto | 90:cb3d968589d8 | 249 | #define __STREXW(value, ptr) __strex(value, ptr) |
Kojto | 90:cb3d968589d8 | 250 | |
Kojto | 90:cb3d968589d8 | 251 | |
Kojto | 90:cb3d968589d8 | 252 | /** \brief Remove the exclusive lock |
Kojto | 90:cb3d968589d8 | 253 | |
Kojto | 90:cb3d968589d8 | 254 | This function removes the exclusive lock which is created by LDREX. |
Kojto | 90:cb3d968589d8 | 255 | |
Kojto | 90:cb3d968589d8 | 256 | */ |
Kojto | 90:cb3d968589d8 | 257 | #define __CLREX __clrex |
Kojto | 90:cb3d968589d8 | 258 | |
Kojto | 90:cb3d968589d8 | 259 | |
Kojto | 90:cb3d968589d8 | 260 | /** \brief Signed Saturate |
Kojto | 90:cb3d968589d8 | 261 | |
Kojto | 90:cb3d968589d8 | 262 | This function saturates a signed value. |
Kojto | 90:cb3d968589d8 | 263 | |
Kojto | 90:cb3d968589d8 | 264 | \param [in] value Value to be saturated |
Kojto | 90:cb3d968589d8 | 265 | \param [in] sat Bit position to saturate to (1..32) |
Kojto | 90:cb3d968589d8 | 266 | \return Saturated value |
Kojto | 90:cb3d968589d8 | 267 | */ |
Kojto | 90:cb3d968589d8 | 268 | #define __SSAT __ssat |
Kojto | 90:cb3d968589d8 | 269 | |
Kojto | 90:cb3d968589d8 | 270 | |
Kojto | 90:cb3d968589d8 | 271 | /** \brief Unsigned Saturate |
Kojto | 90:cb3d968589d8 | 272 | |
Kojto | 90:cb3d968589d8 | 273 | This function saturates an unsigned value. |
Kojto | 90:cb3d968589d8 | 274 | |
Kojto | 90:cb3d968589d8 | 275 | \param [in] value Value to be saturated |
Kojto | 90:cb3d968589d8 | 276 | \param [in] sat Bit position to saturate to (0..31) |
Kojto | 90:cb3d968589d8 | 277 | \return Saturated value |
Kojto | 90:cb3d968589d8 | 278 | */ |
Kojto | 90:cb3d968589d8 | 279 | #define __USAT __usat |
Kojto | 90:cb3d968589d8 | 280 | |
Kojto | 90:cb3d968589d8 | 281 | |
Kojto | 90:cb3d968589d8 | 282 | /** \brief Count leading zeros |
Kojto | 90:cb3d968589d8 | 283 | |
Kojto | 90:cb3d968589d8 | 284 | This function counts the number of leading zeros of a data value. |
Kojto | 90:cb3d968589d8 | 285 | |
Kojto | 90:cb3d968589d8 | 286 | \param [in] value Value to count the leading zeros |
Kojto | 90:cb3d968589d8 | 287 | \return number of leading zeros in value |
Kojto | 90:cb3d968589d8 | 288 | */ |
Kojto | 90:cb3d968589d8 | 289 | #define __CLZ __clz |
Kojto | 90:cb3d968589d8 | 290 | |
Kojto | 90:cb3d968589d8 | 291 | #endif /* (__CORTEX_M >= 0x03) */ |
Kojto | 90:cb3d968589d8 | 292 | |
Kojto | 90:cb3d968589d8 | 293 | |
Kojto | 90:cb3d968589d8 | 294 | |
Kojto | 90:cb3d968589d8 | 295 | #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ |
Kojto | 90:cb3d968589d8 | 296 | /* IAR iccarm specific functions */ |
Kojto | 90:cb3d968589d8 | 297 | |
Kojto | 90:cb3d968589d8 | 298 | #include <cmsis_iar.h> |
Kojto | 90:cb3d968589d8 | 299 | |
Kojto | 90:cb3d968589d8 | 300 | |
Kojto | 90:cb3d968589d8 | 301 | #elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/ |
Kojto | 90:cb3d968589d8 | 302 | /* TI CCS specific functions */ |
Kojto | 90:cb3d968589d8 | 303 | |
Kojto | 90:cb3d968589d8 | 304 | #include <cmsis_ccs.h> |
Kojto | 90:cb3d968589d8 | 305 | |
Kojto | 90:cb3d968589d8 | 306 | |
Kojto | 90:cb3d968589d8 | 307 | #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ |
Kojto | 90:cb3d968589d8 | 308 | /* GNU gcc specific functions */ |
Kojto | 90:cb3d968589d8 | 309 | |
Kojto | 90:cb3d968589d8 | 310 | /* Define macros for porting to both thumb1 and thumb2. |
Kojto | 90:cb3d968589d8 | 311 | * For thumb1, use low register (r0-r7), specified by constrant "l" |
Kojto | 90:cb3d968589d8 | 312 | * Otherwise, use general registers, specified by constrant "r" */ |
Kojto | 90:cb3d968589d8 | 313 | #if defined (__thumb__) && !defined (__thumb2__) |
Kojto | 90:cb3d968589d8 | 314 | #define __CMSIS_GCC_OUT_REG(r) "=l" (r) |
Kojto | 90:cb3d968589d8 | 315 | #define __CMSIS_GCC_USE_REG(r) "l" (r) |
Kojto | 90:cb3d968589d8 | 316 | #else |
Kojto | 90:cb3d968589d8 | 317 | #define __CMSIS_GCC_OUT_REG(r) "=r" (r) |
Kojto | 90:cb3d968589d8 | 318 | #define __CMSIS_GCC_USE_REG(r) "r" (r) |
Kojto | 90:cb3d968589d8 | 319 | #endif |
Kojto | 90:cb3d968589d8 | 320 | |
Kojto | 90:cb3d968589d8 | 321 | /** \brief No Operation |
Kojto | 90:cb3d968589d8 | 322 | |
Kojto | 90:cb3d968589d8 | 323 | No Operation does nothing. This instruction can be used for code alignment purposes. |
Kojto | 90:cb3d968589d8 | 324 | */ |
Kojto | 90:cb3d968589d8 | 325 | __attribute__( ( always_inline ) ) __STATIC_INLINE void __NOP(void) |
Kojto | 90:cb3d968589d8 | 326 | { |
Kojto | 90:cb3d968589d8 | 327 | __ASM volatile ("nop"); |
Kojto | 90:cb3d968589d8 | 328 | } |
Kojto | 90:cb3d968589d8 | 329 | |
Kojto | 90:cb3d968589d8 | 330 | |
Kojto | 90:cb3d968589d8 | 331 | /** \brief Wait For Interrupt |
Kojto | 90:cb3d968589d8 | 332 | |
Kojto | 90:cb3d968589d8 | 333 | Wait For Interrupt is a hint instruction that suspends execution |
Kojto | 90:cb3d968589d8 | 334 | until one of a number of events occurs. |
Kojto | 90:cb3d968589d8 | 335 | */ |
Kojto | 90:cb3d968589d8 | 336 | __attribute__( ( always_inline ) ) __STATIC_INLINE void __WFI(void) |
Kojto | 90:cb3d968589d8 | 337 | { |
Kojto | 90:cb3d968589d8 | 338 | __ASM volatile ("wfi"); |
Kojto | 90:cb3d968589d8 | 339 | } |
Kojto | 90:cb3d968589d8 | 340 | |
Kojto | 90:cb3d968589d8 | 341 | |
Kojto | 90:cb3d968589d8 | 342 | /** \brief Wait For Event |
Kojto | 90:cb3d968589d8 | 343 | |
Kojto | 90:cb3d968589d8 | 344 | Wait For Event is a hint instruction that permits the processor to enter |
Kojto | 90:cb3d968589d8 | 345 | a low-power state until one of a number of events occurs. |
Kojto | 90:cb3d968589d8 | 346 | */ |
Kojto | 90:cb3d968589d8 | 347 | __attribute__( ( always_inline ) ) __STATIC_INLINE void __WFE(void) |
Kojto | 90:cb3d968589d8 | 348 | { |
Kojto | 90:cb3d968589d8 | 349 | __ASM volatile ("wfe"); |
Kojto | 90:cb3d968589d8 | 350 | } |
Kojto | 90:cb3d968589d8 | 351 | |
Kojto | 90:cb3d968589d8 | 352 | |
Kojto | 90:cb3d968589d8 | 353 | /** \brief Send Event |
Kojto | 90:cb3d968589d8 | 354 | |
Kojto | 90:cb3d968589d8 | 355 | Send Event is a hint instruction. It causes an event to be signaled to the CPU. |
Kojto | 90:cb3d968589d8 | 356 | */ |
Kojto | 90:cb3d968589d8 | 357 | __attribute__( ( always_inline ) ) __STATIC_INLINE void __SEV(void) |
Kojto | 90:cb3d968589d8 | 358 | { |
Kojto | 90:cb3d968589d8 | 359 | __ASM volatile ("sev"); |
Kojto | 90:cb3d968589d8 | 360 | } |
Kojto | 90:cb3d968589d8 | 361 | |
Kojto | 90:cb3d968589d8 | 362 | |
Kojto | 90:cb3d968589d8 | 363 | /** \brief Instruction Synchronization Barrier |
Kojto | 90:cb3d968589d8 | 364 | |
Kojto | 90:cb3d968589d8 | 365 | Instruction Synchronization Barrier flushes the pipeline in the processor, |
Kojto | 90:cb3d968589d8 | 366 | so that all instructions following the ISB are fetched from cache or |
Kojto | 90:cb3d968589d8 | 367 | memory, after the instruction has been completed. |
Kojto | 90:cb3d968589d8 | 368 | */ |
Kojto | 90:cb3d968589d8 | 369 | __attribute__( ( always_inline ) ) __STATIC_INLINE void __ISB(void) |
Kojto | 90:cb3d968589d8 | 370 | { |
Kojto | 90:cb3d968589d8 | 371 | __ASM volatile ("isb"); |
Kojto | 90:cb3d968589d8 | 372 | } |
Kojto | 90:cb3d968589d8 | 373 | |
Kojto | 90:cb3d968589d8 | 374 | |
Kojto | 90:cb3d968589d8 | 375 | /** \brief Data Synchronization Barrier |
Kojto | 90:cb3d968589d8 | 376 | |
Kojto | 90:cb3d968589d8 | 377 | This function acts as a special kind of Data Memory Barrier. |
Kojto | 90:cb3d968589d8 | 378 | It completes when all explicit memory accesses before this instruction complete. |
Kojto | 90:cb3d968589d8 | 379 | */ |
Kojto | 90:cb3d968589d8 | 380 | __attribute__( ( always_inline ) ) __STATIC_INLINE void __DSB(void) |
Kojto | 90:cb3d968589d8 | 381 | { |
Kojto | 90:cb3d968589d8 | 382 | __ASM volatile ("dsb"); |
Kojto | 90:cb3d968589d8 | 383 | } |
Kojto | 90:cb3d968589d8 | 384 | |
Kojto | 90:cb3d968589d8 | 385 | |
Kojto | 90:cb3d968589d8 | 386 | /** \brief Data Memory Barrier |
Kojto | 90:cb3d968589d8 | 387 | |
Kojto | 90:cb3d968589d8 | 388 | This function ensures the apparent order of the explicit memory operations before |
Kojto | 90:cb3d968589d8 | 389 | and after the instruction, without ensuring their completion. |
Kojto | 90:cb3d968589d8 | 390 | */ |
Kojto | 90:cb3d968589d8 | 391 | __attribute__( ( always_inline ) ) __STATIC_INLINE void __DMB(void) |
Kojto | 90:cb3d968589d8 | 392 | { |
Kojto | 90:cb3d968589d8 | 393 | __ASM volatile ("dmb"); |
Kojto | 90:cb3d968589d8 | 394 | } |
Kojto | 90:cb3d968589d8 | 395 | |
Kojto | 90:cb3d968589d8 | 396 | |
Kojto | 90:cb3d968589d8 | 397 | /** \brief Reverse byte order (32 bit) |
Kojto | 90:cb3d968589d8 | 398 | |
Kojto | 90:cb3d968589d8 | 399 | This function reverses the byte order in integer value. |
Kojto | 90:cb3d968589d8 | 400 | |
Kojto | 90:cb3d968589d8 | 401 | \param [in] value Value to reverse |
Kojto | 90:cb3d968589d8 | 402 | \return Reversed value |
Kojto | 90:cb3d968589d8 | 403 | */ |
Kojto | 90:cb3d968589d8 | 404 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV(uint32_t value) |
Kojto | 90:cb3d968589d8 | 405 | { |
Kojto | 90:cb3d968589d8 | 406 | #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) |
Kojto | 90:cb3d968589d8 | 407 | return __builtin_bswap32(value); |
Kojto | 90:cb3d968589d8 | 408 | #else |
Kojto | 90:cb3d968589d8 | 409 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 410 | |
Kojto | 90:cb3d968589d8 | 411 | __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); |
Kojto | 90:cb3d968589d8 | 412 | return(result); |
Kojto | 90:cb3d968589d8 | 413 | #endif |
Kojto | 90:cb3d968589d8 | 414 | } |
Kojto | 90:cb3d968589d8 | 415 | |
Kojto | 90:cb3d968589d8 | 416 | |
Kojto | 90:cb3d968589d8 | 417 | /** \brief Reverse byte order (16 bit) |
Kojto | 90:cb3d968589d8 | 418 | |
Kojto | 90:cb3d968589d8 | 419 | This function reverses the byte order in two unsigned short values. |
Kojto | 90:cb3d968589d8 | 420 | |
Kojto | 90:cb3d968589d8 | 421 | \param [in] value Value to reverse |
Kojto | 90:cb3d968589d8 | 422 | \return Reversed value |
Kojto | 90:cb3d968589d8 | 423 | */ |
Kojto | 90:cb3d968589d8 | 424 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV16(uint32_t value) |
Kojto | 90:cb3d968589d8 | 425 | { |
Kojto | 90:cb3d968589d8 | 426 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 427 | |
Kojto | 90:cb3d968589d8 | 428 | __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); |
Kojto | 90:cb3d968589d8 | 429 | return(result); |
Kojto | 90:cb3d968589d8 | 430 | } |
Kojto | 90:cb3d968589d8 | 431 | |
Kojto | 90:cb3d968589d8 | 432 | |
Kojto | 90:cb3d968589d8 | 433 | /** \brief Reverse byte order in signed short value |
Kojto | 90:cb3d968589d8 | 434 | |
Kojto | 90:cb3d968589d8 | 435 | This function reverses the byte order in a signed short value with sign extension to integer. |
Kojto | 90:cb3d968589d8 | 436 | |
Kojto | 90:cb3d968589d8 | 437 | \param [in] value Value to reverse |
Kojto | 90:cb3d968589d8 | 438 | \return Reversed value |
Kojto | 90:cb3d968589d8 | 439 | */ |
Kojto | 90:cb3d968589d8 | 440 | __attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __REVSH(int32_t value) |
Kojto | 90:cb3d968589d8 | 441 | { |
Kojto | 90:cb3d968589d8 | 442 | #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) |
Kojto | 90:cb3d968589d8 | 443 | return (short)__builtin_bswap16(value); |
Kojto | 90:cb3d968589d8 | 444 | #else |
Kojto | 90:cb3d968589d8 | 445 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 446 | |
Kojto | 90:cb3d968589d8 | 447 | __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); |
Kojto | 90:cb3d968589d8 | 448 | return(result); |
Kojto | 90:cb3d968589d8 | 449 | #endif |
Kojto | 90:cb3d968589d8 | 450 | } |
Kojto | 90:cb3d968589d8 | 451 | |
Kojto | 90:cb3d968589d8 | 452 | |
Kojto | 90:cb3d968589d8 | 453 | /** \brief Rotate Right in unsigned value (32 bit) |
Kojto | 90:cb3d968589d8 | 454 | |
Kojto | 90:cb3d968589d8 | 455 | This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. |
Kojto | 90:cb3d968589d8 | 456 | |
Kojto | 90:cb3d968589d8 | 457 | \param [in] value Value to rotate |
Kojto | 90:cb3d968589d8 | 458 | \param [in] value Number of Bits to rotate |
Kojto | 90:cb3d968589d8 | 459 | \return Rotated value |
Kojto | 90:cb3d968589d8 | 460 | */ |
Kojto | 90:cb3d968589d8 | 461 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2) |
Kojto | 90:cb3d968589d8 | 462 | { |
Kojto | 90:cb3d968589d8 | 463 | return (op1 >> op2) | (op1 << (32 - op2)); |
Kojto | 90:cb3d968589d8 | 464 | } |
Kojto | 90:cb3d968589d8 | 465 | |
Kojto | 90:cb3d968589d8 | 466 | |
Kojto | 90:cb3d968589d8 | 467 | /** \brief Breakpoint |
Kojto | 90:cb3d968589d8 | 468 | |
Kojto | 90:cb3d968589d8 | 469 | This function causes the processor to enter Debug state. |
Kojto | 90:cb3d968589d8 | 470 | Debug tools can use this to investigate system state when the instruction at a particular address is reached. |
Kojto | 90:cb3d968589d8 | 471 | |
Kojto | 90:cb3d968589d8 | 472 | \param [in] value is ignored by the processor. |
Kojto | 90:cb3d968589d8 | 473 | If required, a debugger can use it to store additional information about the breakpoint. |
Kojto | 90:cb3d968589d8 | 474 | */ |
Kojto | 90:cb3d968589d8 | 475 | #define __BKPT(value) __ASM volatile ("bkpt "#value) |
Kojto | 90:cb3d968589d8 | 476 | |
Kojto | 90:cb3d968589d8 | 477 | |
Kojto | 90:cb3d968589d8 | 478 | #if (__CORTEX_M >= 0x03) |
Kojto | 90:cb3d968589d8 | 479 | |
Kojto | 90:cb3d968589d8 | 480 | /** \brief Reverse bit order of value |
Kojto | 90:cb3d968589d8 | 481 | |
Kojto | 90:cb3d968589d8 | 482 | This function reverses the bit order of the given value. |
Kojto | 90:cb3d968589d8 | 483 | |
Kojto | 90:cb3d968589d8 | 484 | \param [in] value Value to reverse |
Kojto | 90:cb3d968589d8 | 485 | \return Reversed value |
Kojto | 90:cb3d968589d8 | 486 | */ |
Kojto | 90:cb3d968589d8 | 487 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value) |
Kojto | 90:cb3d968589d8 | 488 | { |
Kojto | 90:cb3d968589d8 | 489 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 490 | |
Kojto | 90:cb3d968589d8 | 491 | __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); |
Kojto | 90:cb3d968589d8 | 492 | return(result); |
Kojto | 90:cb3d968589d8 | 493 | } |
Kojto | 90:cb3d968589d8 | 494 | |
Kojto | 90:cb3d968589d8 | 495 | |
Kojto | 90:cb3d968589d8 | 496 | /** \brief LDR Exclusive (8 bit) |
Kojto | 90:cb3d968589d8 | 497 | |
Kojto | 90:cb3d968589d8 | 498 | This function performs a exclusive LDR command for 8 bit value. |
Kojto | 90:cb3d968589d8 | 499 | |
Kojto | 90:cb3d968589d8 | 500 | \param [in] ptr Pointer to data |
Kojto | 90:cb3d968589d8 | 501 | \return value of type uint8_t at (*ptr) |
Kojto | 90:cb3d968589d8 | 502 | */ |
Kojto | 90:cb3d968589d8 | 503 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr) |
Kojto | 90:cb3d968589d8 | 504 | { |
Kojto | 90:cb3d968589d8 | 505 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 506 | |
Kojto | 90:cb3d968589d8 | 507 | #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) |
Kojto | 90:cb3d968589d8 | 508 | __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) ); |
Kojto | 90:cb3d968589d8 | 509 | #else |
Kojto | 90:cb3d968589d8 | 510 | /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not |
Kojto | 90:cb3d968589d8 | 511 | accepted by assembler. So has to use following less efficient pattern. |
Kojto | 90:cb3d968589d8 | 512 | */ |
Kojto | 90:cb3d968589d8 | 513 | __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); |
Kojto | 90:cb3d968589d8 | 514 | #endif |
Kojto | 90:cb3d968589d8 | 515 | return(result); |
Kojto | 90:cb3d968589d8 | 516 | } |
Kojto | 90:cb3d968589d8 | 517 | |
Kojto | 90:cb3d968589d8 | 518 | |
Kojto | 90:cb3d968589d8 | 519 | /** \brief LDR Exclusive (16 bit) |
Kojto | 90:cb3d968589d8 | 520 | |
Kojto | 90:cb3d968589d8 | 521 | This function performs a exclusive LDR command for 16 bit values. |
Kojto | 90:cb3d968589d8 | 522 | |
Kojto | 90:cb3d968589d8 | 523 | \param [in] ptr Pointer to data |
Kojto | 90:cb3d968589d8 | 524 | \return value of type uint16_t at (*ptr) |
Kojto | 90:cb3d968589d8 | 525 | */ |
Kojto | 90:cb3d968589d8 | 526 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr) |
Kojto | 90:cb3d968589d8 | 527 | { |
Kojto | 90:cb3d968589d8 | 528 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 529 | |
Kojto | 90:cb3d968589d8 | 530 | #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) |
Kojto | 90:cb3d968589d8 | 531 | __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) ); |
Kojto | 90:cb3d968589d8 | 532 | #else |
Kojto | 90:cb3d968589d8 | 533 | /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not |
Kojto | 90:cb3d968589d8 | 534 | accepted by assembler. So has to use following less efficient pattern. |
Kojto | 90:cb3d968589d8 | 535 | */ |
Kojto | 90:cb3d968589d8 | 536 | __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); |
Kojto | 90:cb3d968589d8 | 537 | #endif |
Kojto | 90:cb3d968589d8 | 538 | return(result); |
Kojto | 90:cb3d968589d8 | 539 | } |
Kojto | 90:cb3d968589d8 | 540 | |
Kojto | 90:cb3d968589d8 | 541 | |
Kojto | 90:cb3d968589d8 | 542 | /** \brief LDR Exclusive (32 bit) |
Kojto | 90:cb3d968589d8 | 543 | |
Kojto | 90:cb3d968589d8 | 544 | This function performs a exclusive LDR command for 32 bit values. |
Kojto | 90:cb3d968589d8 | 545 | |
Kojto | 90:cb3d968589d8 | 546 | \param [in] ptr Pointer to data |
Kojto | 90:cb3d968589d8 | 547 | \return value of type uint32_t at (*ptr) |
Kojto | 90:cb3d968589d8 | 548 | */ |
Kojto | 90:cb3d968589d8 | 549 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr) |
Kojto | 90:cb3d968589d8 | 550 | { |
Kojto | 90:cb3d968589d8 | 551 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 552 | |
Kojto | 90:cb3d968589d8 | 553 | __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) ); |
Kojto | 90:cb3d968589d8 | 554 | return(result); |
Kojto | 90:cb3d968589d8 | 555 | } |
Kojto | 90:cb3d968589d8 | 556 | |
Kojto | 90:cb3d968589d8 | 557 | |
Kojto | 90:cb3d968589d8 | 558 | /** \brief STR Exclusive (8 bit) |
Kojto | 90:cb3d968589d8 | 559 | |
Kojto | 90:cb3d968589d8 | 560 | This function performs a exclusive STR command for 8 bit values. |
Kojto | 90:cb3d968589d8 | 561 | |
Kojto | 90:cb3d968589d8 | 562 | \param [in] value Value to store |
Kojto | 90:cb3d968589d8 | 563 | \param [in] ptr Pointer to location |
Kojto | 90:cb3d968589d8 | 564 | \return 0 Function succeeded |
Kojto | 90:cb3d968589d8 | 565 | \return 1 Function failed |
Kojto | 90:cb3d968589d8 | 566 | */ |
Kojto | 90:cb3d968589d8 | 567 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) |
Kojto | 90:cb3d968589d8 | 568 | { |
Kojto | 90:cb3d968589d8 | 569 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 570 | |
Kojto | 90:cb3d968589d8 | 571 | __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); |
Kojto | 90:cb3d968589d8 | 572 | return(result); |
Kojto | 90:cb3d968589d8 | 573 | } |
Kojto | 90:cb3d968589d8 | 574 | |
Kojto | 90:cb3d968589d8 | 575 | |
Kojto | 90:cb3d968589d8 | 576 | /** \brief STR Exclusive (16 bit) |
Kojto | 90:cb3d968589d8 | 577 | |
Kojto | 90:cb3d968589d8 | 578 | This function performs a exclusive STR command for 16 bit values. |
Kojto | 90:cb3d968589d8 | 579 | |
Kojto | 90:cb3d968589d8 | 580 | \param [in] value Value to store |
Kojto | 90:cb3d968589d8 | 581 | \param [in] ptr Pointer to location |
Kojto | 90:cb3d968589d8 | 582 | \return 0 Function succeeded |
Kojto | 90:cb3d968589d8 | 583 | \return 1 Function failed |
Kojto | 90:cb3d968589d8 | 584 | */ |
Kojto | 90:cb3d968589d8 | 585 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) |
Kojto | 90:cb3d968589d8 | 586 | { |
Kojto | 90:cb3d968589d8 | 587 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 588 | |
Kojto | 90:cb3d968589d8 | 589 | __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); |
Kojto | 90:cb3d968589d8 | 590 | return(result); |
Kojto | 90:cb3d968589d8 | 591 | } |
Kojto | 90:cb3d968589d8 | 592 | |
Kojto | 90:cb3d968589d8 | 593 | |
Kojto | 90:cb3d968589d8 | 594 | /** \brief STR Exclusive (32 bit) |
Kojto | 90:cb3d968589d8 | 595 | |
Kojto | 90:cb3d968589d8 | 596 | This function performs a exclusive STR command for 32 bit values. |
Kojto | 90:cb3d968589d8 | 597 | |
Kojto | 90:cb3d968589d8 | 598 | \param [in] value Value to store |
Kojto | 90:cb3d968589d8 | 599 | \param [in] ptr Pointer to location |
Kojto | 90:cb3d968589d8 | 600 | \return 0 Function succeeded |
Kojto | 90:cb3d968589d8 | 601 | \return 1 Function failed |
Kojto | 90:cb3d968589d8 | 602 | */ |
Kojto | 90:cb3d968589d8 | 603 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) |
Kojto | 90:cb3d968589d8 | 604 | { |
Kojto | 90:cb3d968589d8 | 605 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 606 | |
Kojto | 90:cb3d968589d8 | 607 | __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); |
Kojto | 90:cb3d968589d8 | 608 | return(result); |
Kojto | 90:cb3d968589d8 | 609 | } |
Kojto | 90:cb3d968589d8 | 610 | |
Kojto | 90:cb3d968589d8 | 611 | |
Kojto | 90:cb3d968589d8 | 612 | /** \brief Remove the exclusive lock |
Kojto | 90:cb3d968589d8 | 613 | |
Kojto | 90:cb3d968589d8 | 614 | This function removes the exclusive lock which is created by LDREX. |
Kojto | 90:cb3d968589d8 | 615 | |
Kojto | 90:cb3d968589d8 | 616 | */ |
Kojto | 90:cb3d968589d8 | 617 | __attribute__( ( always_inline ) ) __STATIC_INLINE void __CLREX(void) |
Kojto | 90:cb3d968589d8 | 618 | { |
Kojto | 90:cb3d968589d8 | 619 | __ASM volatile ("clrex" ::: "memory"); |
Kojto | 90:cb3d968589d8 | 620 | } |
Kojto | 90:cb3d968589d8 | 621 | |
Kojto | 90:cb3d968589d8 | 622 | |
Kojto | 90:cb3d968589d8 | 623 | /** \brief Signed Saturate |
Kojto | 90:cb3d968589d8 | 624 | |
Kojto | 90:cb3d968589d8 | 625 | This function saturates a signed value. |
Kojto | 90:cb3d968589d8 | 626 | |
Kojto | 90:cb3d968589d8 | 627 | \param [in] value Value to be saturated |
Kojto | 90:cb3d968589d8 | 628 | \param [in] sat Bit position to saturate to (1..32) |
Kojto | 90:cb3d968589d8 | 629 | \return Saturated value |
Kojto | 90:cb3d968589d8 | 630 | */ |
Kojto | 90:cb3d968589d8 | 631 | #define __SSAT(ARG1,ARG2) \ |
Kojto | 90:cb3d968589d8 | 632 | ({ \ |
Kojto | 90:cb3d968589d8 | 633 | uint32_t __RES, __ARG1 = (ARG1); \ |
Kojto | 90:cb3d968589d8 | 634 | __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ |
Kojto | 90:cb3d968589d8 | 635 | __RES; \ |
Kojto | 90:cb3d968589d8 | 636 | }) |
Kojto | 90:cb3d968589d8 | 637 | |
Kojto | 90:cb3d968589d8 | 638 | |
Kojto | 90:cb3d968589d8 | 639 | /** \brief Unsigned Saturate |
Kojto | 90:cb3d968589d8 | 640 | |
Kojto | 90:cb3d968589d8 | 641 | This function saturates an unsigned value. |
Kojto | 90:cb3d968589d8 | 642 | |
Kojto | 90:cb3d968589d8 | 643 | \param [in] value Value to be saturated |
Kojto | 90:cb3d968589d8 | 644 | \param [in] sat Bit position to saturate to (0..31) |
Kojto | 90:cb3d968589d8 | 645 | \return Saturated value |
Kojto | 90:cb3d968589d8 | 646 | */ |
Kojto | 90:cb3d968589d8 | 647 | #define __USAT(ARG1,ARG2) \ |
Kojto | 90:cb3d968589d8 | 648 | ({ \ |
Kojto | 90:cb3d968589d8 | 649 | uint32_t __RES, __ARG1 = (ARG1); \ |
Kojto | 90:cb3d968589d8 | 650 | __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ |
Kojto | 90:cb3d968589d8 | 651 | __RES; \ |
Kojto | 90:cb3d968589d8 | 652 | }) |
Kojto | 90:cb3d968589d8 | 653 | |
Kojto | 90:cb3d968589d8 | 654 | |
Kojto | 90:cb3d968589d8 | 655 | /** \brief Count leading zeros |
Kojto | 90:cb3d968589d8 | 656 | |
Kojto | 90:cb3d968589d8 | 657 | This function counts the number of leading zeros of a data value. |
Kojto | 90:cb3d968589d8 | 658 | |
Kojto | 90:cb3d968589d8 | 659 | \param [in] value Value to count the leading zeros |
Kojto | 90:cb3d968589d8 | 660 | \return number of leading zeros in value |
Kojto | 90:cb3d968589d8 | 661 | */ |
Kojto | 90:cb3d968589d8 | 662 | __attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __CLZ(uint32_t value) |
Kojto | 90:cb3d968589d8 | 663 | { |
Kojto | 90:cb3d968589d8 | 664 | uint32_t result; |
Kojto | 90:cb3d968589d8 | 665 | |
Kojto | 90:cb3d968589d8 | 666 | __ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) ); |
Kojto | 90:cb3d968589d8 | 667 | return(result); |
Kojto | 90:cb3d968589d8 | 668 | } |
Kojto | 90:cb3d968589d8 | 669 | |
Kojto | 90:cb3d968589d8 | 670 | #endif /* (__CORTEX_M >= 0x03) */ |
Kojto | 90:cb3d968589d8 | 671 | |
Kojto | 90:cb3d968589d8 | 672 | |
Kojto | 90:cb3d968589d8 | 673 | |
Kojto | 90:cb3d968589d8 | 674 | |
Kojto | 90:cb3d968589d8 | 675 | #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ |
Kojto | 90:cb3d968589d8 | 676 | /* TASKING carm specific functions */ |
Kojto | 90:cb3d968589d8 | 677 | |
Kojto | 90:cb3d968589d8 | 678 | /* |
Kojto | 90:cb3d968589d8 | 679 | * The CMSIS functions have been implemented as intrinsics in the compiler. |
Kojto | 90:cb3d968589d8 | 680 | * Please use "carm -?i" to get an up to date list of all intrinsics, |
Kojto | 90:cb3d968589d8 | 681 | * Including the CMSIS ones. |
Kojto | 90:cb3d968589d8 | 682 | */ |
Kojto | 90:cb3d968589d8 | 683 | |
Kojto | 90:cb3d968589d8 | 684 | #endif |
Kojto | 90:cb3d968589d8 | 685 | |
Kojto | 90:cb3d968589d8 | 686 | /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ |
Kojto | 90:cb3d968589d8 | 687 | |
Kojto | 90:cb3d968589d8 | 688 | #endif /* __CORE_CMINSTR_H */ |