STM32F10x Standard Peripherals Library
3.5.0
|
00001 /**************************************************************************/ 00024 #include <stdint.h> 00025 00026 /* define compiler specific symbols */ 00027 #if defined ( __CC_ARM ) 00028 #define __ASM __asm 00029 #define __INLINE __inline 00031 #elif defined ( __ICCARM__ ) 00032 #define __ASM __asm 00033 #define __INLINE inline 00035 #elif defined ( __GNUC__ ) 00036 #define __ASM __asm 00037 #define __INLINE inline 00039 #elif defined ( __TASKING__ ) 00040 #define __ASM __asm 00041 #define __INLINE inline 00043 #endif 00044 00045 00046 /* ################### Compiler specific Intrinsics ########################### */ 00047 00048 #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ 00049 /* ARM armcc specific functions */ 00050 00058 __ASM uint32_t __get_PSP(void) 00059 { 00060 mrs r0, psp 00061 bx lr 00062 } 00063 00072 __ASM void __set_PSP(uint32_t topOfProcStack) 00073 { 00074 msr psp, r0 00075 bx lr 00076 } 00077 00086 __ASM uint32_t __get_MSP(void) 00087 { 00088 mrs r0, msp 00089 bx lr 00090 } 00091 00100 __ASM void __set_MSP(uint32_t mainStackPointer) 00101 { 00102 msr msp, r0 00103 bx lr 00104 } 00105 00114 __ASM uint32_t __REV16(uint16_t value) 00115 { 00116 rev16 r0, r0 00117 bx lr 00118 } 00119 00128 __ASM int32_t __REVSH(int16_t value) 00129 { 00130 revsh r0, r0 00131 bx lr 00132 } 00133 00134 00135 #if (__ARMCC_VERSION < 400000) 00136 00142 __ASM void __CLREX(void) 00143 { 00144 clrex 00145 } 00146 00154 __ASM uint32_t __get_BASEPRI(void) 00155 { 00156 mrs r0, basepri 00157 bx lr 00158 } 00159 00167 __ASM void __set_BASEPRI(uint32_t basePri) 00168 { 00169 msr basepri, r0 00170 bx lr 00171 } 00172 00180 __ASM uint32_t __get_PRIMASK(void) 00181 { 00182 mrs r0, primask 00183 bx lr 00184 } 00185 00193 __ASM void __set_PRIMASK(uint32_t priMask) 00194 { 00195 msr primask, r0 00196 bx lr 00197 } 00198 00206 __ASM uint32_t __get_FAULTMASK(void) 00207 { 00208 mrs r0, faultmask 00209 bx lr 00210 } 00211 00219 __ASM void __set_FAULTMASK(uint32_t faultMask) 00220 { 00221 msr faultmask, r0 00222 bx lr 00223 } 00224 00232 __ASM uint32_t __get_CONTROL(void) 00233 { 00234 mrs r0, control 00235 bx lr 00236 } 00237 00245 __ASM void __set_CONTROL(uint32_t control) 00246 { 00247 msr control, r0 00248 bx lr 00249 } 00250 00251 #endif /* __ARMCC_VERSION */ 00252 00253 00254 00255 #elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/ 00256 /* IAR iccarm specific functions */ 00257 #pragma diag_suppress=Pe940 00258 00266 uint32_t __get_PSP(void) 00267 { 00268 __ASM("mrs r0, psp"); 00269 __ASM("bx lr"); 00270 } 00271 00280 void __set_PSP(uint32_t topOfProcStack) 00281 { 00282 __ASM("msr psp, r0"); 00283 __ASM("bx lr"); 00284 } 00285 00294 uint32_t __get_MSP(void) 00295 { 00296 __ASM("mrs r0, msp"); 00297 __ASM("bx lr"); 00298 } 00299 00308 void __set_MSP(uint32_t topOfMainStack) 00309 { 00310 __ASM("msr msp, r0"); 00311 __ASM("bx lr"); 00312 } 00313 00322 uint32_t __REV16(uint16_t value) 00323 { 00324 __ASM("rev16 r0, r0"); 00325 __ASM("bx lr"); 00326 } 00327 00336 uint32_t __RBIT(uint32_t value) 00337 { 00338 __ASM("rbit r0, r0"); 00339 __ASM("bx lr"); 00340 } 00341 00350 uint8_t __LDREXB(uint8_t *addr) 00351 { 00352 __ASM("ldrexb r0, [r0]"); 00353 __ASM("bx lr"); 00354 } 00355 00364 uint16_t __LDREXH(uint16_t *addr) 00365 { 00366 __ASM("ldrexh r0, [r0]"); 00367 __ASM("bx lr"); 00368 } 00369 00378 uint32_t __LDREXW(uint32_t *addr) 00379 { 00380 __ASM("ldrex r0, [r0]"); 00381 __ASM("bx lr"); 00382 } 00383 00393 uint32_t __STREXB(uint8_t value, uint8_t *addr) 00394 { 00395 __ASM("strexb r0, r0, [r1]"); 00396 __ASM("bx lr"); 00397 } 00398 00408 uint32_t __STREXH(uint16_t value, uint16_t *addr) 00409 { 00410 __ASM("strexh r0, r0, [r1]"); 00411 __ASM("bx lr"); 00412 } 00413 00423 uint32_t __STREXW(uint32_t value, uint32_t *addr) 00424 { 00425 __ASM("strex r0, r0, [r1]"); 00426 __ASM("bx lr"); 00427 } 00428 00429 #pragma diag_default=Pe940 00430 00431 00432 #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/ 00433 /* GNU gcc specific functions */ 00434 00442 uint32_t __get_PSP(void) __attribute__( ( naked ) ); 00443 uint32_t __get_PSP(void) 00444 { 00445 uint32_t result=0; 00446 00447 __ASM volatile ("MRS %0, psp\n\t" 00448 "MOV r0, %0 \n\t" 00449 "BX lr \n\t" : "=r" (result) ); 00450 return(result); 00451 } 00452 00461 void __set_PSP(uint32_t topOfProcStack) __attribute__( ( naked ) ); 00462 void __set_PSP(uint32_t topOfProcStack) 00463 { 00464 __ASM volatile ("MSR psp, %0\n\t" 00465 "BX lr \n\t" : : "r" (topOfProcStack) ); 00466 } 00467 00476 uint32_t __get_MSP(void) __attribute__( ( naked ) ); 00477 uint32_t __get_MSP(void) 00478 { 00479 uint32_t result=0; 00480 00481 __ASM volatile ("MRS %0, msp\n\t" 00482 "MOV r0, %0 \n\t" 00483 "BX lr \n\t" : "=r" (result) ); 00484 return(result); 00485 } 00486 00495 void __set_MSP(uint32_t topOfMainStack) __attribute__( ( naked ) ); 00496 void __set_MSP(uint32_t topOfMainStack) 00497 { 00498 __ASM volatile ("MSR msp, %0\n\t" 00499 "BX lr \n\t" : : "r" (topOfMainStack) ); 00500 } 00501 00509 uint32_t __get_BASEPRI(void) 00510 { 00511 uint32_t result=0; 00512 00513 __ASM volatile ("MRS %0, basepri_max" : "=r" (result) ); 00514 return(result); 00515 } 00516 00524 void __set_BASEPRI(uint32_t value) 00525 { 00526 __ASM volatile ("MSR basepri, %0" : : "r" (value) ); 00527 } 00528 00536 uint32_t __get_PRIMASK(void) 00537 { 00538 uint32_t result=0; 00539 00540 __ASM volatile ("MRS %0, primask" : "=r" (result) ); 00541 return(result); 00542 } 00543 00551 void __set_PRIMASK(uint32_t priMask) 00552 { 00553 __ASM volatile ("MSR primask, %0" : : "r" (priMask) ); 00554 } 00555 00563 uint32_t __get_FAULTMASK(void) 00564 { 00565 uint32_t result=0; 00566 00567 __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); 00568 return(result); 00569 } 00570 00578 void __set_FAULTMASK(uint32_t faultMask) 00579 { 00580 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) ); 00581 } 00582 00590 uint32_t __get_CONTROL(void) 00591 { 00592 uint32_t result=0; 00593 00594 __ASM volatile ("MRS %0, control" : "=r" (result) ); 00595 return(result); 00596 } 00597 00605 void __set_CONTROL(uint32_t control) 00606 { 00607 __ASM volatile ("MSR control, %0" : : "r" (control) ); 00608 } 00609 00610 00619 uint32_t __REV(uint32_t value) 00620 { 00621 uint32_t result=0; 00622 00623 __ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) ); 00624 return(result); 00625 } 00626 00635 uint32_t __REV16(uint16_t value) 00636 { 00637 uint32_t result=0; 00638 00639 __ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) ); 00640 return(result); 00641 } 00642 00651 int32_t __REVSH(int16_t value) 00652 { 00653 uint32_t result=0; 00654 00655 __ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) ); 00656 return(result); 00657 } 00658 00667 uint32_t __RBIT(uint32_t value) 00668 { 00669 uint32_t result=0; 00670 00671 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); 00672 return(result); 00673 } 00674 00683 uint8_t __LDREXB(uint8_t *addr) 00684 { 00685 uint8_t result=0; 00686 00687 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) ); 00688 return(result); 00689 } 00690 00699 uint16_t __LDREXH(uint16_t *addr) 00700 { 00701 uint16_t result=0; 00702 00703 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) ); 00704 return(result); 00705 } 00706 00715 uint32_t __LDREXW(uint32_t *addr) 00716 { 00717 uint32_t result=0; 00718 00719 __ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) ); 00720 return(result); 00721 } 00722 00732 uint32_t __STREXB(uint8_t value, uint8_t *addr) 00733 { 00734 uint32_t result=0; 00735 00736 __ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); 00737 return(result); 00738 } 00739 00749 uint32_t __STREXH(uint16_t value, uint16_t *addr) 00750 { 00751 uint32_t result=0; 00752 00753 __ASM volatile ("strexh %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); 00754 return(result); 00755 } 00756 00766 uint32_t __STREXW(uint32_t value, uint32_t *addr) 00767 { 00768 uint32_t result=0; 00769 00770 __ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) ); 00771 return(result); 00772 } 00773 00774 00775 #elif (defined (__TASKING__)) /*------------------ TASKING Compiler ---------------------*/ 00776 /* TASKING carm specific functions */ 00777 00778 /* 00779 * The CMSIS functions have been implemented as intrinsics in the compiler. 00780 * Please use "carm -?i" to get an up to date list of all instrinsics, 00781 * Including the CMSIS ones. 00782 */ 00783 00784 #endif