Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ucmsis.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #ifndef __UCMSIS_H__
  2. #define __UCMSIS_H__
  3. #include <stdint.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #define __I volatile const /*!< Defines 'read only' permissions */
  8. #define __O volatile /*!< Defines 'write only' permissions */
  9. #define __IO volatile /*!< Defines 'read / write' permissions */
  10. /* following defines should be used for structure members */
  11. #define __IM volatile const /*! Defines 'read only' structure member permissions */
  12. #define __OM volatile /*! Defines 'write only' structure member permissions */
  13. #define __IOM volatile /*! Defines 'read / write' structure member permissions */
  14. #define __NVIC_PRIO_BITS 8U
  15. #define WEAK __attribute__((weak))
  16. #define ALIAS(sym) __attribute__((weak, alias (sym)))
  17. #define NORETURN __attribute__((noreturn))
  18. #define SECTION(name) __attribute__ ((section(name)))
  19. #define INLINE __attribute__((always_inline)) inline
  20. #define STATIC_INLINE static INLINE
  21. typedef enum IRQn
  22. {
  23. /* ------------------- Processor Exceptions Numbers ----------------------------- */
  24. NonMaskableInt_IRQn = -14, /* 2 Non Maskable Interrupt */
  25. HardFault_IRQn = -13, /* 3 HardFault Interrupt */
  26. SVCall_IRQn = -5, /* 11 SV Call Interrupt */
  27. PendSV_IRQn = -2, /* 14 Pend SV Interrupt */
  28. SysTick_IRQn = -1, /* 15 System Tick Interrupt */
  29. } IRQn_Type;
  30. /* Memory mapping of Core Hardware */
  31. #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
  32. #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
  33. #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
  34. #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */
  35. #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
  36. #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
  37. #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
  38. #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
  39. #define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
  40. #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
  41. #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
  42. #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
  43. #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */
  44. #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */
  45. #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
  46. #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
  47. /**
  48. \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
  49. */
  50. typedef struct {
  51. __IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
  52. uint32_t RESERVED0[24U];
  53. __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
  54. uint32_t RESERVED1[24U];
  55. __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
  56. uint32_t RESERVED2[24U];
  57. __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
  58. uint32_t RESERVED3[24U];
  59. __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */
  60. uint32_t RESERVED4[56U];
  61. __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */
  62. uint32_t RESERVED5[644U];
  63. __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */
  64. } NVIC_Type;
  65. #define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */
  66. #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
  67. /**
  68. \brief Structure type to access the System Control Block (SCB).
  69. */
  70. typedef struct {
  71. __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
  72. __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
  73. __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
  74. __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
  75. __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
  76. __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
  77. __IOM uint8_t SHP[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */
  78. __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
  79. __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */
  80. __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */
  81. __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */
  82. __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */
  83. __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */
  84. __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */
  85. __IM uint32_t PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */
  86. __IM uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */
  87. __IM uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */
  88. __IM uint32_t MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */
  89. __IM uint32_t ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */
  90. uint32_t RESERVED0[5U];
  91. __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */
  92. } SCB_Type;
  93. /* SCB System Handler Control and State Register Definitions */
  94. #define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */
  95. #define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */
  96. #define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */
  97. #define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */
  98. #define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */
  99. #define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */
  100. #define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */
  101. #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
  102. #define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */
  103. #define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */
  104. #define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */
  105. #define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */
  106. #define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */
  107. #define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */
  108. #define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */
  109. #define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */
  110. #define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */
  111. #define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */
  112. #define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */
  113. #define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */
  114. #define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */
  115. #define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */
  116. #define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */
  117. #define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */
  118. #define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */
  119. #define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */
  120. #define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */
  121. #define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */
  122. /**
  123. \brief Structure type to access the Data Watchpoint and Trace Register (DWT).
  124. */
  125. typedef struct {
  126. __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
  127. __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
  128. __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */
  129. __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */
  130. __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */
  131. __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */
  132. __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */
  133. __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */
  134. __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */
  135. __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */
  136. __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */
  137. uint32_t RESERVED0[1U];
  138. __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */
  139. __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */
  140. __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */
  141. uint32_t RESERVED1[1U];
  142. __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */
  143. __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */
  144. __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */
  145. uint32_t RESERVED2[1U];
  146. __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */
  147. __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */
  148. __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */
  149. } DWT_Type;
  150. /**
  151. \brief Structure type to access the Memory Protection Unit (MPU).
  152. */
  153. typedef struct {
  154. __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
  155. __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
  156. __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
  157. __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
  158. __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
  159. __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */
  160. __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */
  161. __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */
  162. __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */
  163. __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */
  164. __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
  165. } MPU_Type;
  166. /**
  167. \brief Structure type to access the Core Debug Register (CoreDebug).
  168. */
  169. typedef struct {
  170. __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */
  171. __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */
  172. __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */
  173. __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */
  174. } CoreDebug_Type;
  175. STATIC_INLINE uint32_t __get_CONTROL(void)
  176. {
  177. uint32_t tmp;
  178. __asm__ volatile("mrs\t%0, CONTROL\n":"=r" (tmp));
  179. return tmp;
  180. }
  181. STATIC_INLINE void __set_CONTROL(uint32_t tmp)
  182. {
  183. __asm__ volatile("msr\tCONTROL, %0\n"::"r" (tmp));
  184. }
  185. STATIC_INLINE void __set_MSP(uint32_t tmp)
  186. {
  187. __asm__ volatile("msr\tMSP, %0\n"::"r" (tmp));
  188. }
  189. /**
  190. \brief Set Interrupt Priority
  191. \details Sets the priority of a device specific interrupt or a processor exception.
  192. The interrupt number can be positive to specify a device specific interrupt,
  193. or negative to specify a processor exception.
  194. \param [in] IRQn Interrupt number.
  195. \param [in] priority Priority to set.
  196. \note The priority cannot be set for every processor exception.
  197. */
  198. STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
  199. {
  200. if ((int32_t)(IRQn) >= 0)
  201. {
  202. NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
  203. }
  204. else
  205. {
  206. SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
  207. }
  208. }
  209. STATIC_INLINE void __WFI(void)
  210. {
  211. __asm__ volatile("wfi");
  212. }
  213. STATIC_INLINE void __BKPT(uint8_t n)
  214. {
  215. __asm__ volatile("bkpt %0" : : "i" (n & 0xFF));
  216. }
  217. STATIC_INLINE void __disable_irq(void)
  218. {
  219. __asm__ volatile ("cpsid i" : : : "memory");
  220. }
  221. STATIC_INLINE void __enable_irq(void)
  222. {
  223. __asm__ volatile("cpsie i" : : : "memory");
  224. }
  225. #ifdef __cplusplus
  226. }
  227. #endif
  228. #endif /* __UCMSIS_H__ */