I2C_EEPROM

Committer:
jhon309
Date:
Thu Aug 13 00:23:16 2015 +0000
Revision:
0:ac8863619623
I2C

Who changed what in which revision?

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