core_cmFunc.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. /**************************************************************************//**
  2. * @file core_cmFunc.h
  3. * @brief CMSIS Cortex-M Core Function Access Header File
  4. * @version V1.40
  5. * @date 16. February 2010
  6. *
  7. * @note
  8. * Copyright (C) 2009-2010 ARM Limited. All rights reserved.
  9. *
  10. * @par
  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.
  14. *
  15. * @par
  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.
  21. *
  22. ******************************************************************************/
  23. #ifndef __CORE_CMFUNC_H__
  24. #define __CORE_CMFUNC_H__
  25. /* ########################### Core Function Access ########################### */
  26. #if defined ( __CC_ARM ) /*------------------ RealView Compiler ----------------*/
  27. /* ARM armcc specific functions */
  28. /**
  29. * @brief Enable IRQ Interrupts
  30. *
  31. * Enables IRQ interrupts by clearing the I-bit in the CPSR.
  32. * Can only be executed in Privileged modes.
  33. */
  34. /* intrinsic void __enable_irq(); */
  35. /**
  36. * @brief Disable IRQ Interrupts
  37. *
  38. * Disables IRQ interrupts by setting the I-bit in the CPSR.
  39. * Can only be executed in Privileged modes.
  40. */
  41. /* intrinsic void __disable_irq(); */
  42. /**
  43. * @brief Return the Control Register value
  44. *
  45. * @return Control value
  46. *
  47. * Return the content of the control register
  48. */
  49. #if (__ARMCC_VERSION < 400000)
  50. extern uint32_t __get_CONTROL(void);
  51. #else /* (__ARMCC_VERSION >= 400000) */
  52. static __INLINE uint32_t __get_CONTROL(void)
  53. {
  54. register uint32_t __regControl __ASM("control");
  55. return(__regControl);
  56. }
  57. #endif /* __ARMCC_VERSION */
  58. /**
  59. * @brief Set the Control Register value
  60. *
  61. * @param control Control value
  62. *
  63. * Set the control register
  64. */
  65. #if (__ARMCC_VERSION < 400000)
  66. extern void __set_CONTROL(uint32_t control);
  67. #else /* (__ARMCC_VERSION >= 400000) */
  68. static __INLINE void __set_CONTROL(uint32_t control)
  69. {
  70. register uint32_t __regControl __ASM("control");
  71. __regControl = control;
  72. }
  73. #endif /* __ARMCC_VERSION */
  74. /**
  75. * @brief Get IPSR Register value
  76. *
  77. * @return uint32_t IPSR value
  78. *
  79. * return the content of the IPSR register
  80. */
  81. #if (__ARMCC_VERSION < 400000)
  82. extern uint32_t __get_IPSR(void);
  83. #else /* (__ARMCC_VERSION >= 400000) */
  84. static __INLINE uint32_t __get_IPSR(void)
  85. {
  86. register uint32_t __regIPSR __ASM("ipsr");
  87. return(__regIPSR);
  88. }
  89. #endif /* __ARMCC_VERSION */
  90. /**
  91. * @brief Get APSR Register value
  92. *
  93. * @return uint32_t APSR value
  94. *
  95. * return the content of the APSR register
  96. */
  97. #if (__ARMCC_VERSION < 400000)
  98. extern uint32_t __get_APSR(void);
  99. #else /* (__ARMCC_VERSION >= 400000) */
  100. static __INLINE uint32_t __get_APSR(void)
  101. {
  102. register uint32_t __regAPSR __ASM("apsr");
  103. return(__regAPSR);
  104. }
  105. #endif /* __ARMCC_VERSION */
  106. /**
  107. * @brief Get xPSR Register value
  108. *
  109. * @return uint32_t xPSR value
  110. *
  111. * return the content of the xPSR register
  112. */
  113. #if (__ARMCC_VERSION < 400000)
  114. extern uint32_t __get_xPSR(void);
  115. #else /* (__ARMCC_VERSION >= 400000) */
  116. static __INLINE uint32_t __get_xPSR(void)
  117. {
  118. register uint32_t __regXPSR __ASM("xpsr");
  119. return(__regXPSR);
  120. }
  121. #endif /* __ARMCC_VERSION */
  122. /**
  123. * @brief Return the Process Stack Pointer
  124. *
  125. * @return ProcessStackPointer
  126. *
  127. * Return the actual process stack pointer
  128. */
  129. #if (__ARMCC_VERSION < 400000)
  130. extern uint32_t __get_PSP(void);
  131. #else /* (__ARMCC_VERSION >= 400000) */
  132. static __INLINE uint32_t __get_PSP(void)
  133. {
  134. register uint32_t __regProcessStackPointer __ASM("psp");
  135. return(__regProcessStackPointer);
  136. }
  137. #endif /* __ARMCC_VERSION */
  138. /**
  139. * @brief Set the Process Stack Pointer
  140. *
  141. * @param topOfProcStack Process Stack Pointer
  142. *
  143. * Assign the value ProcessStackPointer to the MSP
  144. * (process stack pointer) Cortex processor register
  145. */
  146. #if (__ARMCC_VERSION < 400000)
  147. extern void __set_PSP(uint32_t topOfProcStack);
  148. #else /* (__ARMCC_VERSION >= 400000) */
  149. static __INLINE void __set_PSP(uint32_t topOfProcStack)
  150. {
  151. register uint32_t __regProcessStackPointer __ASM("psp");
  152. __regProcessStackPointer = topOfProcStack;
  153. }
  154. #endif /* __ARMCC_VERSION */
  155. /**
  156. * @brief Return the Main Stack Pointer
  157. *
  158. * @return Main Stack Pointer
  159. *
  160. * Return the current value of the MSP (main stack pointer)
  161. * Cortex processor register
  162. */
  163. #if (__ARMCC_VERSION < 400000)
  164. extern uint32_t __get_MSP(void);
  165. #else /* (__ARMCC_VERSION >= 400000) */
  166. static __INLINE uint32_t __get_MSP(void)
  167. {
  168. register uint32_t __regMainStackPointer __ASM("msp");
  169. return(__regMainStackPointer);
  170. }
  171. #endif /* __ARMCC_VERSION */
  172. /**
  173. * @brief Set the Main Stack Pointer
  174. *
  175. * @param topOfMainStack Main Stack Pointer
  176. *
  177. * Assign the value mainStackPointer to the MSP
  178. * (main stack pointer) Cortex processor register
  179. */
  180. #if (__ARMCC_VERSION < 400000)
  181. extern void __set_MSP(uint32_t topOfMainStack);
  182. #else /* (__ARMCC_VERSION >= 400000) */
  183. static __INLINE void __set_MSP(uint32_t mainStackPointer)
  184. {
  185. register uint32_t __regMainStackPointer __ASM("msp");
  186. __regMainStackPointer = mainStackPointer;
  187. }
  188. #endif /* __ARMCC_VERSION */
  189. /**
  190. * @brief Return the Priority Mask value
  191. *
  192. * @return PriMask
  193. *
  194. * Return state of the priority mask bit from the priority mask register
  195. */
  196. #if (__ARMCC_VERSION < 400000)
  197. extern uint32_t __get_PRIMASK(void);
  198. #else /* (__ARMCC_VERSION >= 400000) */
  199. static __INLINE uint32_t __get_PRIMASK(void)
  200. {
  201. register uint32_t __regPriMask __ASM("primask");
  202. return(__regPriMask);
  203. }
  204. #endif /* __ARMCC_VERSION */
  205. /**
  206. * @brief Set the Priority Mask value
  207. *
  208. * @param priMask PriMask
  209. *
  210. * Set the priority mask bit in the priority mask register
  211. */
  212. #if (__ARMCC_VERSION < 400000)
  213. extern void __set_PRIMASK(uint32_t priMask);
  214. #else /* (__ARMCC_VERSION >= 400000) */
  215. static __INLINE void __set_PRIMASK(uint32_t priMask)
  216. {
  217. register uint32_t __regPriMask __ASM("primask");
  218. __regPriMask = (priMask);
  219. }
  220. #endif /* __ARMCC_VERSION */
  221. #if (__CORTEX_M >= 0x03)
  222. /**
  223. * @brief Enable FIQ Interrupts
  224. *
  225. * Enables FIQ interrupts by clearing the F-bit in the CPSR.
  226. * Can only be executed in Privileged modes.
  227. */
  228. #define __enable_fault_irq __enable_fiq
  229. /**
  230. * @brief Disable FIQ Interrupts
  231. *
  232. * Disables FIQ interrupts by setting the F-bit in the CPSR.
  233. * Can only be executed in Privileged modes.
  234. */
  235. #define __disable_fault_irq __disable_fiq
  236. /**
  237. * @brief Return the Base Priority value
  238. *
  239. * @return BasePriority
  240. *
  241. * Return the content of the base priority register
  242. */
  243. #if (__ARMCC_VERSION < 400000)
  244. extern uint32_t __get_BASEPRI(void);
  245. #else /* (__ARMCC_VERSION >= 400000) */
  246. static __INLINE uint32_t __get_BASEPRI(void)
  247. {
  248. register uint32_t __regBasePri __ASM("basepri");
  249. return(__regBasePri);
  250. }
  251. #endif /* __ARMCC_VERSION */
  252. /**
  253. * @brief Set the Base Priority value
  254. *
  255. * @param basePri BasePriority
  256. *
  257. * Set the base priority register
  258. */
  259. #if (__ARMCC_VERSION < 400000)
  260. extern void __set_BASEPRI(uint32_t basePri);
  261. #else /* (__ARMCC_VERSION >= 400000) */
  262. static __INLINE void __set_BASEPRI(uint32_t basePri)
  263. {
  264. register uint32_t __regBasePri __ASM("basepri");
  265. __regBasePri = (basePri & 0xff);
  266. }
  267. #endif /* __ARMCC_VERSION */
  268. /**
  269. * @brief Return the Fault Mask value
  270. *
  271. * @return FaultMask
  272. *
  273. * Return the content of the fault mask register
  274. */
  275. #if (__ARMCC_VERSION < 400000)
  276. extern uint32_t __get_FAULTMASK(void);
  277. #else /* (__ARMCC_VERSION >= 400000) */
  278. static __INLINE uint32_t __get_FAULTMASK(void)
  279. {
  280. register uint32_t __regFaultMask __ASM("faultmask");
  281. return(__regFaultMask);
  282. }
  283. #endif /* __ARMCC_VERSION */
  284. /**
  285. * @brief Set the Fault Mask value
  286. *
  287. * @param faultMask faultMask value
  288. *
  289. * Set the fault mask register
  290. */
  291. #if (__ARMCC_VERSION < 400000)
  292. extern void __set_FAULTMASK(uint32_t faultMask);
  293. #else /* (__ARMCC_VERSION >= 400000) */
  294. static __INLINE void __set_FAULTMASK(uint32_t faultMask)
  295. {
  296. register uint32_t __regFaultMask __ASM("faultmask");
  297. __regFaultMask = (faultMask & 1);
  298. }
  299. #endif /* __ARMCC_VERSION */
  300. #endif /* (__CORTEX_M >= 0x03) */
  301. #if (__CORTEX_M == 0x04)
  302. /**
  303. * @brief Return the FPSCR value
  304. *
  305. * @return FloatingPointStatusControlRegister
  306. *
  307. * Return the content of the FPSCR register
  308. */
  309. static __INLINE uint32_t __get_FPSCR(void)
  310. {
  311. #if (__FPU_PRESENT == 1)
  312. register uint32_t __regfpscr __ASM("fpscr");
  313. return(__regfpscr);
  314. #else
  315. return(0);
  316. #endif
  317. }
  318. /**
  319. * @brief Set the FPSCR value
  320. *
  321. * @param fpscr FloatingPointStatusControlRegister
  322. *
  323. * Set the FPSCR register
  324. */
  325. static __INLINE void __set_FPSCR(uint32_t fpscr)
  326. {
  327. #if (__FPU_PRESENT == 1)
  328. register uint32_t __regfpscr __ASM("fpscr");
  329. __regfpscr = (fpscr);
  330. #endif
  331. }
  332. #endif /* (__CORTEX_M == 0x04) */
  333. #elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/
  334. /* IAR iccarm specific functions */
  335. #if defined (__ICCARM__)
  336. #include <intrinsics.h> /* IAR Intrinsics */
  337. #endif
  338. #pragma diag_suppress=Pe940
  339. /**
  340. * @brief Enable IRQ Interrupts
  341. *
  342. * Enables IRQ interrupts by clearing the I-bit in the CPSR.
  343. * Can only be executed in Privileged modes.
  344. */
  345. #define __enable_irq __enable_interrupt
  346. /**
  347. * @brief Disable IRQ Interrupts
  348. *
  349. * Disables IRQ interrupts by setting the I-bit in the CPSR.
  350. * Can only be executed in Privileged modes.
  351. */
  352. #define __disable_irq __disable_interrupt
  353. /**
  354. * @brief Return the Control Register value
  355. *
  356. * @return Control value
  357. *
  358. * Return the content of the control register
  359. */
  360. /* intrinsic unsigned long __get_CONTROL( void ); (see intrinsic.h) */
  361. /**
  362. * @brief Set the Control Register value
  363. *
  364. * @param control Control value
  365. *
  366. * Set the control register
  367. */
  368. /* intrinsic void __set_CONTROL( unsigned long ); (see intrinsic.h) */
  369. /**
  370. * @brief Get IPSR Register value
  371. *
  372. * @return uint32_t IPSR value
  373. *
  374. * return the content of the IPSR register
  375. */
  376. static uint32_t __get_IPSR(void)
  377. {
  378. __ASM("mrs r0, ipsr");
  379. }
  380. /**
  381. * @brief Get APSR Register value
  382. *
  383. * @return uint32_t APSR value
  384. *
  385. * return the content of the APSR register
  386. */
  387. /* __intrinsic unsigned long __get_APSR( void ); (see intrinsic.h) */
  388. /**
  389. * @brief Get xPSR Register value
  390. *
  391. * @return uint32_t xPSR value
  392. *
  393. * return the content of the xPSR register
  394. */
  395. static uint32_t __get_xPSR(void)
  396. {
  397. __ASM("mrs r0, psr"); // assembler does not know "xpsr"
  398. }
  399. /**
  400. * @brief Return the Process Stack Pointer
  401. *
  402. * @return ProcessStackPointer
  403. *
  404. * Return the actual process stack pointer
  405. */
  406. static uint32_t __get_PSP(void)
  407. {
  408. __ASM("mrs r0, psp");
  409. }
  410. /**
  411. * @brief Set the Process Stack Pointer
  412. *
  413. * @param topOfProcStack Process Stack Pointer
  414. *
  415. * Assign the value ProcessStackPointer to the MSP
  416. * (process stack pointer) Cortex processor register
  417. */
  418. static void __set_PSP(uint32_t topOfProcStack)
  419. {
  420. __ASM("msr psp, r0");
  421. }
  422. /**
  423. * @brief Return the Main Stack Pointer
  424. *
  425. * @return Main Stack Pointer
  426. *
  427. * Return the current value of the MSP (main stack pointer)
  428. * Cortex processor register
  429. */
  430. static uint32_t __get_MSP(void)
  431. {
  432. __ASM("mrs r0, msp");
  433. }
  434. /**
  435. * @brief Set the Main Stack Pointer
  436. *
  437. * @param topOfMainStack Main Stack Pointer
  438. *
  439. * Assign the value mainStackPointer to the MSP
  440. * (main stack pointer) Cortex processor register
  441. */
  442. static void __set_MSP(uint32_t topOfMainStack)
  443. {
  444. __ASM("msr msp, r0");
  445. }
  446. /**
  447. * @brief Return the Priority Mask value
  448. *
  449. * @return PriMask
  450. *
  451. * Return state of the priority mask bit from the priority mask register
  452. */
  453. /* intrinsic unsigned long __get_PRIMASK( void ); (see intrinsic.h) */
  454. /**
  455. * @brief Set the Priority Mask value
  456. *
  457. * @param priMask PriMask
  458. *
  459. * Set the priority mask bit in the priority mask register
  460. */
  461. /* intrinsic void __set_PRIMASK( unsigned long ); (see intrinsic.h) */
  462. #if (__CORTEX_M >= 0x03)
  463. /**
  464. * @brief Enable FIQ Interrupts
  465. *
  466. * Enables FIQ interrupts by clearing the F-bit in the CPSR.
  467. * Can only be executed in Privileged modes.
  468. */
  469. static __INLINE void __enable_fault_irq() { __ASM ("cpsie f"); }
  470. /**
  471. * @brief Disable FIQ Interrupts
  472. *
  473. * Disables FIQ interrupts by setting the F-bit in the CPSR.
  474. * Can only be executed in Privileged modes.
  475. */
  476. static __INLINE void __disable_fault_irq() { __ASM ("cpsid f"); }
  477. /**
  478. * @brief Return the Base Priority value
  479. *
  480. * @return BasePriority
  481. *
  482. * Return the content of the base priority register
  483. */
  484. /* intrinsic unsigned long __get_BASEPRI( void ); (see intrinsic.h) */
  485. /**
  486. * @brief Set the Base Priority value
  487. *
  488. * @param basePri BasePriority
  489. *
  490. * Set the base priority register
  491. */
  492. /* intrinsic void __set_BASEPRI( unsigned long ); (see intrinsic.h) */
  493. /**
  494. * @brief Return the Fault Mask value
  495. *
  496. * @return FaultMask
  497. *
  498. * Return the content of the fault mask register
  499. */
  500. /* intrinsic unsigned long __get_FAULTMASK( void ); (see intrinsic.h) */
  501. /**
  502. * @brief Set the Fault Mask value
  503. *
  504. * @param faultMask faultMask value
  505. *
  506. * Set the fault mask register
  507. */
  508. /* intrinsic void __set_FAULTMASK(unsigned long); (see intrinsic.h) */
  509. #endif /* (__CORTEX_M >= 0x03) */
  510. #if (__CORTEX_M == 0x04)
  511. /**
  512. * @brief Return the FPSCR value
  513. *
  514. * @return FloatingPointStatusControlRegister
  515. *
  516. * Return the content of the FPSCR register
  517. */
  518. static __INLINE uint32_t __get_FPSCR(void)
  519. {
  520. #if (__FPU_PRESENT == 1)
  521. /* not yet implemented */
  522. return(0);
  523. #else
  524. return(0);
  525. #endif
  526. }
  527. /**
  528. * @brief Set the FPSCR value
  529. *
  530. * @param fpscr FloatingPointStatusControlRegister
  531. *
  532. * Set the FPSCR register
  533. */
  534. static __INLINE void __set_FPSCR(uint32_t fpscr)
  535. {
  536. #if (__FPU_PRESENT == 1)
  537. /* not yet implemented */
  538. #endif
  539. }
  540. #endif /* (__CORTEX_M == 0x04) */
  541. #pragma diag_default=Pe940
  542. #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
  543. /* GNU gcc specific functions */
  544. /**
  545. * @brief Enable IRQ Interrupts
  546. *
  547. * Enables IRQ interrupts by clearing the I-bit in the CPSR.
  548. * Can only be executed in Privileged modes.
  549. */
  550. static __INLINE void __enable_irq() { __ASM volatile ("cpsie i"); }
  551. /**
  552. * @brief Disable IRQ Interrupts
  553. *
  554. * Disables IRQ interrupts by setting the I-bit in the CPSR.
  555. * Can only be executed in Privileged modes.
  556. */
  557. static __INLINE void __disable_irq() { __ASM volatile ("cpsid i"); }
  558. /**
  559. * @brief Return the Control Register value
  560. *
  561. * @return Control value
  562. *
  563. * Return the content of the control register
  564. */
  565. static __INLINE uint32_t __get_CONTROL(void)
  566. {
  567. uint32_t result=0;
  568. __ASM volatile ("MRS %0, control" : "=r" (result) );
  569. return(result);
  570. }
  571. /**
  572. * @brief Set the Control Register value
  573. *
  574. * @param control Control value
  575. *
  576. * Set the control register
  577. */
  578. static __INLINE void __set_CONTROL(uint32_t control)
  579. {
  580. __ASM volatile ("MSR control, %0" : : "r" (control) );
  581. }
  582. /**
  583. * @brief Get IPSR Register value
  584. *
  585. * @return uint32_t IPSR value
  586. *
  587. * return the content of the IPSR register
  588. */
  589. static __INLINE uint32_t __get_IPSR(void)
  590. {
  591. uint32_t result=0;
  592. __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
  593. return(result);
  594. }
  595. /**
  596. * @brief Get APSR Register value
  597. *
  598. * @return uint32_t APSR value
  599. *
  600. * return the content of the APSR register
  601. */
  602. static __INLINE uint32_t __get_APSR(void)
  603. {
  604. uint32_t result=0;
  605. __ASM volatile ("MRS %0, apsr" : "=r" (result) );
  606. return(result);
  607. }
  608. /**
  609. * @brief Get xPSR Register value
  610. *
  611. * @return uint32_t xPSR value
  612. *
  613. * return the content of the xPSR register
  614. */
  615. static __INLINE uint32_t __get_xPSR(void)
  616. {
  617. uint32_t result=0;
  618. __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
  619. return(result);
  620. }
  621. /**
  622. * @brief Return the Process Stack Pointer
  623. *
  624. * @return ProcessStackPointer
  625. *
  626. * Return the actual process stack pointer
  627. */
  628. static __INLINE uint32_t __get_PSP(void) __attribute__( ( naked ) );
  629. static __INLINE uint32_t __get_PSP(void)
  630. {
  631. register uint32_t result __ASM ("r0") = 0;
  632. __ASM volatile ("MRS %0, psp\n"
  633. "BX lr \n" : "=r" (result) );
  634. return(result);
  635. }
  636. /**
  637. * @brief Set the Process Stack Pointer
  638. *
  639. * @param topOfProcStack Process Stack Pointer
  640. *
  641. * Assign the value ProcessStackPointer to the MSP
  642. * (process stack pointer) Cortex processor register
  643. */
  644. static __INLINE void __set_PSP(uint32_t topOfProcStack) __attribute__( ( naked ) );
  645. static __INLINE void __set_PSP(uint32_t topOfProcStack)
  646. {
  647. __ASM volatile ("MSR psp, %0\n"
  648. "BX lr \n" : : "r" (topOfProcStack) );
  649. }
  650. /**
  651. * @brief Return the Main Stack Pointer
  652. *
  653. * @return Main Stack Pointer
  654. *
  655. * Return the current value of the MSP (main stack pointer)
  656. * Cortex processor register
  657. */
  658. static __INLINE uint32_t __get_MSP(void) __attribute__( ( naked ) );
  659. static __INLINE uint32_t __get_MSP(void)
  660. {
  661. register uint32_t result __ASM ("r0") = 0;
  662. __ASM volatile ("MRS %0, msp\n"
  663. "BX lr \n" : "=r" (result) );
  664. return(result);
  665. }
  666. /**
  667. * @brief Set the Main Stack Pointer
  668. *
  669. * @param topOfMainStack Main Stack Pointer
  670. *
  671. * Assign the value mainStackPointer to the MSP
  672. * (main stack pointer) Cortex processor register
  673. */
  674. static __INLINE void __set_MSP(uint32_t topOfMainStack) __attribute__( ( naked ) );
  675. static __INLINE void __set_MSP(uint32_t topOfMainStack)
  676. {
  677. __ASM volatile ("MSR msp, %0\n"
  678. "BX lr \n" : : "r" (topOfMainStack) );
  679. }
  680. /**
  681. * @brief Return the Priority Mask value
  682. *
  683. * @return PriMask
  684. *
  685. * Return state of the priority mask bit from the priority mask register
  686. */
  687. static __INLINE uint32_t __get_PRIMASK(void)
  688. {
  689. uint32_t result=0;
  690. __ASM volatile ("MRS %0, primask" : "=r" (result) );
  691. return(result);
  692. }
  693. /**
  694. * @brief Set the Priority Mask value
  695. *
  696. * @param priMask PriMask
  697. *
  698. * Set the priority mask bit in the priority mask register
  699. */
  700. static __INLINE void __set_PRIMASK(uint32_t priMask)
  701. {
  702. __ASM volatile ("MSR primask, %0" : : "r" (priMask) );
  703. }
  704. #if (__CORTEX_M >= 0x03)
  705. /**
  706. * @brief Enable FIQ Interrupts
  707. *
  708. * Enables FIQ interrupts by clearing the F-bit in the CPSR.
  709. * Can only be executed in Privileged modes.
  710. */
  711. static __INLINE void __enable_fault_irq() { __ASM volatile ("cpsie f"); }
  712. /**
  713. * @brief Disable FIQ Interrupts
  714. *
  715. * Disables FIQ interrupts by setting the F-bit in the CPSR.
  716. * Can only be executed in Privileged modes.
  717. */
  718. static __INLINE void __disable_fault_irq() { __ASM volatile ("cpsid f"); }
  719. /**
  720. * @brief Return the Base Priority value
  721. *
  722. * @return BasePriority
  723. *
  724. * Return the content of the base priority register
  725. */
  726. static __INLINE uint32_t __get_BASEPRI(void)
  727. {
  728. uint32_t result=0;
  729. __ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
  730. return(result);
  731. }
  732. /**
  733. * @brief Set the Base Priority value
  734. *
  735. * @param basePri BasePriority
  736. *
  737. * Set the base priority register
  738. */
  739. static __INLINE void __set_BASEPRI(uint32_t value)
  740. {
  741. __ASM volatile ("MSR basepri, %0" : : "r" (value) );
  742. }
  743. /**
  744. * @brief Return the Fault Mask value
  745. *
  746. * @return FaultMask
  747. *
  748. * Return the content of the fault mask register
  749. */
  750. static __INLINE uint32_t __get_FAULTMASK(void)
  751. {
  752. uint32_t result=0;
  753. __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
  754. return(result);
  755. }
  756. #endif /* (__CORTEX_M >= 0x03) */
  757. /**
  758. * @brief Set the Fault Mask value
  759. *
  760. * @param faultMask faultMask value
  761. *
  762. * Set the fault mask register
  763. */
  764. static __INLINE void __set_FAULTMASK(uint32_t faultMask)
  765. {
  766. __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) );
  767. }
  768. #if (__CORTEX_M == 0x04)
  769. /**
  770. * @brief Return the FPSCR value
  771. *
  772. * @return FloatingPointStatusControlRegister
  773. *
  774. * Return the content of the FPSCR register
  775. */
  776. static __INLINE uint32_t __get_FPSCR(void)
  777. {
  778. #if (__FPU_PRESENT == 1)
  779. uint32_t result=0;
  780. __ASM volatile ("MRS %0, fpscr" : "=r" (result) );
  781. return(result);
  782. #else
  783. return(0);
  784. #endif
  785. }
  786. /**
  787. * @brief Set the FPSCR value
  788. *
  789. * @param fpscr FloatingPointStatusControlRegister
  790. *
  791. * Set the FPSCR register
  792. */
  793. static __INLINE void __set_FPSCR(uint32_t fpscr)
  794. {
  795. #if (__FPU_PRESENT == 1)
  796. __ASM volatile ("MSR control, %0" : : "r" (fpscr) );
  797. #endif
  798. }
  799. #endif /* (__CORTEX_M == 0x04) */
  800. #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/
  801. /* TASKING carm specific functions */
  802. /*
  803. * The CMSIS functions have been implemented as intrinsics in the compiler.
  804. * Please use "carm -?i" to get an up to date list of all instrinsics,
  805. * Including the CMSIS ones.
  806. */
  807. #endif
  808. #endif // __CORE_CMFUNC_H__