1 /**************************************************************************//**
3 * @brief CMSIS Cortex-M3 Core Peripheral Access Layer Source File
5 * @date 30. October 2009
8 * Copyright (C) 2009 ARM Limited. All rights reserved.
11 * ARM Limited (ARM) is supplying this software for use with Cortex-M
12 * processor based microcontrollers. This file can be freely distributed
13 * within development tools that are supporting such ARM based processors.
16 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
17 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
19 * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
20 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22 ******************************************************************************/
26 /* define compiler specific symbols */
27 #if defined ( __CC_ARM )
28 #define __ASM __asm /*!< asm keyword for ARM Compiler */
29 #define __INLINE __inline /*!< inline keyword for ARM Compiler */
31 #elif defined ( __ICCARM__ )
32 #define __ASM __asm /*!< asm keyword for IAR Compiler */
33 #define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */
35 #elif defined ( __GNUC__ )
36 #define __ASM __asm /*!< asm keyword for GNU Compiler */
37 #define __INLINE inline /*!< inline keyword for GNU Compiler */
39 #elif defined ( __TASKING__ )
40 #define __ASM __asm /*!< asm keyword for TASKING Compiler */
41 #define __INLINE inline /*!< inline keyword for TASKING Compiler */
46 /* ################### Compiler specific Intrinsics ########################### */
48 #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
49 /* ARM armcc specific functions */
52 * @brief Return the Process Stack Pointer
54 * @return ProcessStackPointer
56 * Return the actual process stack pointer
58 __ASM uint32_t __get_PSP(void)
65 * @brief Set the Process Stack Pointer
67 * @param topOfProcStack Process Stack Pointer
69 * Assign the value ProcessStackPointer to the MSP
70 * (process stack pointer) Cortex processor register
72 __ASM void __set_PSP(uint32_t topOfProcStack)
79 * @brief Return the Main Stack Pointer
81 * @return Main Stack Pointer
83 * Return the current value of the MSP (main stack pointer)
84 * Cortex processor register
86 __ASM uint32_t __get_MSP(void)
93 * @brief Set the Main Stack Pointer
95 * @param topOfMainStack Main Stack Pointer
97 * Assign the value mainStackPointer to the MSP
98 * (main stack pointer) Cortex processor register
100 __ASM void __set_MSP(uint32_t mainStackPointer)
107 * @brief Reverse byte order in unsigned short value
109 * @param value value to reverse
110 * @return reversed value
112 * Reverse byte order in unsigned short value
114 __ASM uint32_t __REV16(uint16_t value)
121 * @brief Reverse byte order in signed short value with sign extension to integer
123 * @param value value to reverse
124 * @return reversed value
126 * Reverse byte order in signed short value with sign extension to integer
128 __ASM int32_t __REVSH(int16_t value)
135 #if (__ARMCC_VERSION < 400000)
138 * @brief Remove the exclusive lock created by ldrex
140 * Removes the exclusive lock which is created by ldrex.
142 __ASM void __CLREX(void)
148 * @brief Return the Base Priority value
150 * @return BasePriority
152 * Return the content of the base priority register
154 __ASM uint32_t __get_BASEPRI(void)
161 * @brief Set the Base Priority value
163 * @param basePri BasePriority
165 * Set the base priority register
167 __ASM void __set_BASEPRI(uint32_t basePri)
174 * @brief Return the Priority Mask value
178 * Return state of the priority mask bit from the priority mask register
180 __ASM uint32_t __get_PRIMASK(void)
187 * @brief Set the Priority Mask value
189 * @param priMask PriMask
191 * Set the priority mask bit in the priority mask register
193 __ASM void __set_PRIMASK(uint32_t priMask)
200 * @brief Return the Fault Mask value
204 * Return the content of the fault mask register
206 __ASM uint32_t __get_FAULTMASK(void)
213 * @brief Set the Fault Mask value
215 * @param faultMask faultMask value
217 * Set the fault mask register
219 __ASM void __set_FAULTMASK(uint32_t faultMask)
226 * @brief Return the Control Register value
228 * @return Control value
230 * Return the content of the control register
232 __ASM uint32_t __get_CONTROL(void)
239 * @brief Set the Control Register value
241 * @param control Control value
243 * Set the control register
245 __ASM void __set_CONTROL(uint32_t control)
251 #endif /* __ARMCC_VERSION */
255 #elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/
256 /* IAR iccarm specific functions */
257 #pragma diag_suppress=Pe940
260 * @brief Return the Process Stack Pointer
262 * @return ProcessStackPointer
264 * Return the actual process stack pointer
266 uint32_t __get_PSP(void)
268 __ASM("mrs r0, psp");
273 * @brief Set the Process Stack Pointer
275 * @param topOfProcStack Process Stack Pointer
277 * Assign the value ProcessStackPointer to the MSP
278 * (process stack pointer) Cortex processor register
280 void __set_PSP(uint32_t topOfProcStack)
282 __ASM("msr psp, r0");
287 * @brief Return the Main Stack Pointer
289 * @return Main Stack Pointer
291 * Return the current value of the MSP (main stack pointer)
292 * Cortex processor register
294 uint32_t __get_MSP(void)
296 __ASM("mrs r0, msp");
301 * @brief Set the Main Stack Pointer
303 * @param topOfMainStack Main Stack Pointer
305 * Assign the value mainStackPointer to the MSP
306 * (main stack pointer) Cortex processor register
308 void __set_MSP(uint32_t topOfMainStack)
310 __ASM("msr msp, r0");
315 * @brief Reverse byte order in unsigned short value
317 * @param value value to reverse
318 * @return reversed value
320 * Reverse byte order in unsigned short value
322 uint32_t __REV16(uint16_t value)
324 __ASM("rev16 r0, r0");
329 * @brief Reverse bit order of value
331 * @param value value to reverse
332 * @return reversed value
334 * Reverse bit order of value
336 uint32_t __RBIT(uint32_t value)
338 __ASM("rbit r0, r0");
343 * @brief LDR Exclusive (8 bit)
345 * @param *addr address pointer
346 * @return value of (*address)
348 * Exclusive LDR command for 8 bit values)
350 uint8_t __LDREXB(uint8_t *addr)
352 __ASM("ldrexb r0, [r0]");
357 * @brief LDR Exclusive (16 bit)
359 * @param *addr address pointer
360 * @return value of (*address)
362 * Exclusive LDR command for 16 bit values
364 uint16_t __LDREXH(uint16_t *addr)
366 __ASM("ldrexh r0, [r0]");
371 * @brief LDR Exclusive (32 bit)
373 * @param *addr address pointer
374 * @return value of (*address)
376 * Exclusive LDR command for 32 bit values
378 uint32_t __LDREXW(uint32_t *addr)
380 __ASM("ldrex r0, [r0]");
385 * @brief STR Exclusive (8 bit)
387 * @param value value to store
388 * @param *addr address pointer
389 * @return successful / failed
391 * Exclusive STR command for 8 bit values
393 uint32_t __STREXB(uint8_t value, uint8_t *addr)
395 __ASM("strexb r0, r0, [r1]");
400 * @brief STR Exclusive (16 bit)
402 * @param value value to store
403 * @param *addr address pointer
404 * @return successful / failed
406 * Exclusive STR command for 16 bit values
408 uint32_t __STREXH(uint16_t value, uint16_t *addr)
410 __ASM("strexh r0, r0, [r1]");
415 * @brief STR Exclusive (32 bit)
417 * @param value value to store
418 * @param *addr address pointer
419 * @return successful / failed
421 * Exclusive STR command for 32 bit values
423 uint32_t __STREXW(uint32_t value, uint32_t *addr)
425 __ASM("strex r0, r0, [r1]");
429 #pragma diag_default=Pe940
432 #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
433 /* GNU gcc specific functions */
436 * @brief Return the Process Stack Pointer
438 * @return ProcessStackPointer
440 * Return the actual process stack pointer
442 uint32_t __get_PSP(void) __attribute__( ( naked ) );
443 uint32_t __get_PSP(void)
447 __ASM volatile ("MRS %0, psp\n\t"
449 "BX lr \n\t" : "=r" (result) );
454 * @brief Set the Process Stack Pointer
456 * @param topOfProcStack Process Stack Pointer
458 * Assign the value ProcessStackPointer to the MSP
459 * (process stack pointer) Cortex processor register
461 void __set_PSP(uint32_t topOfProcStack) __attribute__( ( naked ) );
462 void __set_PSP(uint32_t topOfProcStack)
464 __ASM volatile ("MSR psp, %0\n\t"
465 "BX lr \n\t" : : "r" (topOfProcStack) );
469 * @brief Return the Main Stack Pointer
471 * @return Main Stack Pointer
473 * Return the current value of the MSP (main stack pointer)
474 * Cortex processor register
476 uint32_t __get_MSP(void) __attribute__( ( naked ) );
477 uint32_t __get_MSP(void)
481 __ASM volatile ("MRS %0, msp\n\t"
483 "BX lr \n\t" : "=r" (result) );
488 * @brief Set the Main Stack Pointer
490 * @param topOfMainStack Main Stack Pointer
492 * Assign the value mainStackPointer to the MSP
493 * (main stack pointer) Cortex processor register
495 void __set_MSP(uint32_t topOfMainStack) __attribute__( ( naked ) );
496 void __set_MSP(uint32_t topOfMainStack)
498 __ASM volatile ("MSR msp, %0\n\t"
499 "BX lr \n\t" : : "r" (topOfMainStack) );
503 * @brief Return the Base Priority value
505 * @return BasePriority
507 * Return the content of the base priority register
509 uint32_t __get_BASEPRI(void)
513 __ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
518 * @brief Set the Base Priority value
520 * @param basePri BasePriority
522 * Set the base priority register
524 void __set_BASEPRI(uint32_t value)
526 __ASM volatile ("MSR basepri, %0" : : "r" (value) );
530 * @brief Return the Priority Mask value
534 * Return state of the priority mask bit from the priority mask register
536 uint32_t __get_PRIMASK(void)
540 __ASM volatile ("MRS %0, primask" : "=r" (result) );
545 * @brief Set the Priority Mask value
547 * @param priMask PriMask
549 * Set the priority mask bit in the priority mask register
551 void __set_PRIMASK(uint32_t priMask)
553 __ASM volatile ("MSR primask, %0" : : "r" (priMask) );
557 * @brief Return the Fault Mask value
561 * Return the content of the fault mask register
563 uint32_t __get_FAULTMASK(void)
567 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
572 * @brief Set the Fault Mask value
574 * @param faultMask faultMask value
576 * Set the fault mask register
578 void __set_FAULTMASK(uint32_t faultMask)
580 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) );
584 * @brief Return the Control Register value
586 * @return Control value
588 * Return the content of the control register
590 uint32_t __get_CONTROL(void)
594 __ASM volatile ("MRS %0, control" : "=r" (result) );
599 * @brief Set the Control Register value
601 * @param control Control value
603 * Set the control register
605 void __set_CONTROL(uint32_t control)
607 __ASM volatile ("MSR control, %0" : : "r" (control) );
612 * @brief Reverse byte order in integer value
614 * @param value value to reverse
615 * @return reversed value
617 * Reverse byte order in integer value
619 uint32_t __REV(uint32_t value)
623 __ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) );
628 * @brief Reverse byte order in unsigned short value
630 * @param value value to reverse
631 * @return reversed value
633 * Reverse byte order in unsigned short value
635 uint32_t __REV16(uint16_t value)
639 __ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) );
644 * @brief Reverse byte order in signed short value with sign extension to integer
646 * @param value value to reverse
647 * @return reversed value
649 * Reverse byte order in signed short value with sign extension to integer
651 int32_t __REVSH(int16_t value)
655 __ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) );
660 * @brief Reverse bit order of value
662 * @param value value to reverse
663 * @return reversed value
665 * Reverse bit order of value
667 uint32_t __RBIT(uint32_t value)
671 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
676 * @brief LDR Exclusive (8 bit)
678 * @param *addr address pointer
679 * @return value of (*address)
681 * Exclusive LDR command for 8 bit value
683 uint8_t __LDREXB(uint8_t *addr)
687 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) );
692 * @brief LDR Exclusive (16 bit)
694 * @param *addr address pointer
695 * @return value of (*address)
697 * Exclusive LDR command for 16 bit values
699 uint16_t __LDREXH(uint16_t *addr)
703 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) );
708 * @brief LDR Exclusive (32 bit)
710 * @param *addr address pointer
711 * @return value of (*address)
713 * Exclusive LDR command for 32 bit values
715 uint32_t __LDREXW(uint32_t *addr)
719 __ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) );
724 * @brief STR Exclusive (8 bit)
726 * @param value value to store
727 * @param *addr address pointer
728 * @return successful / failed
730 * Exclusive STR command for 8 bit values
732 uint32_t __STREXB(uint8_t value, uint8_t *addr)
736 __ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
741 * @brief STR Exclusive (16 bit)
743 * @param value value to store
744 * @param *addr address pointer
745 * @return successful / failed
747 * Exclusive STR command for 16 bit values
749 uint32_t __STREXH(uint16_t value, uint16_t *addr)
753 __ASM volatile ("strexh %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
758 * @brief STR Exclusive (32 bit)
760 * @param value value to store
761 * @param *addr address pointer
762 * @return successful / failed
764 * Exclusive STR command for 32 bit values
766 uint32_t __STREXW(uint32_t value, uint32_t *addr)
770 __ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
775 #elif (defined (__TASKING__)) /*------------------ TASKING Compiler ---------------------*/
776 /* TASKING carm specific functions */
779 * The CMSIS functions have been implemented as intrinsics in the compiler.
780 * Please use "carm -?i" to get an up to date list of all instrinsics,
781 * Including the CMSIS ones.