core_rv32.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. /*
  2. * Copyright (C) 2017-2019 Alibaba Group Holding Limited
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-08-20 zx.chen CSI RV32 Core Peripheral Access Layer Header File
  9. */
  10. #ifndef __CORE_RV32_H_GENERIC
  11. #define __CORE_RV32_H_GENERIC
  12. #include <stdint.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /*******************************************************************************
  17. * CSI definitions
  18. ******************************************************************************/
  19. /**
  20. \ingroup RV32
  21. @{
  22. */
  23. #ifndef __RV32
  24. #define __RV32 (0x01U)
  25. #endif
  26. /** __FPU_USED indicates whether an FPU is used or not.
  27. This core does not support an FPU at all
  28. */
  29. #define __FPU_USED 0U
  30. #if defined ( __GNUC__ )
  31. #if defined (__VFP_FP__) && !defined(__SOFTFP__)
  32. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  33. #endif
  34. #endif
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif /* __CORE_RV32_H_GENERIC */
  39. #ifndef __CSI_GENERIC
  40. #ifndef __CORE_RV32_H_DEPENDANT
  41. #define __CORE_RV32_H_DEPENDANT
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /* check device defines and use defaults */
  46. #ifndef __RV32_REV
  47. #define __RV32_REV 0x0000U
  48. #endif
  49. #ifndef __VIC_PRIO_BITS
  50. #define __VIC_PRIO_BITS 2U
  51. #endif
  52. #ifndef __Vendor_SysTickConfig
  53. #define __Vendor_SysTickConfig 1U
  54. #endif
  55. #ifndef __MPU_PRESENT
  56. #define __MPU_PRESENT 1U
  57. #endif
  58. #ifndef __ICACHE_PRESENT
  59. #define __ICACHE_PRESENT 1U
  60. #endif
  61. #ifndef __DCACHE_PRESENT
  62. #define __DCACHE_PRESENT 1U
  63. #endif
  64. #include <csi_rv32_gcc.h>
  65. /* IO definitions (access restrictions to peripheral registers) */
  66. /**
  67. \defgroup CSI_glob_defs CSI Global Defines
  68. <strong>IO Type Qualifiers</strong> are used
  69. \li to specify the access to peripheral variables.
  70. \li for automatic generation of peripheral register debug information.
  71. */
  72. #ifdef __cplusplus
  73. #define __I volatile /*!< Defines 'read only' permissions */
  74. #else
  75. #define __I volatile const /*!< Defines 'read only' permissions */
  76. #endif
  77. #define __O volatile /*!< Defines 'write only' permissions */
  78. #define __IO volatile /*!< Defines 'read / write' permissions */
  79. /* following defines should be used for structure members */
  80. #define __IM volatile const /*! Defines 'read only' structure member permissions */
  81. #define __OM volatile /*! Defines 'write only' structure member permissions */
  82. #define __IOM volatile /*! Defines 'read / write' structure member permissions */
  83. /*@} end of group CK802 */
  84. /*******************************************************************************
  85. * Register Abstraction
  86. Core Register contain:
  87. - Core Register
  88. - Core CLIC Register
  89. ******************************************************************************/
  90. /**
  91. \defgroup CSI_core_register Defines and Type Definitions
  92. \brief Type definitions and defines for CK80X processor based devices.
  93. */
  94. /**
  95. \ingroup CSI_core_register
  96. \defgroup CSI_CORE Status and Control Registers
  97. \brief Core Register type definitions.
  98. @{
  99. */
  100. /**
  101. \ingroup CSI_core_register
  102. \defgroup CSI_CLIC Core-Local Interrupt Controller (CLIC)
  103. \brief Type definitions for the CLIC Registers
  104. @{
  105. */
  106. /**
  107. \brief Access to the structure of a vector interrupt controller.
  108. */
  109. typedef struct
  110. {
  111. __IOM uint8_t IP; /*!< Offset: 0x000 (R/W) Interrupt set pending register */
  112. __IOM uint8_t IE; /*!< Offset: 0x004 (R/W) Interrupt set enable register */
  113. __IOM uint8_t ATTR; /*!< Offset: 0x008 (R/W) Interrupt set attribute register */
  114. __IOM uint8_t CTL; /*!< Offset: 0x00C (R/W) Interrupt control register */
  115. } CLIC_INT_Control;
  116. typedef struct
  117. {
  118. __IOM uint32_t CLICCFG:8; /*!< Offset: 0x000 (R/W) CLIC configure register */
  119. __IM uint32_t CLICINFO;
  120. __IOM uint32_t MINTTHRESH;
  121. uint32_t RESERVED[1021];
  122. CLIC_INT_Control CLICINT[4096];
  123. } CLIC_Type;
  124. #define CLIC_INFO_CLICINTCTLBITS_Pos 21U
  125. #define CLIC_INFO_CLICINTCTLBITS_Msk (0xFUL << CLIC_INFO_CLICINTCTLBITS_Pos)
  126. #define CLIC_INTIP_IP_Pos 0U /*!< CLIC INTIP: IP Position */
  127. #define CLIC_INTIP_IP_Msk (0x1UL << CLIC_INTIP_IP_Pos) /*!< CLIC INTIP: IP Mask */
  128. #define CLIC_INTIE_IE_Pos 0U /*!< CLIC INTIE: IE Position */
  129. #define CLIC_INTIE_IE_Msk (0x1UL << CLIC_INTIE_IE_Pos) /*!< CLIC INTIE: IE Mask */
  130. #define CLIC_INTIE_T_Pos 7U /*!< CLIC INTIE: T Position */
  131. #define CLIC_INTIE_T_Msk (0x1UL << CLIC_INTIE_T_Pos) /*!< CLIC INTIE: T Mask */
  132. #define CLIC_INTATTR_TRIG_Pos 1U /*!< CLIC INTATTR: TRIG Position */
  133. #define CLIC_INTATTR_TRIG_Msk (0x3UL << CLIC_INTATTR_TRIG_Pos) /*!< CLIC INTATTR: TRIG Mask */
  134. #define CLIC_INTATTR_SHV_Pos 0U /*!< CLIC INTATTR: SHV Position */
  135. #define CLIC_INTATTR_SHV_Msk (0x1UL << CLIC_INTATTR_SHV_Pos) /*!< CLIC INTATTR: SHV Mask */
  136. #define CLIC_INTCFG_NVBIT_Pos 5U /*!< CLIC INTCFG: NVBIT Position */
  137. #define CLIC_INTCFG_NVBIT_Msk (0x1UL << CLIC_INTCFG_NVBIT_Pos) /*!< CLIC INTCFG: NVBIT Mask */
  138. #define CLIC_INTCFG_PRIO_Pos 5U /*!< CLIC INTCFG: INTCFG Position */
  139. #define CLIC_INTCFG_PRIO_Msk (0x7UL << CLIC_INTCFG_PRIO_Pos) /*!< CLIC INTCFG: INTCFG Mask */
  140. #define CLIC_CLICCFG_NVBIT_Pos 0U /*!< CLIC CLICCFG: NVBIT Position */
  141. #define CLIC_CLICCFG_NVBIT_Msk (0x1UL << CLIC_CLICCFG_NVBIT_Pos) /*!< CLIC CLICCFG: NVBIT Mask */
  142. #define CLIC_CLICCFG_NLBIT_Pos 1U /*!< CLIC CLICCFG: NLBIT Position */
  143. #define CLIC_CLICCFG_NLBIT_Msk (0xFUL << CLIC_CLICCFG_NLBIT_Pos) /*!< CLIC CLICCFG: NLBIT Mask */
  144. #define CLIC_CLICCFG_NMBIT_Pos 5U /*!< CLIC CLICCFG: NMBIT Position */
  145. #define CLIC_CLICCFG_NMBIT_Msk (0x3UL << CLIC_CLICCFG_NMBIT_Pos) /*!< CLIC CLICCFG: NMBIT Mask */
  146. /*@} end of group CSI_CLIC */
  147. /**
  148. \ingroup CSI_core_register
  149. \defgroup CSI_PMP Physical Memory Protection (PMP)
  150. \brief Type definitions for the PMP Registers
  151. @{
  152. */
  153. #define PMP_PMPCFG_R_Pos 0U /*!< PMP PMPCFG: R Position */
  154. #define PMP_PMPCFG_R_Msk (0x1UL << PMP_PMPCFG_R_Pos) /*!< PMP PMPCFG: R Mask */
  155. #define PMP_PMPCFG_W_Pos 1U /*!< PMP PMPCFG: W Position */
  156. #define PMP_PMPCFG_W_Msk (0x1UL << PMP_PMPCFG_W_Pos) /*!< PMP PMPCFG: W Mask */
  157. #define PMP_PMPCFG_X_Pos 2U /*!< PMP PMPCFG: X Position */
  158. #define PMP_PMPCFG_X_Msk (0x1UL << PMP_PMPCFG_X_Pos) /*!< PMP PMPCFG: X Mask */
  159. #define PMP_PMPCFG_A_Pos 3U /*!< PMP PMPCFG: A Position */
  160. #define PMP_PMPCFG_A_Msk (0x3UL << PMP_PMPCFG_A_Pos) /*!< PMP PMPCFG: A Mask */
  161. #define PMP_PMPCFG_L_Pos 7U /*!< PMP PMPCFG: L Position */
  162. #define PMP_PMPCFG_L_Msk (0x1UL << PMP_PMPCFG_L_Pos) /*!< PMP PMPCFG: L Mask */
  163. typedef enum
  164. {
  165. REGION_SIZE_4B = -1,
  166. REGION_SIZE_8B = 0,
  167. REGION_SIZE_16B = 1,
  168. REGION_SIZE_32B = 2,
  169. REGION_SIZE_64B = 3,
  170. REGION_SIZE_128B = 4,
  171. REGION_SIZE_256B = 5,
  172. REGION_SIZE_512B = 6,
  173. REGION_SIZE_1KB = 7,
  174. REGION_SIZE_2KB = 8,
  175. REGION_SIZE_4KB = 9,
  176. REGION_SIZE_8KB = 10,
  177. REGION_SIZE_16KB = 11,
  178. REGION_SIZE_32KB = 12,
  179. REGION_SIZE_64KB = 13,
  180. REGION_SIZE_128KB = 14,
  181. REGION_SIZE_256KB = 15,
  182. REGION_SIZE_512KB = 16,
  183. REGION_SIZE_1MB = 17,
  184. REGION_SIZE_2MB = 18,
  185. REGION_SIZE_4MB = 19,
  186. REGION_SIZE_8MB = 20,
  187. REGION_SIZE_16MB = 21,
  188. REGION_SIZE_32MB = 22,
  189. REGION_SIZE_64MB = 23,
  190. REGION_SIZE_128MB = 24,
  191. REGION_SIZE_256MB = 25,
  192. REGION_SIZE_512MB = 26,
  193. REGION_SIZE_1GB = 27,
  194. REGION_SIZE_2GB = 28,
  195. REGION_SIZE_4GB = 29,
  196. REGION_SIZE_8GB = 30,
  197. REGION_SIZE_16GB = 31
  198. } region_size_e;
  199. typedef enum
  200. {
  201. ADDRESS_MATCHING_TOR = 1,
  202. ADDRESS_MATCHING_NAPOT = 3
  203. } address_matching_e;
  204. typedef struct
  205. {
  206. uint32_t r: 1; /* readable enable */
  207. uint32_t w: 1; /* writeable enable */
  208. uint32_t x: 1; /* execable enable */
  209. address_matching_e a: 2; /* address matching mode */
  210. uint32_t reserved: 2; /* reserved */
  211. uint32_t l: 1; /* lock enable */
  212. } mpu_region_attr_t;
  213. /*@} end of group CSI_PMP */
  214. /* CACHE Register Definitions */
  215. #define CACHE_MHCR_L0BTB_Pos 12U /*!< CACHE MHCR: L0BTB Position */
  216. #define CACHE_MHCR_L0BTB_Msk (0x1UL << CACHE_MHCR_L0BTB_Pos) /*!< CACHE MHCR: WA Mask */
  217. #define CACHE_MHCR_BPE_Pos 5U /*!< CACHE MHCR: BPE Position */
  218. #define CACHE_MHCR_BPE_Msk (0x1UL << CACHE_MHCR_BPE_Pos) /*!< CACHE MHCR: BPE Mask */
  219. #define CACHE_MHCR_RS_Pos 4U /*!< CACHE MHCR: RS Position */
  220. #define CACHE_MHCR_RS_Msk (0x1UL << CACHE_MHCR_RS_Pos) /*!< CACHE MHCR: RS Mask */
  221. #define CACHE_MHCR_WA_Pos 3U /*!< CACHE MHCR: WA Position */
  222. #define CACHE_MHCR_WA_Msk (0x1UL << CACHE_MHCR_WA_Pos) /*!< CACHE MHCR: WA Mask */
  223. #define CACHE_MHCR_WB_Pos 2U /*!< CACHE MHCR: WB Position */
  224. #define CACHE_MHCR_WB_Msk (0x1UL << CACHE_MHCR_WB_Pos) /*!< CACHE MHCR: WB Mask */
  225. #define CACHE_MHCR_DE_Pos 1U /*!< CACHE MHCR: DE Position */
  226. #define CACHE_MHCR_DE_Msk (0x1UL << CACHE_MHCR_DE_Pos) /*!< CACHE MHCR: DE Mask */
  227. #define CACHE_MHCR_IE_Pos 0U /*!< CACHE MHCR: IE Position */
  228. #define CACHE_MHCR_IE_Msk (0x1UL << CACHE_MHCR_IE_Pos) /*!< CACHE MHCR: IE Mask */
  229. #define CACHE_INV_ADDR_Pos 5U
  230. #define CACHE_INV_ADDR_Msk (0xFFFFFFFFUL << CACHE_INV_ADDR_Pos)
  231. /*@} end of group CSI_CACHE */
  232. #define SYSMAP_SYSMAPCFG_B_Pos 0U /*!< SYSMAP SYSMAPCFG: B Position */
  233. #define SYSMAP_SYSMAPCFG_B_Msk (0x1UL << SYSMAP_SYSMAPCFG_B_Pos) /*!< SYSMAP SYSMAPCFG: B Mask */
  234. #define SYSMAP_SYSMAPCFG_C_Pos 1U /*!< SYSMAP SYSMAPCFG: C Position */
  235. #define SYSMAP_SYSMAPCFG_C_Msk (0x1UL << SYSMAP_SYSMAPCFG_C_Pos) /*!< SYSMAP SYSMAPCFG: C Mask */
  236. #define SYSMAP_SYSMAPCFG_SO_Pos 2U /*!< SYSMAP SYSMAPCFG: SO Position */
  237. #define SYSMAP_SYSMAPCFG_SO_Msk (0x1UL << SYSMAP_SYSMAPCFG_SO_Pos) /*!< SYSMAP SYSMAPCFG: SO Mask */
  238. /**
  239. \ingroup CSI_core_register
  240. \defgroup CSI_SYSMAP system map (SYSMAP)
  241. \brief Type definitions for the SYSMAP Registers
  242. @{
  243. */
  244. typedef struct
  245. {
  246. __IOM uint32_t SYSMAPADDR0; /*!< Offset: 0x000 (R/W) SYSMAP configure register */
  247. __IOM uint32_t SYSMAPCFG0; /*!< Offset: 0x004 (R/W) SYSMAP configure register */
  248. __IOM uint32_t SYSMAPADDR1; /*!< Offset: 0x008 (R/W) SYSMAP configure register */
  249. __IOM uint32_t SYSMAPCFG1; /*!< Offset: 0x00c (R/W) SYSMAP configure register */
  250. __IOM uint32_t SYSMAPADDR2; /*!< Offset: 0x010 (R/W) SYSMAP configure register */
  251. __IOM uint32_t SYSMAPCFG2; /*!< Offset: 0x014 (R/W) SYSMAP configure register */
  252. __IOM uint32_t SYSMAPADDR3; /*!< Offset: 0x018 (R/W) SYSMAP configure register */
  253. __IOM uint32_t SYSMAPCFG3; /*!< Offset: 0x01c (R/W) SYSMAP configure register */
  254. __IOM uint32_t SYSMAPADDR4; /*!< Offset: 0x020 (R/W) SYSMAP configure register */
  255. __IOM uint32_t SYSMAPCFG4; /*!< Offset: 0x024 (R/W) SYSMAP configure register */
  256. __IOM uint32_t SYSMAPADDR5; /*!< Offset: 0x028 (R/W) SYSMAP configure register */
  257. __IOM uint32_t SYSMAPCFG5; /*!< Offset: 0x02c (R/W) SYSMAP configure register */
  258. __IOM uint32_t SYSMAPADDR6; /*!< Offset: 0x030 (R/W) SYSMAP configure register */
  259. __IOM uint32_t SYSMAPCFG6; /*!< Offset: 0x034 (R/W) SYSMAP configure register */
  260. __IOM uint32_t SYSMAPADDR7; /*!< Offset: 0x038 (R/W) SYSMAP configure register */
  261. __IOM uint32_t SYSMAPCFG7; /*!< Offset: 0x03c (R/W) SYSMAP configure register */
  262. } SYSMAP_Type;
  263. /*@} end of group CSI_SYSMAP */
  264. /**
  265. \ingroup CSI_core_register
  266. \defgroup CSI_SysTick System Tick Timer (CORET)
  267. \brief Type definitions for the System Timer Registers.
  268. @{
  269. */
  270. /**
  271. \brief The data structure of the access system timer.
  272. */
  273. typedef struct
  274. {
  275. __IOM unsigned long long MTIMECMP; /*!< Offset: 0x000 (R/W) Timer compare register */
  276. uint32_t RESERVED[8187];
  277. __IM unsigned long long MTIME; /*!< Offset: 0x7FFC (R) Timer current register */
  278. } CORET_Type;
  279. /*@} end of group CSI_SysTick */
  280. /**
  281. \ingroup CSI_core_register
  282. \defgroup CSI_DCC
  283. \brief Type definitions for the DCC.
  284. @{
  285. */
  286. /**
  287. \brief Access to the data structure of DCC.
  288. */
  289. typedef struct
  290. {
  291. uint32_t RESERVED0[13U];
  292. __IOM uint32_t HCR; /*!< Offset: 0x034 (R/W) */
  293. __IM uint32_t EHSR; /*!< Offset: 0x03C (R/ ) */
  294. uint32_t RESERVED1[6U];
  295. union {
  296. __IM uint32_t DERJW; /*!< Offset: 0x058 (R/ ) Data exchange register CPU read*/
  297. __OM uint32_t DERJR; /*!< Offset: 0x058 ( /W) Data exchange register CPU writer*/
  298. };
  299. } DCC_Type;
  300. #define DCC_HCR_JW_Pos 18U /*!< DCC HCR: jw_int_en Position */
  301. #define DCC_HCR_JW_Msk (1UL << DCC_HCR_JW_Pos) /*!< DCC HCR: jw_int_en Mask */
  302. #define DCC_HCR_JR_Pos 19U /*!< DCC HCR: jr_int_en Position */
  303. #define DCC_HCR_JR_Msk (1UL << DCC_HCR_JR_Pos) /*!< DCC HCR: jr_int_en Mask */
  304. #define DCC_EHSR_JW_Pos 1U /*!< DCC EHSR: jw_vld Position */
  305. #define DCC_EHSR_JW_Msk (1UL << DCC_EHSR_JW_Pos) /*!< DCC EHSR: jw_vld Mask */
  306. #define DCC_EHSR_JR_Pos 2U /*!< DCC EHSR: jr_vld Position */
  307. #define DCC_EHSR_JR_Msk (1UL << DCC_EHSR_JR_Pos) /*!< DCC EHSR: jr_vld Mask */
  308. /*@} end of group CSI_DCC */
  309. /**
  310. \ingroup CSI_core_register
  311. \defgroup CSI_core_bitfield Core register bit field macros
  312. \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
  313. @{
  314. */
  315. /**
  316. \brief Mask and shift a bit field value for use in a register bit range.
  317. \param[in] field Name of the register bit field.
  318. \param[in] value Value of the bit field.
  319. \return Masked and shifted value.
  320. */
  321. #define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
  322. /**
  323. \brief Mask and shift a register value to extract a bit filed value.
  324. \param[in] field Name of the register bit field.
  325. \param[in] value Value of register.
  326. \return Masked and shifted bit field value.
  327. */
  328. #define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
  329. /*@} end of group CSI_core_bitfield */
  330. /**
  331. \ingroup CSI_core_register
  332. \defgroup CSI_core_base Core Definitions
  333. \brief Definitions for base addresses, unions, and structures.
  334. @{
  335. */
  336. /* Memory mapping of CK802 Hardware */
  337. #define TCIP_BASE (0xE000E000UL) /*!< Titly Coupled IP Base Address */
  338. #define CORET_BASE (0xE0004000UL) /*!< CORET Base Address */
  339. #define CLIC_BASE (0xE0800000UL) /*!< CLIC Base Address */
  340. #define SYSMAP_BASE (0xEFFFF000UL) /*!< SYSMAP Base Address */
  341. #define DCC_BASE (0xE4010000UL) /*!< DCC Base Address */
  342. #define CACHE_BASE (TCIP_BASE + 0x1000UL) /*!< CACHE Base Address */
  343. #define CORET ((CORET_Type *) CORET_BASE ) /*!< SysTick configuration struct */
  344. #define CLIC ((CLIC_Type *) CLIC_BASE ) /*!< CLIC configuration struct */
  345. #define DCC ((DCC_Type *) DCC_BASE ) /*!< DCC configuration struct */
  346. #define SYSMAP ((SYSMAP_Type *) SYSMAP_BASE ) /*!< SYSMAP configuration struct */
  347. #define CACHE ((CACHE_Type *) CACHE_BASE ) /*!< cache configuration struct */
  348. /*@} */
  349. /*******************************************************************************
  350. * Hardware Abstraction Layer
  351. Core Function Interface contains:
  352. - Core VIC Functions
  353. - Core CORET Functions
  354. - Core Register Access Functions
  355. ******************************************************************************/
  356. /**
  357. \defgroup CSI_Core_FunctionInterface Functions and Instructions Reference
  358. */
  359. /* ########################## VIC functions #################################### */
  360. /**
  361. \ingroup CSI_Core_FunctionInterface
  362. \defgroup CSI_Core_VICFunctions VIC Functions
  363. \brief Functions that manage interrupts and exceptions via the VIC.
  364. @{
  365. */
  366. /* The following MACROS handle generation of the register offset and byte masks */
  367. #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
  368. #define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 5UL) )
  369. #define _IP2_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
  370. /**
  371. \brief Enable External Interrupt
  372. \details Enable a device-specific interrupt in the VIC interrupt controller.
  373. \param [in] IRQn External interrupt number. Value cannot be negative.
  374. */
  375. __STATIC_INLINE void csi_vic_enable_irq(int32_t IRQn)
  376. {
  377. CLIC->CLICINT[IRQn].IE |= CLIC_INTIE_IE_Msk;
  378. }
  379. /**
  380. \brief Disable External Interrupt
  381. \details Disable a device-specific interrupt in the VIC interrupt controller.
  382. \param [in] IRQn External interrupt number. Value cannot be negative.
  383. */
  384. __STATIC_INLINE void csi_vic_disable_irq(int32_t IRQn)
  385. {
  386. CLIC->CLICINT[IRQn].IE &= ~CLIC_INTIE_IE_Msk;
  387. }
  388. /**
  389. \brief Enable External Secure Interrupt
  390. \details Enable a secure device-specific interrupt in the VIC interrupt controller.
  391. \param [in] IRQn External interrupt number. Value cannot be negative.
  392. */
  393. __STATIC_INLINE void csi_vic_enable_sirq(int32_t IRQn)
  394. {
  395. CLIC->CLICINT[IRQn].IE |= (CLIC_INTIE_IE_Msk | CLIC_INTIE_T_Msk);
  396. }
  397. /**
  398. \brief Disable External Secure Interrupt
  399. \details Disable a secure device-specific interrupt in the VIC interrupt controller.
  400. \param [in] IRQn External interrupt number. Value cannot be negative.
  401. */
  402. __STATIC_INLINE void csi_vic_disable_sirq(int32_t IRQn)
  403. {
  404. CLIC->CLICINT[IRQn].IE &= ~(CLIC_INTIE_IE_Msk | CLIC_INTIE_T_Msk);
  405. }
  406. /**
  407. \brief Check Interrupt is Enabled or not
  408. \details Read the enabled register in the VIC and returns the pending bit for the specified interrupt.
  409. \param [in] IRQn Interrupt number.
  410. \return 0 Interrupt status is not enabled.
  411. \return 1 Interrupt status is enabled.
  412. */
  413. __STATIC_INLINE uint32_t csi_vic_get_enabled_irq(int32_t IRQn)
  414. {
  415. return (uint32_t)(CLIC->CLICINT[IRQn].IE & CLIC_INTIE_IE_Msk);
  416. }
  417. /**
  418. \brief Check Interrupt is Pending or not
  419. \details Read the pending register in the VIC and returns the pending bit for the specified interrupt.
  420. \param [in] IRQn Interrupt number.
  421. \return 0 Interrupt status is not pending.
  422. \return 1 Interrupt status is pending.
  423. */
  424. __STATIC_INLINE uint32_t csi_vic_get_pending_irq(int32_t IRQn)
  425. {
  426. return (uint32_t)(CLIC->CLICINT[IRQn].IP & CLIC_INTIP_IP_Msk);
  427. }
  428. /**
  429. \brief Set Pending Interrupt
  430. \details Set the pending bit of an external interrupt.
  431. \param [in] IRQn Interrupt number. Value cannot be negative.
  432. */
  433. __STATIC_INLINE void csi_vic_set_pending_irq(int32_t IRQn)
  434. {
  435. CLIC->CLICINT[IRQn].IP |= CLIC_INTIP_IP_Msk;
  436. }
  437. /**
  438. \brief Clear Pending Interrupt
  439. \details Clear the pending bit of an external interrupt.
  440. \param [in] IRQn External interrupt number. Value cannot be negative.
  441. */
  442. __STATIC_INLINE void csi_vic_clear_pending_irq(int32_t IRQn)
  443. {
  444. CLIC->CLICINT[IRQn].IP &= ~CLIC_INTIP_IP_Msk;
  445. }
  446. /**
  447. \brief Set Interrupt Priority
  448. \details Set the priority of an interrupt.
  449. \note The priority cannot be set for every core interrupt.
  450. \param [in] IRQn Interrupt number.
  451. \param [in] priority Priority to set.
  452. */
  453. __STATIC_INLINE void csi_vic_set_prio(int32_t IRQn, uint32_t priority)
  454. {
  455. uint8_t nlbits = (CLIC->CLICINFO & CLIC_INFO_CLICINTCTLBITS_Msk) >> CLIC_INFO_CLICINTCTLBITS_Pos;
  456. CLIC->CLICINT[IRQn].CTL = (CLIC->CLICINT[IRQn].CTL & (~CLIC_INTCFG_PRIO_Msk)) | (priority << (8 - nlbits));
  457. }
  458. /**
  459. \brief Get Interrupt Priority
  460. \details Read the priority of an interrupt.
  461. The interrupt number can be positive to specify an external (device specific) interrupt,
  462. or negative to specify an internal (core) interrupt.
  463. \param [in] IRQn Interrupt number.
  464. \return Interrupt Priority.
  465. Value is aligned automatically to the implemented priority bits of the microcontroller.
  466. */
  467. __STATIC_INLINE uint32_t csi_vic_get_prio(int32_t IRQn)
  468. {
  469. uint8_t nlbits = (CLIC->CLICINFO & CLIC_INFO_CLICINTCTLBITS_Msk) >> CLIC_INFO_CLICINTCTLBITS_Pos;
  470. return CLIC->CLICINT[IRQn].CTL >> (8 - nlbits);
  471. }
  472. /**
  473. \brief Set interrupt handler
  474. \details Set the interrupt handler according to the interrupt num, the handler will be filled in irq vectors.
  475. \param [in] IRQn Interrupt number.
  476. \param [in] handler Interrupt handler.
  477. */
  478. __STATIC_INLINE void csi_vic_set_vector(int32_t IRQn, uint32_t handler)
  479. {
  480. if (IRQn >= 0 && IRQn < 1024) {
  481. uint32_t *vectors = (uint32_t *)__get_MTVT();
  482. vectors[IRQn] = handler;
  483. }
  484. }
  485. /**
  486. \brief Get interrupt handler
  487. \details Get the address of interrupt handler function.
  488. \param [in] IRQn Interrupt number.
  489. */
  490. __STATIC_INLINE uint32_t csi_vic_get_vector(int32_t IRQn)
  491. {
  492. if (IRQn >= 0 && IRQn < 1024) {
  493. uint32_t *vectors = (uint32_t *)__get_MTVT();
  494. return (uint32_t)vectors[IRQn];
  495. }
  496. return 0;
  497. }
  498. /*@} end of CSI_Core_VICFunctions */
  499. /* ########################## PMP functions #################################### */
  500. /**
  501. \ingroup CSI_Core_FunctionInterface
  502. \defgroup CSI_Core_PMPFunctions PMP Functions
  503. \brief Functions that manage interrupts and exceptions via the VIC.
  504. @{
  505. */
  506. /**
  507. \brief configure memory protected region.
  508. \details
  509. \param [in] idx memory protected region (0, 1, 2, ..., 15).
  510. \param [in] base_addr base address must be aligned with page size.
  511. \param [in] size \ref region_size_e. memory protected region size.
  512. \param [in] attr \ref region_size_t. memory protected region attribute.
  513. \param [in] enable enable or disable memory protected region.
  514. */
  515. __STATIC_INLINE void csi_mpu_config_region(uint32_t idx, uint32_t base_addr, region_size_e size,
  516. mpu_region_attr_t attr, uint32_t enable)
  517. {
  518. uint8_t pmpxcfg = 0;
  519. uint32_t addr = 0;
  520. if (idx > 15) {
  521. return;
  522. }
  523. if (!enable) {
  524. attr.a = 0;
  525. }
  526. if (attr.a == ADDRESS_MATCHING_TOR) {
  527. addr = base_addr >> 2;
  528. } else {
  529. if (size == REGION_SIZE_4B) {
  530. addr = base_addr >> 2;
  531. attr.a = 2;
  532. } else {
  533. addr = ((base_addr >> 2) & (0xFFFFFFFFU - ((1 << (size + 1)) - 1))) | ((1 << size) - 1);
  534. }
  535. }
  536. __set_PMPADDRx(idx, addr);
  537. pmpxcfg |= (attr.r << PMP_PMPCFG_R_Pos) | (attr.w << PMP_PMPCFG_W_Pos) |
  538. (attr.x << PMP_PMPCFG_X_Pos) | (attr.a << PMP_PMPCFG_A_Pos) |
  539. (attr.l << PMP_PMPCFG_L_Pos);
  540. __set_PMPxCFG(idx, pmpxcfg);
  541. }
  542. /**
  543. \brief disable mpu region by idx.
  544. \details
  545. \param [in] idx memory protected region (0, 1, 2, ..., 15).
  546. */
  547. __STATIC_INLINE void csi_mpu_disable_region(uint32_t idx)
  548. {
  549. __set_PMPxCFG(idx, __get_PMPxCFG(idx) & (~PMP_PMPCFG_A_Msk));
  550. }
  551. /*@} end of CSI_Core_PMPFunctions */
  552. /* ################################## SysTick function ############################################ */
  553. /**
  554. \ingroup CSI_Core_FunctionInterface
  555. \defgroup CSI_Core_SysTickFunctions SysTick Functions
  556. \brief Functions that configure the System.
  557. @{
  558. */
  559. /**
  560. \brief CORE timer Configuration
  561. \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
  562. Counter is in free running mode to generate periodic interrupts.
  563. \param [in] ticks Number of ticks between two interrupts.
  564. \param [in] IRQn core timer Interrupt number.
  565. \return 0 Function succeeded.
  566. \return 1 Function failed.
  567. \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
  568. function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
  569. must contain a vendor-specific implementation of this function.
  570. */
  571. __STATIC_INLINE uint32_t csi_coret_config(uint32_t ticks, int32_t IRQn)
  572. {
  573. if ((CORET->MTIMECMP != 0) && (CORET->MTIMECMP != 0xffffffffffffffff)) {
  574. CORET->MTIMECMP = CORET->MTIMECMP + ticks;
  575. } else {
  576. CORET->MTIMECMP = CORET->MTIME + ticks;
  577. }
  578. return (0UL);
  579. }
  580. /**
  581. \brief get CORE timer reload value
  582. \return CORE timer counter value.
  583. */
  584. __STATIC_INLINE uint32_t csi_coret_get_load(void)
  585. {
  586. return CORET->MTIMECMP & 0xFFFFFFFF;
  587. }
  588. /**
  589. \brief get CORE timer reload high value
  590. \return CORE timer counter value.
  591. */
  592. __STATIC_INLINE uint32_t csi_coret_get_loadh(void)
  593. {
  594. return (CORET->MTIMECMP >> 32) & 0xFFFFFFFF;
  595. }
  596. /**
  597. \brief get CORE timer counter value
  598. \return CORE timer counter value.
  599. */
  600. __STATIC_INLINE uint32_t csi_coret_get_value(void)
  601. {
  602. return CORET->MTIME & 0xFFFFFFFF;
  603. }
  604. /**
  605. \brief get CORE timer counter high value
  606. \return CORE timer counter value.
  607. */
  608. __STATIC_INLINE uint32_t csi_coret_get_valueh(void)
  609. {
  610. return (CORET->MTIME >> 32) & 0xFFFFFFFF;
  611. }
  612. /*@} end of CSI_Core_SysTickFunctions */
  613. /* ########################## SYSMAP functions #################################### */
  614. /**
  615. \ingroup CSI_Core_FunctionInterface
  616. \defgroup CSI_Core_SYSMAPFunctions SYSMAP Functions
  617. \brief Functions that manage system map attribute
  618. @{
  619. */
  620. /**
  621. \brief Get SYSMAPCFGx Register by index
  622. \details Returns the content of the SYSMAPxCFG Register.
  623. \param [in] idx SYSMAP region index
  624. \return SYSMAPxCFG Register value
  625. */
  626. __STATIC_INLINE uint8_t __get_SYSMAPCFGx(uint32_t idx)
  627. {
  628. switch (idx)
  629. {
  630. case 0: return SYSMAP->SYSMAPCFG0;
  631. case 1: return SYSMAP->SYSMAPCFG1;
  632. case 2: return SYSMAP->SYSMAPCFG2;
  633. case 3: return SYSMAP->SYSMAPCFG3;
  634. case 4: return SYSMAP->SYSMAPCFG4;
  635. case 5: return SYSMAP->SYSMAPCFG5;
  636. case 6: return SYSMAP->SYSMAPCFG6;
  637. case 7: return SYSMAP->SYSMAPCFG7;
  638. default: return 0;
  639. }
  640. }
  641. /**
  642. \brief Set SYSMAPCFGx by index
  643. \details Writes the given value to the SYSMAPxCFG Register.
  644. \param [in] idx SYSMAPx region index
  645. \param [in] sysmapxcfg SYSMAPxCFG Register value to set
  646. */
  647. __STATIC_INLINE void __set_SYSMAPCFGx(uint32_t idx, uint32_t sysmapxcfg)
  648. {
  649. switch (idx)
  650. {
  651. case 0: SYSMAP->SYSMAPCFG0 = sysmapxcfg; break;
  652. case 1: SYSMAP->SYSMAPCFG1 = sysmapxcfg; break;
  653. case 2: SYSMAP->SYSMAPCFG2 = sysmapxcfg; break;
  654. case 3: SYSMAP->SYSMAPCFG3 = sysmapxcfg; break;
  655. case 4: SYSMAP->SYSMAPCFG4 = sysmapxcfg; break;
  656. case 5: SYSMAP->SYSMAPCFG5 = sysmapxcfg; break;
  657. case 6: SYSMAP->SYSMAPCFG6 = sysmapxcfg; break;
  658. case 7: SYSMAP->SYSMAPCFG7 = sysmapxcfg; break;
  659. default: return;
  660. }
  661. }
  662. /**
  663. \brief Get SYSMAPADDRx Register by index
  664. \details Returns the content of the SYSMAPADDRx Register.
  665. \param [in] idx SYSMAP region index
  666. \return SYSMAPADDRx Register value
  667. */
  668. __STATIC_INLINE uint32_t __get_SYSMAPADDRx(uint32_t idx)
  669. {
  670. switch(idx)
  671. {
  672. case 0: return SYSMAP->SYSMAPADDR0;
  673. case 1: return SYSMAP->SYSMAPADDR1;
  674. case 2: return SYSMAP->SYSMAPADDR2;
  675. case 3: return SYSMAP->SYSMAPADDR3;
  676. case 4: return SYSMAP->SYSMAPADDR4;
  677. case 5: return SYSMAP->SYSMAPADDR5;
  678. case 6: return SYSMAP->SYSMAPADDR6;
  679. case 7: return SYSMAP->SYSMAPADDR7;
  680. default: return 0;
  681. }
  682. }
  683. /**
  684. \brief Set SYSMAPADDRx by index
  685. \details Writes the given value to the SYSMAPADDRx Register.
  686. \param [in] idx SYSMAP region index
  687. \param [in] sysmapaddr SYSMAPADDRx Register value to set
  688. */
  689. __STATIC_INLINE void __set_SYSMAPADDRx(uint32_t idx, uint32_t sysmapxaddr)
  690. {
  691. switch (idx)
  692. {
  693. case 0: SYSMAP->SYSMAPADDR0 = sysmapxaddr; break;
  694. case 1: SYSMAP->SYSMAPADDR1 = sysmapxaddr; break;
  695. case 2: SYSMAP->SYSMAPADDR2 = sysmapxaddr; break;
  696. case 3: SYSMAP->SYSMAPADDR3 = sysmapxaddr; break;
  697. case 4: SYSMAP->SYSMAPADDR4 = sysmapxaddr; break;
  698. case 5: SYSMAP->SYSMAPADDR5 = sysmapxaddr; break;
  699. case 6: SYSMAP->SYSMAPADDR6 = sysmapxaddr; break;
  700. case 7: SYSMAP->SYSMAPADDR7 = sysmapxaddr; break;
  701. default: return;
  702. }
  703. }
  704. /**
  705. \brief configure system map attribute.
  706. \details
  707. \param [in] idx system map region (0, 1, 2, ..., 7).
  708. \param [in] base_addr base address must be aligned with page size.
  709. \param [in] enable enable or disable memory protected region.
  710. */
  711. __STATIC_INLINE void csi_sysmap_config_region(uint32_t idx, uint32_t base_addr, uint32_t attr)
  712. {
  713. uint32_t addr = 0;
  714. if (idx > 7) {
  715. return;
  716. }
  717. addr = base_addr >> 12;
  718. attr = attr << 2;
  719. __set_SYSMAPADDRx(idx, addr);
  720. __set_SYSMAPCFGx(idx, attr);
  721. }
  722. /*@} end of CSI_Core_SYSMAPFunctions */
  723. /* ##################################### DCC function ########################################### */
  724. /**
  725. \ingroup CSI_Core_FunctionInterface
  726. \defgroup CSI_core_DebugFunctions HAD Functions
  727. \brief Functions that access the HAD debug interface.
  728. @{
  729. */
  730. /**
  731. \brief HAD Send Character
  732. \details Transmits a character via the HAD channel 0, and
  733. \li Just returns when no debugger is connected that has booked the output.
  734. \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted.
  735. \param [in] ch Character to transmit.
  736. \returns Character to transmit.
  737. */
  738. __STATIC_INLINE uint32_t csi_had_send_char(uint32_t ch)
  739. {
  740. DCC->DERJR = (uint8_t)ch;
  741. return (ch);
  742. }
  743. /**
  744. \brief HAD Receive Character
  745. \details Inputs a character via the external variable \ref HAD_RxBuffer.
  746. \return Received character.
  747. \return -1 No character pending.
  748. */
  749. __STATIC_INLINE int32_t csi_had_receive_char(void)
  750. {
  751. int32_t ch = -1; /* no character available */
  752. if (_FLD2VAL(DCC_EHSR_JW, DCC->EHSR)) {
  753. ch = DCC->DERJW;
  754. }
  755. return (ch);
  756. }
  757. /**
  758. \brief HAD Check Character
  759. \details Check whether a character is pending for reading in the variable \ref HAD_RxBuffer.
  760. \return 0 No character available.
  761. \return 1 Character available.
  762. */
  763. __STATIC_INLINE int32_t csi_had_check_char(void)
  764. {
  765. return _FLD2VAL(DCC_EHSR_JW, DCC->EHSR); /* no character available */
  766. }
  767. /*@} end of CSI_core_DebugFunctions */
  768. /* ########################## sleep and Reset functions #################################### */
  769. /**
  770. \ingroup CSI_Core_FunctionInterface
  771. \defgroup CSI_Core_SleepAndResetFunctions Sleep and Reset Functions
  772. \brief Functions that configure Sleep and Reset.
  773. @{
  774. */
  775. /* MEXSTATUS Register Definitions */
  776. #define MEXSTATUS_RESET_Pos 0U
  777. #define MEXSTATUS_RESET_Msk (0x3UL << MEXSTATUS_RESET_Pos) /*!< MEXSTATUS: RESET Position */
  778. #define MEXSTATUS_SLEEP_Pos 2U
  779. #define MEXSTATUS_SLEEP_Msk (0x3UL << MEXSTATUS_SLEEP_Pos) /*!< MEXSTATUS: RESET Position */
  780. /*@} end of group CSI_MEXSTATUS */
  781. /**
  782. \brief CPU System Reset
  783. \details Triggle CPU System Reset
  784. */
  785. __STATIC_INLINE void csi_system_reset (void)
  786. {
  787. uint32_t mexstatus;
  788. mexstatus = __get_MEXSTATUS();
  789. mexstatus &= (~(MEXSTATUS_RESET_Msk));
  790. mexstatus |= (uint32_t)(0x2 << MEXSTATUS_RESET_Pos);
  791. __set_MEXSTATUS(mexstatus);
  792. }
  793. /**
  794. \brief CPU Core Reset
  795. \details Triggle CPU Core Reset
  796. */
  797. __STATIC_INLINE void csi_core_reset (void)
  798. {
  799. uint32_t mexstatus;
  800. mexstatus = __get_MEXSTATUS();
  801. mexstatus &= (~(MEXSTATUS_RESET_Msk));
  802. mexstatus |= (uint32_t)(0x1 << MEXSTATUS_RESET_Pos);
  803. __set_MEXSTATUS(mexstatus);
  804. }
  805. /* ########################## Cache functions #################################### */
  806. /**
  807. \ingroup CSI_Core_FunctionInterface
  808. \defgroup CSI_Core_CacheFunctions Cache Functions
  809. \brief Functions that configure Instruction and Data cache.
  810. @{
  811. */
  812. /**
  813. \brief Enable I-Cache
  814. \details Turns on I-Cache
  815. */
  816. __STATIC_INLINE void csi_icache_enable (void)
  817. {
  818. #if (__ICACHE_PRESENT == 1U)
  819. uint32_t cache;
  820. __DSB();
  821. __ISB();
  822. __ICACHE_IALL();
  823. cache = __get_MHCR();
  824. cache |= CACHE_MHCR_IE_Msk;
  825. __set_MHCR(cache);
  826. __DSB();
  827. __ISB();
  828. #endif
  829. }
  830. /**
  831. \brief Disable I-Cache
  832. \details Turns off I-Cache
  833. */
  834. __STATIC_INLINE void csi_icache_disable (void)
  835. {
  836. #if (__ICACHE_PRESENT == 1U)
  837. uint32_t cache;
  838. __DSB();
  839. __ISB();
  840. cache = __get_MHCR();
  841. cache &= ~CACHE_MHCR_IE_Msk; /* disable icache */
  842. __set_MHCR(cache);
  843. __ICACHE_IALL(); /* invalidate all icache */
  844. __DSB();
  845. __ISB();
  846. #endif
  847. }
  848. /**
  849. \brief Invalidate I-Cache
  850. \details Invalidates I-Cache
  851. */
  852. __STATIC_INLINE void csi_icache_invalid (void)
  853. {
  854. #if (__ICACHE_PRESENT == 1U)
  855. __DSB();
  856. __ISB();
  857. __ICACHE_IALL(); /* invalidate all icache */
  858. __DSB();
  859. __ISB();
  860. #endif
  861. }
  862. /**
  863. \brief Enable D-Cache
  864. \details Turns on D-Cache
  865. \note I-Cache also turns on.
  866. */
  867. __STATIC_INLINE void csi_dcache_enable (void)
  868. {
  869. #if (__DCACHE_PRESENT == 1U)
  870. uint32_t cache;
  871. __DSB();
  872. __ISB();
  873. __DCACHE_IALL(); /* invalidate all dcache */
  874. cache = __get_MHCR();
  875. cache |= (CACHE_MHCR_DE_Msk | CACHE_MHCR_WB_Msk | CACHE_MHCR_WA_Msk | CACHE_MHCR_RS_Msk | CACHE_MHCR_BPE_Msk | CACHE_MHCR_L0BTB_Msk); /* enable all Cache */
  876. __set_MHCR(cache);
  877. __DSB();
  878. __ISB();
  879. #endif
  880. }
  881. /**
  882. \brief Disable D-Cache
  883. \details Turns off D-Cache
  884. \note I-Cache also turns off.
  885. */
  886. __STATIC_INLINE void csi_dcache_disable (void)
  887. {
  888. #if (__DCACHE_PRESENT == 1U)
  889. uint32_t cache;
  890. __DSB();
  891. __ISB();
  892. cache = __get_MHCR();
  893. cache &= ~(uint32_t)CACHE_MHCR_DE_Msk; /* disable all Cache */
  894. __set_MHCR(cache);
  895. __DCACHE_IALL(); /* invalidate all Cache */
  896. __DSB();
  897. __ISB();
  898. #endif
  899. }
  900. /**
  901. \brief Invalidate D-Cache
  902. \details Invalidates D-Cache
  903. \note I-Cache also invalid
  904. */
  905. __STATIC_INLINE void csi_dcache_invalid (void)
  906. {
  907. #if (__DCACHE_PRESENT == 1U)
  908. __DSB();
  909. __ISB();
  910. __DCACHE_IALL(); /* invalidate all Cache */
  911. __DSB();
  912. __ISB();
  913. #endif
  914. }
  915. /**
  916. \brief Clean D-Cache
  917. \details Cleans D-Cache
  918. \note I-Cache also cleans
  919. */
  920. __STATIC_INLINE void csi_dcache_clean (void)
  921. {
  922. #if (__DCACHE_PRESENT == 1U)
  923. __DSB();
  924. __ISB();
  925. __DCACHE_CALL(); /* clean all Cache */
  926. __DSB();
  927. __ISB();
  928. #endif
  929. }
  930. /**
  931. \brief Clean & Invalidate D-Cache
  932. \details Cleans and Invalidates D-Cache
  933. \note I-Cache also flush.
  934. */
  935. __STATIC_INLINE void csi_dcache_clean_invalid (void)
  936. {
  937. #if (__DCACHE_PRESENT == 1U)
  938. __DSB();
  939. __ISB();
  940. __DCACHE_CIALL(); /* clean and inv all Cache */
  941. __DSB();
  942. __ISB();
  943. #endif
  944. }
  945. /**
  946. \brief D-Cache Invalidate by address
  947. \details Invalidates D-Cache for the given address
  948. \param[in] addr address (aligned to 32-byte boundary)
  949. \param[in] dsize size of memory block (in number of bytes)
  950. */
  951. __STATIC_INLINE void csi_dcache_invalid_range (uint32_t *addr, int32_t dsize)
  952. {
  953. #if (__DCACHE_PRESENT == 1U)
  954. int32_t op_size = dsize + (uint32_t)addr % 32;
  955. uint32_t op_addr = (uint32_t)addr;
  956. int32_t linesize = 32;
  957. __DSB();
  958. while (op_size > 0) {
  959. __DCACHE_IPA(op_addr);
  960. op_addr += linesize;
  961. op_size -= linesize;
  962. }
  963. __DSB();
  964. __ISB();
  965. #endif
  966. }
  967. /**
  968. \brief D-Cache Clean by address
  969. \details Cleans D-Cache for the given address
  970. \param[in] addr address (aligned to 32-byte boundary)
  971. \param[in] dsize size of memory block (in number of bytes)
  972. */
  973. __STATIC_INLINE void csi_dcache_clean_range (uint32_t *addr, int32_t dsize)
  974. {
  975. #if (__DCACHE_PRESENT == 1U)
  976. int32_t op_size = dsize + (uint32_t)addr % 32;
  977. uint32_t op_addr = (uint32_t) addr & CACHE_INV_ADDR_Msk;
  978. int32_t linesize = 32;
  979. __DSB();
  980. while (op_size > 0) {
  981. __DCACHE_CPA(op_addr);
  982. op_addr += linesize;
  983. op_size -= linesize;
  984. }
  985. __DSB();
  986. __ISB();
  987. #endif
  988. }
  989. /**
  990. \brief D-Cache Clean and Invalidate by address
  991. \details Cleans and invalidates D_Cache for the given address
  992. \param[in] addr address (aligned to 32-byte boundary)
  993. \param[in] dsize size of memory block (aligned to 16-byte boundary)
  994. */
  995. __STATIC_INLINE void csi_dcache_clean_invalid_range (uint32_t *addr, int32_t dsize)
  996. {
  997. #if (__DCACHE_PRESENT == 1U)
  998. int32_t op_size = dsize + (uint32_t)addr % 32;
  999. uint32_t op_addr = (uint32_t) addr;
  1000. int32_t linesize = 32;
  1001. __DSB();
  1002. while (op_size > 0) {
  1003. __DCACHE_CIPA(op_addr);
  1004. op_addr += linesize;
  1005. op_size -= linesize;
  1006. }
  1007. __DSB();
  1008. __ISB();
  1009. #endif
  1010. }
  1011. /**
  1012. \brief setup cacheable range Cache
  1013. \details setup Cache range
  1014. */
  1015. __STATIC_INLINE void csi_cache_set_range (uint32_t index, uint32_t baseAddr, uint32_t size, uint32_t enable)
  1016. {
  1017. ;
  1018. }
  1019. /**
  1020. \brief Enable cache profile
  1021. \details Turns on Cache profile
  1022. */
  1023. __STATIC_INLINE void csi_cache_enable_profile (void)
  1024. {
  1025. ;
  1026. }
  1027. /**
  1028. \brief Disable cache profile
  1029. \details Turns off Cache profile
  1030. */
  1031. __STATIC_INLINE void csi_cache_disable_profile (void)
  1032. {
  1033. ;
  1034. }
  1035. /**
  1036. \brief Reset cache profile
  1037. \details Reset Cache profile
  1038. */
  1039. __STATIC_INLINE void csi_cache_reset_profile (void)
  1040. {
  1041. ;
  1042. }
  1043. /**
  1044. \brief cache access times
  1045. \details Cache access times
  1046. \note every 256 access add 1.
  1047. \return cache access times, actual times should be multiplied by 256
  1048. */
  1049. __STATIC_INLINE uint32_t csi_cache_get_access_time (void)
  1050. {
  1051. return 0;
  1052. }
  1053. /**
  1054. \brief cache miss times
  1055. \details Cache miss times
  1056. \note every 256 miss add 1.
  1057. \return cache miss times, actual times should be multiplied by 256
  1058. */
  1059. __STATIC_INLINE uint32_t csi_cache_get_miss_time (void)
  1060. {
  1061. return 0;
  1062. }
  1063. /*@} end of CSI_Core_CacheFunctions */
  1064. /*@} end of CSI_core_DebugFunctions */
  1065. /* ################################## IRQ Functions ############################################ */
  1066. /**
  1067. \brief Save the Irq context
  1068. \details save the psr result before disable irq.
  1069. */
  1070. __STATIC_INLINE uint32_t csi_irq_save(void)
  1071. {
  1072. uint32_t result;
  1073. result = __get_MSTATUS();
  1074. __disable_irq();
  1075. return(result);
  1076. }
  1077. /**
  1078. \brief Restore the Irq context
  1079. \details restore saved primask state.
  1080. \param [in] irq_state psr irq state.
  1081. */
  1082. __STATIC_INLINE void csi_irq_restore(uint32_t irq_state)
  1083. {
  1084. __set_MSTATUS(irq_state);
  1085. }
  1086. /*@} end of IRQ Functions */
  1087. #ifdef __cplusplus
  1088. }
  1089. #endif
  1090. #endif /* __CORE_RV32_H_DEPENDANT */
  1091. #endif /* __CSI_GENERIC */