core_801.h 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. /*
  2. * Copyright (C) 2017-2019 Alibaba Group Holding Limited
  3. */
  4. /******************************************************************************
  5. * @file core_801.h
  6. * @brief CSI 801 Core Peripheral Access Layer Header File
  7. * @version V1.0
  8. * @date 02. June 2017
  9. ******************************************************************************/
  10. #ifndef __CORE_801_H_GENERIC
  11. #define __CORE_801_H_GENERIC
  12. #include <stdint.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /*******************************************************************************
  17. * CSI definitions
  18. ******************************************************************************/
  19. /**
  20. \ingroup Ck801
  21. @{
  22. */
  23. /* CSI CK801 definitions */
  24. #define __CK801_CSI_VERSION_MAIN (0x04U) /*!< [31:16] CSI HAL main version */
  25. #define __CK801_CSI_VERSION_SUB (0x1EU) /*!< [15:0] CSI HAL sub version */
  26. #define __CK801_CSI_VERSION ((__CK801_CSI_VERSION_MAIN << 16U) | \
  27. __CK801_CSI_VERSION_SUB ) /*!< CSI HAL version number */
  28. #ifndef __CK80X
  29. #define __CK80X (0x01U) /*!< CK80X Core */
  30. #endif
  31. /** __FPU_USED indicates whether an FPU is used or not.
  32. This core does not support an FPU at all
  33. */
  34. #define __FPU_USED 0U
  35. #if defined ( __GNUC__ )
  36. #if defined (__VFP_FP__) && !defined(__SOFTFP__)
  37. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  38. #endif
  39. #endif
  40. #ifdef __cplusplus
  41. }
  42. #endif
  43. #endif /* __CORE_CK801_H_GENERIC */
  44. #ifndef __CSI_GENERIC
  45. #ifndef __CORE_CK801_H_DEPENDANT
  46. #define __CORE_CK801_H_DEPENDANT
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /* check device defines and use defaults */
  51. #ifndef __CK801_REV
  52. #define __CK801_REV 0x0000U
  53. #endif
  54. #ifndef __VIC_PRIO_BITS
  55. #define __VIC_PRIO_BITS 2U
  56. #endif
  57. #ifndef __Vendor_SysTickConfig
  58. #define __Vendor_SysTickConfig 1U
  59. #endif
  60. #ifndef __GSR_GCR_PRESENT
  61. #define __GSR_GCR_PRESENT 0U
  62. #endif
  63. #ifndef __MPU_PRESENT
  64. #define __MPU_PRESENT 1U
  65. #endif
  66. #include <core/csi_gcc.h>
  67. /* IO definitions (access restrictions to peripheral registers) */
  68. /**
  69. \defgroup CSI_glob_defs CSI Global Defines
  70. <strong>IO Type Qualifiers</strong> are used
  71. \li to specify the access to peripheral variables.
  72. \li for automatic generation of peripheral register debug information.
  73. */
  74. #ifdef __cplusplus
  75. #define __I volatile /*!< Defines 'read only' permissions */
  76. #else
  77. #define __I volatile const /*!< Defines 'read only' permissions */
  78. #endif
  79. #define __O volatile /*!< Defines 'write only' permissions */
  80. #define __IO volatile /*!< Defines 'read / write' permissions */
  81. /* following defines should be used for structure members */
  82. #define __IM volatile const /*! Defines 'read only' structure member permissions */
  83. #define __OM volatile /*! Defines 'write only' structure member permissions */
  84. #define __IOM volatile /*! Defines 'read / write' structure member permissions */
  85. /*@} end of group CK801 */
  86. /*******************************************************************************
  87. * Register Abstraction
  88. Core Register contain:
  89. - Core Register
  90. - Core VIC Register
  91. - Core Cache Register
  92. - Core CoreTIM Register
  93. ******************************************************************************/
  94. /**
  95. \defgroup CSI_core_register Defines and Type Definitions
  96. \brief Type definitions and defines for CK80X processor based devices.
  97. */
  98. /**
  99. \ingroup CSI_core_register
  100. \defgroup CSI_CORE Status and Control Registers
  101. \brief Core Register type definitions.
  102. @{
  103. */
  104. /**
  105. \brief Access Processor Status Register(PSR)struct definition.
  106. */
  107. typedef union {
  108. struct {
  109. uint32_t C: 1; /*!< bit: 0 Conditional code/Carry flag */
  110. uint32_t _reserved0: 5; /*!< bit: 2.. 5 Reserved */
  111. uint32_t IE: 1; /*!< bit: 6 Interrupt effective control bit */
  112. uint32_t IC: 1; /*!< bit: 7 Interrupt control bit */
  113. uint32_t EE: 1; /*!< bit: 8 Abnormally effective control bit */
  114. uint32_t MM: 1; /*!< bit: 9 Unsymmetrical masking bit */
  115. uint32_t _reserved1: 6; /*!< bit: 10..15 Reserved */
  116. uint32_t VEC: 8; /*!< bit: 16..23 Abnormal event vector value */
  117. uint32_t _reserved2: 7; /*!< bit: 24..30 Reserved */
  118. uint32_t S: 1; /*!< bit: 31 Superuser mode set bit */
  119. } b; /*!< Structure Access by bit */
  120. uint32_t w; /*!< Type Access by whole register */
  121. } PSR_Type;
  122. /* PSR Register Definitions */
  123. #define PSR_S_Pos 31U /*!< PSR: S Position */
  124. #define PSR_S_Msk (1UL << PSR_S_Pos) /*!< PSR: S Mask */
  125. #define PSR_VEC_Pos 16U /*!< PSR: VEC Position */
  126. #define PSR_VEC_Msk (0x7FUL << PSR_VEC_Pos) /*!< PSR: VEC Mask */
  127. #define PSR_MM_Pos 9U /*!< PSR: MM Position */
  128. #define PSR_MM_Msk (1UL << PSR_MM_Pos) /*!< PSR: MM Mask */
  129. #define PSR_EE_Pos 8U /*!< PSR: EE Position */
  130. #define PSR_EE_Msk (1UL << PSR_EE_Pos) /*!< PSR: EE Mask */
  131. #define PSR_IC_Pos 7U /*!< PSR: IC Position */
  132. #define PSR_IC_Msk (1UL << PSR_IC_Pos) /*!< PSR: IC Mask */
  133. #define PSR_IE_Pos 6U /*!< PSR: IE Position */
  134. #define PSR_IE_Msk (1UL << PSR_IE_Pos) /*!< PSR: IE Mask */
  135. #define PSR_C_Pos 0U /*!< PSR: C Position */
  136. #define PSR_C_Msk (1UL << PSR_C_Pos) /*!< PSR: C Mask */
  137. /**
  138. \brief Consortium definition for accessing Cache Configuration Registers(CCR, CR<18, 0>).
  139. */
  140. typedef union {
  141. struct {
  142. uint32_t MP: 1; /*!< bit: 0 memory protection settings */
  143. uint32_t _reserved0: 6; /*!< bit: 1.. 6 Reserved */
  144. uint32_t BE: 1; /*!< bit: 7 Endian mode */
  145. uint32_t SCK: 3; /*!< bit: 8..10 the clock ratio of the system and the processor */
  146. uint32_t _reserved1: 2; /*!< bit: 11..12 Reserved */
  147. uint32_t BE_V2: 1; /*!< bit: 13 V2 Endian mode */
  148. uint32_t _reserved2: 18; /*!< bit: 14..31 Reserved */
  149. } b; /*!< Structure Access by bit */
  150. uint32_t w; /*!< Type Access by whole register */
  151. } CCR_Type;
  152. /* CCR Register Definitions */
  153. #define CCR_BE_V2_Pos 13U /*!< CCR: BE_V2 Position */
  154. #define CCR_BE_V2_Msk (0x1UL << CCR_ISR_Pos) /*!< CCR: BE_V2 Mask */
  155. #define CCR_SCK_Pos 8U /*!< CCR: SCK Position */
  156. #define CCR_SCK_Msk (0x3UL << CCR_SCK_Pos) /*!< CCR: SCK Mask */
  157. #define CCR_BE_Pos 7U /*!< CCR: BE Position */
  158. #define CCR_BE_Msk (0x1UL << CCR_BE_Pos) /*!< CCR: BE Mask */
  159. #define CCR_MP_Pos 0U /*!< CCR: MP Position */
  160. #define CCR_MP_Msk (0x1UL << CCR_MP_Pos) /*!< CCR: MP Mask */
  161. /**
  162. \brief Consortium definition for accessing high ease access permission configutation registers(CAPR, CR<19,0>)
  163. */
  164. typedef union {
  165. struct {
  166. uint32_t X0: 1; /*!< bit: 0 Non executable attribute setting */
  167. uint32_t X1: 1; /*!< bit: 1 Non executable attribute setting */
  168. uint32_t X2: 1; /*!< bit: 2 Non executable attribute setting */
  169. uint32_t X3: 1; /*!< bit: 3 Non executable attribute setting */
  170. uint32_t X4: 1; /*!< bit: 4 Non executable attribute setting */
  171. uint32_t X5: 1; /*!< bit: 5 Non executable attribute setting */
  172. uint32_t X6: 1; /*!< bit: 6 Non executable attribute setting */
  173. uint32_t X7: 1; /*!< bit: 7 Non executable attribute setting */
  174. uint32_t AP0: 2; /*!< bit: 8.. 9 access permissions settings bit */
  175. uint32_t AP1: 2; /*!< bit: 10..11 access permissions settings bit */
  176. uint32_t AP2: 2; /*!< bit: 12..13 access permissions settings bit */
  177. uint32_t AP3: 2; /*!< bit: 14..15 access permissions settings bit */
  178. uint32_t AP4: 2; /*!< bit: 16..17 access permissions settings bit */
  179. uint32_t AP5: 2; /*!< bit: 18..19 access permissions settings bit */
  180. uint32_t AP6: 2; /*!< bit: 20..21 access permissions settings bit */
  181. uint32_t AP7: 2; /*!< bit: 22..23 access permissions settings bit */
  182. uint32_t S0: 1; /*!< bit: 24 Security property settings */
  183. uint32_t S1: 1; /*!< bit: 25 Security property settings */
  184. uint32_t S2: 1; /*!< bit: 26 Security property settings */
  185. uint32_t S3: 1; /*!< bit: 27 Security property settings */
  186. uint32_t S4: 1; /*!< bit: 28 Security property settings */
  187. uint32_t S5: 1; /*!< bit: 29 Security property settings */
  188. uint32_t S6: 1; /*!< bit: 30 Security property settings */
  189. uint32_t S7: 1; /*!< bit: 31 Security property settings */
  190. } b; /*!< Structure Access by bit */
  191. uint32_t w; /*!< Type Access by whole register */
  192. } CAPR_Type;
  193. /* CAPR Register Definitions */
  194. #define CAPR_S7_Pos 31U /*!< CAPR: S7 Position */
  195. #define CAPR_S7_Msk (1UL << CAPR_S7_Pos) /*!< CAPR: S7 Mask */
  196. #define CAPR_S6_Pos 30U /*!< CAPR: S6 Position */
  197. #define CAPR_S6_Msk (1UL << CAPR_S6_Pos) /*!< CAPR: S6 Mask */
  198. #define CAPR_S5_Pos 29U /*!< CAPR: S5 Position */
  199. #define CAPR_S5_Msk (1UL << CAPR_S5_Pos) /*!< CAPR: S5 Mask */
  200. #define CAPR_S4_Pos 28U /*!< CAPR: S4 Position */
  201. #define CAPR_S4_Msk (1UL << CAPR_S4_Pos) /*!< CAPR: S4 Mask */
  202. #define CAPR_S3_Pos 27U /*!< CAPR: S3 Position */
  203. #define CAPR_S3_Msk (1UL << CAPR_S3_Pos) /*!< CAPR: S3 Mask */
  204. #define CAPR_S2_Pos 26U /*!< CAPR: S2 Position */
  205. #define CAPR_S2_Msk (1UL << CAPR_S2_Pos) /*!< CAPR: S2 Mask */
  206. #define CAPR_S1_Pos 25U /*!< CAPR: S1 Position */
  207. #define CAPR_S1_Msk (1UL << CAPR_S1_Pos) /*!< CAPR: S1 Mask */
  208. #define CAPR_S0_Pos 24U /*!< CAPR: S0 Position */
  209. #define CAPR_S0_Msk (1UL << CAPR_S0_Pos) /*!< CAPR: S0 Mask */
  210. #define CAPR_AP7_Pos 22U /*!< CAPR: AP7 Position */
  211. #define CAPR_AP7_Msk (0x3UL << CAPR_AP7_Pos) /*!< CAPR: AP7 Mask */
  212. #define CAPR_AP6_Pos 20U /*!< CAPR: AP6 Position */
  213. #define CAPR_AP6_Msk (0x3UL << CAPR_AP6_Pos) /*!< CAPR: AP6 Mask */
  214. #define CAPR_AP5_Pos 18U /*!< CAPR: AP5 Position */
  215. #define CAPR_AP5_Msk (0x3UL << CAPR_AP5_Pos) /*!< CAPR: AP5 Mask */
  216. #define CAPR_AP4_Pos 16U /*!< CAPR: AP4 Position */
  217. #define CAPR_AP4_Msk (0x3UL << CAPR_AP4_Pos) /*!< CAPR: AP4 Mask */
  218. #define CAPR_AP3_Pos 14U /*!< CAPR: AP3 Position */
  219. #define CAPR_AP3_Msk (0x3UL << CAPR_AP3_Pos) /*!< CAPR: AP3 Mask */
  220. #define CAPR_AP2_Pos 12U /*!< CAPR: AP2 Position */
  221. #define CAPR_AP2_Msk (0x3UL << CAPR_AP2_Pos) /*!< CAPR: AP2 Mask */
  222. #define CAPR_AP1_Pos 10U /*!< CAPR: AP1 Position */
  223. #define CAPR_AP1_Msk (0x3UL << CAPR_AP1_Pos) /*!< CAPR: AP1 Mask */
  224. #define CAPR_AP0_Pos 8U /*!< CAPR: AP0 Position */
  225. #define CAPR_AP0_Msk (0x3UL << CAPR_AP0_Pos) /*!< CAPR: AP0 Mask */
  226. #define CAPR_X7_Pos 7U /*!< CAPR: X7 Position */
  227. #define CAPR_X7_Msk (0x1UL << CAPR_X7_Pos) /*!< CAPR: X7 Mask */
  228. #define CAPR_X6_Pos 6U /*!< CAPR: X6 Position */
  229. #define CAPR_X6_Msk (0x1UL << CAPR_X6_Pos) /*!< CAPR: X6 Mask */
  230. #define CAPR_X5_Pos 5U /*!< CAPR: X5 Position */
  231. #define CAPR_X5_Msk (0x1UL << CAPR_X5_Pos) /*!< CAPR: X5 Mask */
  232. #define CAPR_X4_Pos 4U /*!< CAPR: X4 Position */
  233. #define CAPR_X4_Msk (0x1UL << CAPR_X4_Pos) /*!< CAPR: X4 Mask */
  234. #define CAPR_X3_Pos 3U /*!< CAPR: X3 Position */
  235. #define CAPR_X3_Msk (0x1UL << CAPR_X3_Pos) /*!< CAPR: X3 Mask */
  236. #define CAPR_X2_Pos 2U /*!< CAPR: X2 Position */
  237. #define CAPR_X2_Msk (0x1UL << CAPR_X2_Pos) /*!< CAPR: X2 Mask */
  238. #define CAPR_X1_Pos 1U /*!< CAPR: X1 Position */
  239. #define CAPR_X1_Msk (0x1UL << CAPR_X1_Pos) /*!< CAPR: X1 Mask */
  240. #define CAPR_X0_Pos 0U /*!< CAPR: X0 Position */
  241. #define CAPR_X0_Msk (0x1UL << CAPR_X0_Pos) /*!< CAPR: X0 Mask */
  242. /**
  243. \brief Consortium definition for accessing control register(PACR, CR<20,0>).
  244. */
  245. typedef union {
  246. struct {
  247. uint32_t E: 1; /*!< bit: 0 Effective setting of protected area */
  248. uint32_t Size: 5; /*!< bit: 1.. 5 Size of protected area */
  249. uint32_t _reserved0: 1; /*!< bit: 6 Reserved */
  250. uint32_t base_addr: 25; /*!< bit: 7..31 The high position of the address of a protected area */
  251. } b; /*!< Structure Access by bit */
  252. uint32_t w; /*!< Type Access by whole register */
  253. } PACR_Type;
  254. /* PACR Register Definitions */
  255. #define PACR_BASE_ADDR_Pos 7U /*!< PACR: base_addr Position */
  256. #define PACR_BASE_ADDR_Msk (0x1FFFFFFUL << PACR_BASE_ADDR_Pos) /*!< PACR: base_addr Mask */
  257. #define PACR_SIZE_Pos 1U /*!< PACR: Size Position */
  258. #define PACR_SIZE_Msk (0x1FUL << PACR_SIZE_Pos) /*!< PACR: Size Mask */
  259. #define PACR_E_Pos 0U /*!< PACR: E Position */
  260. #define PACR_E_Msk (0x1UL << PACR_E_Pos) /*!< PACR: E Mask */
  261. /**
  262. \brief Consortium definition for accessing protection area selection register(PRSR,CR<21,0>).
  263. */
  264. typedef union {
  265. struct {
  266. uint32_t RID: 3; /*!< bit: 0.. 2 Protected area index value */
  267. uint32_t _reserved0: 29; /*!< bit: 3..31 Reserved */
  268. } b; /*!< Structure Access by bit */
  269. uint32_t w; /*!< Type Access by whole register */
  270. } PRSR_Type;
  271. /* PRSR Register Definitions */
  272. #define PRSR_RID_Pos 0U /*!< PRSR: RID Position */
  273. #define PRSR_RID_Msk (0x7UL << PRSR_RID_Pos) /*!< PRSR: RID Mask */
  274. /**
  275. \brief Consortium definition for CPU Hint Register(CHR, CR<31,0>).
  276. */
  277. typedef union {
  278. struct {
  279. uint32_t _reserved0: 4; /*!< bit: 0.. 3 Reserved */
  280. uint32_t IAE: 1; /*!< bit: 4 Interrupt response acceleration enable */
  281. uint32_t _reserved1: 11; /*!< bit: 5..15 Reserved */
  282. uint32_t SRST_VAL: 16; /*!< bit: 16..31 Software reset decision value */
  283. } b;
  284. uint32_t w;
  285. } CHR_Type;
  286. /* CHR Register Definitions */
  287. #define CHR_IAE_Pos 4U /*!< CHR: IAE Position */
  288. #define CHR_IAE_Msk (0x1UL << CHR_IAE_Pos) /*!< CHR: IAE Mask */
  289. #define CHR_SRST_VAL_Pos 16U /*!< CHR: SRST_VAL Position */
  290. #define CHR_SRST_VAL_Mask (0xFFFFUL << CHR_SRST_VAL_Pos) /*!< CHR: SRST_VAL Mask */
  291. /*@} end of group CSI_CORE */
  292. /**
  293. \ingroup CSI_core_register
  294. \defgroup CSI_VIC Vectored Interrupt Controller (VIC)
  295. \brief Type definitions for the VIC Registers
  296. @{
  297. */
  298. /**
  299. \brief Access to the structure of a vector interrupt controller.
  300. */
  301. typedef struct {
  302. __IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt set enable register */
  303. uint32_t RESERVED0[15U];
  304. __IOM uint32_t IWER[1U]; /*!< Offset: 0x040 (R/W) Interrupt wake-up set register */
  305. uint32_t RESERVED1[15U];
  306. __IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt clear enable register */
  307. uint32_t RESERVED2[15U];
  308. __IOM uint32_t IWDR[1U]; /*!< Offset: 0x0c0 (R/W) Interrupt wake-up clear register */
  309. uint32_t RESERVED3[15U];
  310. __IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt set pend register */
  311. uint32_t RESERVED4[15U];
  312. __IOM uint32_t ISSR[1U]; /*!< Offset: 0x140 (R/W) Security interrupt set register */
  313. uint32_t RESERVED5[15U];
  314. __IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt clear pend register */
  315. uint32_t RESERVED6[15U];
  316. __IOM uint32_t ICSR[1U]; /*!< Offset: 0x1c0 (R/W) Security interrupt clear register */
  317. uint32_t RESERVED7[15U];
  318. __IOM uint32_t IABR[1U]; /*!< Offset: 0x200 (R/W) Interrupt answer stateregister */
  319. uint32_t RESERVED8[63U];
  320. __IOM uint32_t IPR[8U]; /*!< Offset: 0x300 (R/W) Interrupt priority register */
  321. uint32_t RESERVED9[504U];
  322. __IM uint32_t ISR; /*!< Offset: 0xB00 (R/ ) Interrupt state register */
  323. __IOM uint32_t IPTR; /*!< Offset: 0xB04 (R/W) Interrupt priority thershold register */
  324. } VIC_Type;
  325. /*@} end of group CSI_VIC */
  326. /**
  327. \ingroup CSI_core_register
  328. \defgroup CSI_SysTick System Tick Timer (CORET)
  329. \brief Type definitions for the System Timer Registers.
  330. @{
  331. */
  332. /**
  333. \brief The data structure of the access system timer.
  334. */
  335. typedef struct {
  336. __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control register */
  337. __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) Backfill register */
  338. __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) Current register */
  339. __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) Calibration register */
  340. } CORET_Type;
  341. /* CORET Control / Status Register Definitions */
  342. #define CORET_CTRL_COUNTFLAG_Pos 16U /*!< CORET CTRL: COUNTFLAG Position */
  343. #define CORET_CTRL_COUNTFLAG_Msk (1UL << CORET_CTRL_COUNTFLAG_Pos) /*!< CORET CTRL: COUNTFLAG Mask */
  344. #define CORET_CTRL_CLKSOURCE_Pos 2U /*!< CORET CTRL: CLKSOURCE Position */
  345. #define CORET_CTRL_CLKSOURCE_Msk (1UL << CORET_CTRL_CLKSOURCE_Pos) /*!< CORET CTRL: CLKSOURCE Mask */
  346. #define CORET_CTRL_TICKINT_Pos 1U /*!< CORET CTRL: TICKINT Position */
  347. #define CORET_CTRL_TICKINT_Msk (1UL << CORET_CTRL_TICKINT_Pos) /*!< CORET CTRL: TICKINT Mask */
  348. #define CORET_CTRL_ENABLE_Pos 0U /*!< CORET CTRL: ENABLE Position */
  349. #define CORET_CTRL_ENABLE_Msk (1UL /*<< CORET_CTRL_ENABLE_Pos*/) /*!< CORET CTRL: ENABLE Mask */
  350. /* CORET Reload Register Definitions */
  351. #define CORET_LOAD_RELOAD_Pos 0U /*!< CORET LOAD: RELOAD Position */
  352. #define CORET_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< CORET_LOAD_RELOAD_Pos*/) /*!< CORET LOAD: RELOAD Mask */
  353. /* CORET Current Register Definitions */
  354. #define CORET_VAL_CURRENT_Pos 0U /*!< CORET VAL: CURRENT Position */
  355. #define CORET_VAL_CURRENT_Msk (0xFFFFFFUL /*<< CORET_VAL_CURRENT_Pos*/) /*!< CORET VAL: CURRENT Mask */
  356. /* CORET Calibration Register Definitions */
  357. #define CORET_CALIB_NOREF_Pos 31U /*!< CORET CALIB: NOREF Position */
  358. #define CORET_CALIB_NOREF_Msk (1UL << CORET_CALIB_NOREF_Pos) /*!< CORET CALIB: NOREF Mask */
  359. #define CORET_CALIB_SKEW_Pos 30U /*!< CORET CALIB: SKEW Position */
  360. #define CORET_CALIB_SKEW_Msk (1UL << CORET_CALIB_SKEW_Pos) /*!< CORET CALIB: SKEW Mask */
  361. #define CORET_CALIB_TENMS_Pos 0U /*!< CORET CALIB: TENMS Position */
  362. #define CORET_CALIB_TENMS_Msk (0xFFFFFFUL /*<< CORET_CALIB_TENMS_Pos*/) /*!< CORET CALIB: TENMS Mask */
  363. /*@} end of group CSI_SysTick */
  364. /**
  365. \ingroup CSI_core_register
  366. \defgroup CSI_DCC
  367. \brief Type definitions for the DCC.
  368. @{
  369. */
  370. /**
  371. \brief Access to the data structure of DCC.
  372. */
  373. typedef struct {
  374. uint32_t RESERVED0[13U];
  375. __IOM uint32_t HCR; /*!< Offset: 0x034 (R/W) */
  376. __IM uint32_t EHSR; /*!< Offset: 0x03C (R/ ) */
  377. uint32_t RESERVED1[6U];
  378. union {
  379. __IM uint32_t DERJW; /*!< Offset: 0x058 (R/ ) Data exchange register CPU read*/
  380. __OM uint32_t DERJR; /*!< Offset: 0x058 ( /W) Data exchange register CPU writer*/
  381. };
  382. } DCC_Type;
  383. #define DCC_HCR_JW_Pos 18U /*!< DCC HCR: jw_int_en Position */
  384. #define DCC_HCR_JW_Msk (1UL << DCC_HCR_JW_Pos) /*!< DCC HCR: jw_int_en Mask */
  385. #define DCC_HCR_JR_Pos 19U /*!< DCC HCR: jr_int_en Position */
  386. #define DCC_HCR_JR_Msk (1UL << DCC_HCR_JR_Pos) /*!< DCC HCR: jr_int_en Mask */
  387. #define DCC_EHSR_JW_Pos 1U /*!< DCC EHSR: jw_vld Position */
  388. #define DCC_EHSR_JW_Msk (1UL << DCC_EHSR_JW_Pos) /*!< DCC EHSR: jw_vld Mask */
  389. #define DCC_EHSR_JR_Pos 2U /*!< DCC EHSR: jr_vld Position */
  390. #define DCC_EHSR_JR_Msk (1UL << DCC_EHSR_JR_Pos) /*!< DCC EHSR: jr_vld Mask */
  391. /*@} end of group CSI_DCC */
  392. /**
  393. \ingroup CSI_core_register
  394. \defgroup CSI_core_bitfield Core register bit field macros
  395. \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
  396. @{
  397. */
  398. /**
  399. \brief Mask and shift a bit field value for use in a register bit range.
  400. \param[in] field Name of the register bit field.
  401. \param[in] value Value of the bit field.
  402. \return Masked and shifted value.
  403. */
  404. #define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
  405. /**
  406. \brief Mask and shift a register value to extract a bit filed value.
  407. \param[in] field Name of the register bit field.
  408. \param[in] value Value of register.
  409. \return Masked and shifted bit field value.
  410. */
  411. #define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
  412. /*@} end of group CSI_core_bitfield */
  413. /**
  414. \ingroup CSI_core_register
  415. \defgroup CSI_core_base Core Definitions
  416. \brief Definitions for base addresses, unions, and structures.
  417. @{
  418. */
  419. /* Memory mapping of CK801 Hardware */
  420. #define TCIP_BASE (0xE000E000UL) /*!< Titly Coupled IP Base Address */
  421. #define CORET_BASE (TCIP_BASE + 0x0010UL) /*!< CORET Base Address */
  422. #define VIC_BASE (TCIP_BASE + 0x0100UL) /*!< VIC Base Address */
  423. #define DCC_BASE (0xE0011000UL) /*!< DCC Base Address */
  424. #define CORET ((CORET_Type *) CORET_BASE ) /*!< SysTick configuration struct */
  425. #define VIC ((VIC_Type *) VIC_BASE ) /*!< VIC configuration struct */
  426. #define DCC ((DCC_Type *) DCC_BASE ) /*!< DCC configuration struct */
  427. /*@} */
  428. /*******************************************************************************
  429. * Hardware Abstraction Layer
  430. Core Function Interface contains:
  431. - Core VIC Functions
  432. - Core CORET Functions
  433. - Core Register Access Functions
  434. ******************************************************************************/
  435. /**
  436. \defgroup CSI_Core_FunctionInterface Functions and Instructions Reference
  437. */
  438. /* ########################## VIC functions #################################### */
  439. /**
  440. \ingroup CSI_Core_FunctionInterface
  441. \defgroup CSI_Core_VICFunctions VIC Functions
  442. \brief Functions that manage interrupts and exceptions via the VIC.
  443. @{
  444. */
  445. /* The following MACROS handle generation of the register offset and byte masks */
  446. #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
  447. #define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
  448. /**
  449. \brief Enable External Interrupt
  450. \details Enable a device-specific interrupt in the VIC interrupt controller.
  451. \param [in] IRQn External interrupt number. Value cannot be negative.
  452. */
  453. __STATIC_INLINE void csi_vic_enable_irq(int32_t IRQn)
  454. {
  455. VIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  456. }
  457. /**
  458. \brief Disable External Interrupt
  459. \details Disable a device-specific interrupt in the VIC interrupt controller.
  460. \param [in] IRQn External interrupt number. Value cannot be negative.
  461. */
  462. __STATIC_INLINE void csi_vic_disable_irq(int32_t IRQn)
  463. {
  464. VIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  465. }
  466. /**
  467. \brief Enable External Secure Interrupt
  468. \details Enable a secure device-specific interrupt in the VIC interrupt controller.
  469. \param [in] IRQn External interrupt number. Value cannot be negative.
  470. */
  471. __STATIC_INLINE void csi_vic_enable_sirq(int32_t IRQn)
  472. {
  473. VIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  474. VIC->ISSR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  475. }
  476. /**
  477. \brief Disable External Secure Interrupt
  478. \details Disable a secure device-specific interrupt in the VIC interrupt controller.
  479. \param [in] IRQn External interrupt number. Value cannot be negative.
  480. */
  481. __STATIC_INLINE void csi_vic_disable_sirq(int32_t IRQn)
  482. {
  483. VIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  484. VIC->ICSR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  485. }
  486. /**
  487. \brief Check Interrupt is Enabled or not
  488. \details Read the enabled register in the VIC and returns the pending bit for the specified interrupt.
  489. \param [in] IRQn Interrupt number.
  490. \return Interrput status is enabled.
  491. */
  492. __STATIC_INLINE uint32_t csi_vic_get_enabled_irq(int32_t IRQn)
  493. {
  494. return ((uint32_t)(((VIC->ISER[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
  495. }
  496. /**
  497. \brief Check Interrupt is Pending or not
  498. \details Read the pending register in the VIC and returns the pending bit for the specified interrupt.
  499. \param [in] IRQn Interrupt number.
  500. \return 0 Interrupt status is not pending.
  501. \return 1 Interrupt status is pending.
  502. */
  503. __STATIC_INLINE uint32_t csi_vic_get_pending_irq(int32_t IRQn)
  504. {
  505. return ((uint32_t)(((VIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
  506. }
  507. /**
  508. \brief Set Pending Interrupt
  509. \details Set the pending bit of an external interrupt.
  510. \param [in] IRQn Interrupt number. Value cannot be negative.
  511. */
  512. __STATIC_INLINE void csi_vic_set_pending_irq(int32_t IRQn)
  513. {
  514. VIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  515. }
  516. /**
  517. \brief Clear Pending Interrupt
  518. \details Clear the pending bit of an external interrupt.
  519. \param [in] IRQn External interrupt number. Value cannot be negative.
  520. */
  521. __STATIC_INLINE void csi_vic_clear_pending_irq(int32_t IRQn)
  522. {
  523. VIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  524. }
  525. /**
  526. \brief Check Interrupt is Wakeup or not
  527. \details Read the wake up register in the VIC and returns the pending bit for the specified interrupt.
  528. \param [in] IRQn Interrupt number.
  529. \return 0 Interrupt is not set as wake up interrupt.
  530. \return 1 Interrupt is set as wake up interrupt.
  531. */
  532. __STATIC_INLINE uint32_t csi_vic_get_wakeup_irq(int32_t IRQn)
  533. {
  534. return ((uint32_t)(((VIC->IWER[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
  535. }
  536. /**
  537. \brief Set Wakeup Interrupt
  538. \details Set the wake up bit of an external interrupt.
  539. \param [in] IRQn Interrupt number. Value cannot be negative.
  540. */
  541. __STATIC_INLINE void csi_vic_set_wakeup_irq(int32_t IRQn)
  542. {
  543. VIC->IWER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  544. }
  545. /**
  546. \brief Clear Wake up Interrupt
  547. \details Clear the wake up bit of an external interrupt.
  548. \param [in] IRQn External interrupt number. Value cannot be negative.
  549. */
  550. __STATIC_INLINE void csi_vic_clear_wakeup_irq(int32_t IRQn)
  551. {
  552. VIC->IWDR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
  553. }
  554. /**
  555. \brief Get Interrupt is Active or not
  556. \details Read the active register in the VIC and returns the active bit for the device specific interrupt.
  557. \param [in] IRQn Device specific interrupt number.
  558. \return 0 Interrupt status is not active.
  559. \return 1 Interrupt status is active.
  560. \note IRQn must not be negative.
  561. */
  562. __STATIC_INLINE uint32_t csi_vic_get_active(int32_t IRQn)
  563. {
  564. return ((uint32_t)(((VIC->IABR[0] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
  565. }
  566. /**
  567. \brief Set Threshold register
  568. \details set the threshold register in the VIC.
  569. \param [in] VectThreshold specific vecter threshold.
  570. \param [in] PrioThreshold specific priority threshold.
  571. */
  572. __STATIC_INLINE void csi_vic_set_threshold(uint32_t VectThreshold, uint32_t PrioThreshold)
  573. {
  574. VIC->IPTR = 0x80000000 | (((VectThreshold + 32) & 0xFF) << 8) | ((PrioThreshold & 0x3) << 6);
  575. }
  576. /**
  577. \brief Set Interrupt Priority
  578. \details Set the priority of an interrupt.
  579. \note The priority cannot be set for every core interrupt.
  580. \param [in] IRQn Interrupt number.
  581. \param [in] priority Priority to set.
  582. */
  583. __STATIC_INLINE void csi_vic_set_prio(int32_t IRQn, uint32_t priority)
  584. {
  585. VIC->IPR[_IP_IDX(IRQn)] = ((uint32_t)(VIC->IPR[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
  586. (((priority << (8U - __VIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
  587. }
  588. /**
  589. \brief Get Interrupt Priority
  590. \details Read the priority of an interrupt.
  591. The interrupt number can be positive to specify an external (device specific) interrupt,
  592. or negative to specify an internal (core) interrupt.
  593. \param [in] IRQn Interrupt number.
  594. \return Interrupt Priority.
  595. Value is aligned automatically to the implemented priority bits of the microcontroller.
  596. */
  597. __STATIC_INLINE uint32_t csi_vic_get_prio(int32_t IRQn)
  598. {
  599. return ((uint32_t)(((VIC->IPR[_IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn)) & (uint32_t)0xFFUL) >> (8U - __VIC_PRIO_BITS)));
  600. }
  601. /**
  602. \brief Set interrupt handler
  603. \details Set the interrupt handler according to the interrupt num, the handler will be filled in irq vectors.
  604. \param [in] IRQn Interrupt number.
  605. \param [in] handler Interrupt handler.
  606. */
  607. __STATIC_INLINE void csi_vic_set_vector(int32_t IRQn, uint32_t handler)
  608. {
  609. if (IRQn >= 0 && IRQn < 32) {
  610. uint32_t *vectors = (uint32_t *)__get_VBR();
  611. vectors[32 + IRQn] = handler;
  612. }
  613. }
  614. /**
  615. \brief Get interrupt handler
  616. \details Get the address of interrupt handler function.
  617. \param [in] IRQn Interrupt number.
  618. */
  619. __STATIC_INLINE uint32_t csi_vic_get_vector(int32_t IRQn)
  620. {
  621. if (IRQn >= 0 && IRQn < 32) {
  622. uint32_t *vectors = (uint32_t *)__get_VBR();
  623. return (uint32_t)vectors[32 + IRQn];
  624. }
  625. return 0;
  626. }
  627. /*@} end of CSI_Core_VICFunctions */
  628. /* ################################## SysTick function ############################################ */
  629. /**
  630. \ingroup CSI_Core_FunctionInterface
  631. \defgroup CSI_Core_SysTickFunctions SysTick Functions
  632. \brief Functions that configure the System.
  633. @{
  634. */
  635. /**
  636. \brief CORE timer Configuration
  637. \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
  638. Counter is in free running mode to generate periodic interrupts.
  639. \param [in] ticks Number of ticks between two interrupts.
  640. \param [in] IRQn core timer Interrupt number.
  641. \return 0 Function succeeded.
  642. \return 1 Function failed.
  643. \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
  644. function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
  645. must contain a vendor-specific implementation of this function.
  646. */
  647. __STATIC_INLINE uint32_t csi_coret_config(uint32_t ticks, int32_t IRQn)
  648. {
  649. (void)IRQn;
  650. if ((ticks - 1UL) > CORET_LOAD_RELOAD_Msk) {
  651. return (1UL); /* Reload value impossible */
  652. }
  653. CORET->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
  654. CORET->VAL = 0UL; /* Load the CORET Counter Value */
  655. CORET->CTRL = CORET_CTRL_CLKSOURCE_Msk |
  656. CORET_CTRL_TICKINT_Msk |
  657. CORET_CTRL_ENABLE_Msk; /* Enable CORET IRQ and CORET Timer */
  658. return (0UL); /* Function successful */
  659. }
  660. /**
  661. \brief get CORE timer reload value
  662. \return CORE timer counter value.
  663. */
  664. __STATIC_INLINE uint32_t csi_coret_get_load(void)
  665. {
  666. return CORET->LOAD;
  667. }
  668. /**
  669. \brief get CORE timer counter value
  670. \return CORE timer counter value.
  671. */
  672. __STATIC_INLINE uint32_t csi_coret_get_value(void)
  673. {
  674. return CORET->VAL;
  675. }
  676. /**
  677. \brief clean CORE timer interrupt flag
  678. */
  679. __STATIC_INLINE void csi_coret_clear_irq(void)
  680. {
  681. CORET->CTRL;
  682. }
  683. /*@} end of CSI_Core_SysTickFunctions */
  684. /* ##################################### DCC function ########################################### */
  685. /**
  686. \ingroup CSI_Core_FunctionInterface
  687. \defgroup CSI_core_DebugFunctions HAD Functions
  688. \brief Functions that access the HAD debug interface.
  689. @{
  690. */
  691. /**
  692. \brief HAD Send Character
  693. \details Transmits a character via the HAD channel 0, and
  694. \li Just returns when no debugger is connected that has booked the output.
  695. \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted.
  696. \param [in] ch Character to transmit.
  697. \returns Character to transmit.
  698. */
  699. __STATIC_INLINE uint32_t csi_had_send_char(uint32_t ch)
  700. {
  701. DCC->DERJR = (uint8_t)ch;
  702. return (ch);
  703. }
  704. /**
  705. \brief HAD Receive Character
  706. \details Inputs a character via the external variable \ref HAD_RxBuffer.
  707. \return Received character.
  708. \return -1 No character pending.
  709. */
  710. __STATIC_INLINE int32_t csi_had_receive_char(void)
  711. {
  712. int32_t ch = -1; /* no character available */
  713. if (_FLD2VAL(DCC_EHSR_JW, DCC->EHSR)) {
  714. ch = DCC->DERJW;
  715. }
  716. return (ch);
  717. }
  718. /**
  719. \brief HAD Check Character
  720. \details Check whether a character is pending for reading in the variable \ref HAD_RxBuffer.
  721. \return 0 No character available.
  722. \return 1 Character available.
  723. */
  724. __STATIC_INLINE int32_t csi_had_check_char(void)
  725. {
  726. return _FLD2VAL(DCC_EHSR_JW, DCC->EHSR); /* no character available */
  727. }
  728. /*@} end of CSI_core_DebugFunctions */
  729. /* ########################## MPU functions #################################### */
  730. /**
  731. \ingroup CSI_Core_FunctionInterface
  732. \defgroup CSI_Core_MPUFunctions MPU Functions
  733. \brief Functions that configure MPU.
  734. @{
  735. */
  736. typedef enum {
  737. REGION_SIZE_128B = 0x6,
  738. REGION_SIZE_256B = 0x7,
  739. REGION_SIZE_512B = 0x8,
  740. REGION_SIZE_1KB = 0x9,
  741. REGION_SIZE_2KB = 0xA,
  742. REGION_SIZE_4KB = 0xB,
  743. REGION_SIZE_8KB = 0xC,
  744. REGION_SIZE_16KB = 0xD,
  745. REGION_SIZE_32KB = 0xE,
  746. REGION_SIZE_64KB = 0xF,
  747. REGION_SIZE_128KB = 0x10,
  748. REGION_SIZE_256KB = 0x11,
  749. REGION_SIZE_512KB = 0x12,
  750. REGION_SIZE_1MB = 0x13,
  751. REGION_SIZE_2MB = 0x14,
  752. REGION_SIZE_4MB = 0x15,
  753. REGION_SIZE_8MB = 0x16,
  754. REGION_SIZE_16MB = 0x17,
  755. REGION_SIZE_32MB = 0x18,
  756. REGION_SIZE_64MB = 0x19,
  757. REGION_SIZE_128MB = 0x1A,
  758. REGION_SIZE_256MB = 0x1B,
  759. REGION_SIZE_512MB = 0x1C,
  760. REGION_SIZE_1GB = 0x1D,
  761. REGION_SIZE_2GB = 0x1E,
  762. REGION_SIZE_4GB = 0x1F
  763. } region_size_e;
  764. typedef enum {
  765. AP_BOTH_INACCESSIBLE = 0,
  766. AP_SUPER_RW_USER_INACCESSIBLE,
  767. AP_SUPER_RW_USER_RDONLY,
  768. AP_BOTH_RW
  769. } access_permission_e;
  770. typedef struct {
  771. uint32_t nx: 1; /* instruction fetched excution */
  772. access_permission_e ap: 2; /* super user and normal user access.*/
  773. uint32_t s: 1; /* security */
  774. } mpu_region_attr_t;
  775. /**
  776. \brief enable mpu
  777. \details
  778. */
  779. __STATIC_INLINE void csi_mpu_enable(void)
  780. {
  781. __set_CCR(__get_CCR() | CCR_MP_Msk);
  782. }
  783. /**
  784. \brief disable mpu
  785. \details
  786. */
  787. __STATIC_INLINE void csi_mpu_disable(void)
  788. {
  789. __set_CCR(__get_CCR() & (~CCR_MP_Msk));
  790. }
  791. /**
  792. \brief configure memory protected region.
  793. \details
  794. \param [in] idx memory protected region (0, 1, 2, ..., 7).
  795. \param [in] base_addr base address must be aligned with page size.
  796. \param [in] size \ref region_size_e. memory protected region size.
  797. \param [in] attr \ref region_size_t. memory protected region attribute.
  798. \param [in] enable enable or disable memory protected region.
  799. */
  800. __STATIC_INLINE void csi_mpu_config_region(uint32_t idx, uint32_t base_addr, region_size_e size,
  801. mpu_region_attr_t attr, uint32_t enable)
  802. {
  803. if (idx > 7) {
  804. return;
  805. }
  806. CAPR_Type capr;
  807. PACR_Type pacr;
  808. PRSR_Type prsr;
  809. capr.w = __get_CAPR();
  810. pacr.w = __get_PACR();
  811. prsr.w = __get_PRSR();
  812. pacr.b.base_addr = (base_addr >> PACR_BASE_ADDR_Pos) & (0x3FFFFFF);
  813. prsr.b.RID = idx;
  814. __set_PRSR(prsr.w);
  815. if (size != REGION_SIZE_128B) {
  816. pacr.w &= ~(((1u << (size -6)) - 1) << 7);
  817. }
  818. pacr.b.Size = size;
  819. capr.w &= ~((0x1 << idx) | (0x3 << (idx * 2 + 8)) | (0x1 << (idx + 24)));
  820. capr.w = (capr.w | (attr.nx << idx) | (attr.ap << (idx * 2 + 8)) | (attr.s << (idx + 24)));
  821. __set_CAPR(capr.w);
  822. pacr.b.E = enable;
  823. __set_PACR(pacr.w);
  824. }
  825. /**
  826. \brief enable mpu region by idx.
  827. \details
  828. \param [in] idx memory protected region (0, 1, 2, ..., 7).
  829. */
  830. __STATIC_INLINE void csi_mpu_enable_region(uint32_t idx)
  831. {
  832. if (idx > 7) {
  833. return;
  834. }
  835. __set_PRSR((__get_PRSR() & (~PRSR_RID_Msk)) | idx);
  836. __set_PACR(__get_PACR() | PACR_E_Msk);
  837. }
  838. /**
  839. \brief disable mpu region by idx.
  840. \details
  841. \param [in] idx memory protected region (0, 1, 2, ..., 7).
  842. */
  843. __STATIC_INLINE void csi_mpu_disable_region(uint32_t idx)
  844. {
  845. if (idx > 7) {
  846. return;
  847. }
  848. __set_PRSR((__get_PRSR() & (~PRSR_RID_Msk)) | idx);
  849. __set_PACR(__get_PACR() & (~PACR_E_Msk));
  850. }
  851. /*@} end of CSI_Core_MMUFunctions */
  852. /* ################################## IRQ Functions ############################################ */
  853. /**
  854. \brief Save the Irq context
  855. \details save the psr result before disable irq.
  856. \param [in] irq_num External interrupt number. Value cannot be negative.
  857. */
  858. __STATIC_INLINE uint32_t csi_irq_save(void)
  859. {
  860. uint32_t result;
  861. result = __get_PSR();
  862. __disable_irq();
  863. return(result);
  864. }
  865. /**
  866. \brief Restore the Irq context
  867. \details restore saved primask state.
  868. \param [in] irq_state psr irq state.
  869. */
  870. __STATIC_INLINE void csi_irq_restore(uint32_t irq_state)
  871. {
  872. __set_PSR(irq_state);
  873. }
  874. /*@} end of IRQ Functions */
  875. /**
  876. \brief System Reset
  877. \details Initiates a system reset request to reset the MCU.
  878. */
  879. __STATIC_INLINE void csi_system_reset(void)
  880. {
  881. CHR_Type chr;
  882. chr.w = __get_CHR();
  883. #ifdef __RESET_CONST
  884. chr.b.SRST_VAL = __RESET_CONST;
  885. #else
  886. chr.b.SRST_VAL = 0xABCD;
  887. #endif
  888. __DSB(); /* Ensure all outstanding memory accesses included
  889. buffered write are completed before reset */
  890. __set_CHR(chr.w);
  891. __DSB(); /* Ensure completion of memory access */
  892. for(;;) /* wait until reset */
  893. {
  894. __NOP();
  895. }
  896. }
  897. /* ################################## Old Interfaces ############################################ */
  898. /* These interfaces are deprecated */
  899. #define NVIC_EnableIRQ(IRQn) csi_vic_enable_irq(IRQn)
  900. #define NVIC_DisableIRQ(IRQn) csi_vic_disable_irq(IRQn)
  901. #define NVIC_GetPendingIRQ(IRQn) csi_vic_get_pending_irq(IRQn)
  902. #define NVIC_SetPendingIRQ(IRQn) csi_vic_set_pending_irq(IRQn)
  903. #define NVIC_ClearPendingIRQ(IRQn) csi_vic_clear_pending_irq(IRQn)
  904. #define NVIC_GetWakeupIRQ(IRQn) csi_vic_get_wakeup_irq(IRQn)
  905. #define NVIC_SetWakeupIRQ(IRQn) csi_vic_set_wakeup_irq(IRQn)
  906. #define NVIC_ClearWakeupIRQ(IRQn) csi_vic_clear_wakeup_irq(IRQn)
  907. #define NVIC_GetActive(IRQn) csi_vic_get_active(IRQn)
  908. #define NVIC_SetThreshold(VectThreshold, PrioThreshold) csi_vic_set_threshold(VectThreshold, PrioThreshold)
  909. #define NVIC_SetPriority(IRQn, priority) csi_vic_set_prio(IRQn, priority)
  910. #define NVIC_GetPriority(IRQn) csi_vic_get_prio(IRQn)
  911. #define NVIC_SystemReset() csi_system_reset()
  912. #define SysTick_Config(ticks) csi_coret_config(ticks, CORET_IRQn)
  913. #define CORET_Config(ticks) csi_coret_config(ticks, CORET_IRQn)
  914. /*@} end of Old Interfaces */
  915. #ifdef __cplusplus
  916. }
  917. #endif
  918. #endif /* __CORE_801_H_DEPENDANT */
  919. #endif /* __CSI_GENERIC */