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