evalsoc.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /******************************************************************************
  2. * @file evalsoc.h
  3. * @brief NMSIS Core Peripheral Access Layer Header File for
  4. * Nuclei Eval SoC which support Nuclei N/NX class cores
  5. * @version V1.00
  6. * @date 22. Nov 2019
  7. ******************************************************************************/
  8. /*
  9. * Copyright (c) 2019 Nuclei Limited. All rights reserved.
  10. *
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the License); you may
  14. * not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. #ifndef __EVALSOC_H__
  26. #define __EVALSOC_H__
  27. #include <stddef.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. // NOTE: this cpufeature.h header file is introduced in Nuclei SDK 0.6.0
  32. #include "cpufeature.h"
  33. /** @addtogroup Nuclei
  34. * @{
  35. */
  36. /** @addtogroup evalsoc
  37. * @{
  38. */
  39. /** @addtogroup Configuration_of_NMSIS
  40. * @{
  41. */
  42. /** \brief SoC Download mode definition */
  43. typedef enum {
  44. DOWNLOAD_MODE_FLASHXIP = 0, /*!< Flashxip download mode */
  45. DOWNLOAD_MODE_FLASH = 1, /*!< Flash download mode */
  46. DOWNLOAD_MODE_ILM = 2, /*!< ilm download mode */
  47. DOWNLOAD_MODE_DDR = 3, /*!< ddr download mode */
  48. DOWNLOAD_MODE_SRAM = 4, /*!< sram download mode */
  49. DOWNLOAD_MODE_SRAMXIP = 5, /*!< sramxip download mode */
  50. DOWNLOAD_MODE_MAX,
  51. } DownloadMode_Type;
  52. // IRegion_Info_Type structure is removed in Nuclei SDK 0.6.0 release
  53. /* Simulation mode macros */
  54. #define SIMULATION_MODE_XLSPIKE 0 /*!< xlspike simulation mode */
  55. #define SIMULATION_MODE_QEMU 1 /*!< qemu simulation mode */
  56. /* =========================================================================================================================== */
  57. /* ================ Interrupt Number Definition ================ */
  58. /* =========================================================================================================================== */
  59. /* evalsoc's External IRQn ID is from the hard-wired persperctive, which has an offset mapped to the ECLIC IRQn.
  60. eg.: uart0's external interrupt id in evalsoc is 32, while its ECLIC IRQn is 51 */
  61. #define SOC_EXTERNAL_MAP_TO_ECLIC_IRQn_OFFSET 19
  62. /* get evalsoc's External IRQn from ECLIC external IRQn which indexs from 19 */
  63. #define IRQn_MAP_TO_EXT_ID(IRQn) (IRQn - SOC_EXTERNAL_MAP_TO_ECLIC_IRQn_OFFSET)
  64. typedef enum IRQn {
  65. /* ======================================= Nuclei Core Specific Interrupt Numbers ======================================== */
  66. Reserved0_IRQn = 0, /*!< Internal reserved */
  67. SysTimerSW_S_IRQn = 1, /*!< System Timer supervisor mode SW interrupt triggered by ssip */
  68. Reserved2_IRQn = 2, /*!< Internal reserved */
  69. SysTimerSW_IRQn = 3, /*!< System Timer machine mode SW interrupt triggered by msip */
  70. Reserved3_IRQn = 4, /*!< Internal reserved */
  71. SysTimer_S_IRQn = 5, /*!< System Timer supervisor mode interrupt triggered by stimecmp csr */
  72. Reserved5_IRQn = 6, /*!< Internal reserved */
  73. SysTimer_IRQn = 7, /*!< System Timer machine mode interrupt triggered by mtimecmp */
  74. Reserved6_IRQn = 8, /*!< Internal reserved */
  75. Reserved7_IRQn = 9, /*!< Internal reserved */
  76. Reserved8_IRQn = 10, /*!< Internal reserved */
  77. Reserved9_IRQn = 11, /*!< Internal reserved */
  78. Reserved10_IRQn = 12, /*!< Internal reserved */
  79. Reserved11_IRQn = 13, /*!< Internal reserved */
  80. Reserved12_IRQn = 14, /*!< Internal reserved */
  81. Reserved13_IRQn = 15, /*!< Internal reserved */
  82. InterCore_IRQn = 16, /*!< CIDU Inter Core Interrupt */
  83. Reserved15_IRQn = 17, /*!< Internal reserved */
  84. Reserved16_IRQn = 18, /*!< Internal reserved */
  85. /* =========================================== evalsoc Specific Interrupt Numbers ========================================= */
  86. /* ToDo: add here your device specific external interrupt numbers. 19~1023 is reserved number for user. Maxmum interrupt supported
  87. could get from clicinfo.NUM_INTERRUPT. According the interrupt handlers defined in startup_Device.s
  88. eg.: Interrupt for Timer#1 eclic_tim1_handler -> TIM1_IRQn */
  89. SOC_INT19_IRQn = 19, /*!< Device Interrupt */
  90. SOC_INT20_IRQn = 20, /*!< Device Interrupt */
  91. SOC_INT21_IRQn = 21, /*!< Device Interrupt */
  92. SOC_INT22_IRQn = 22, /*!< Device Interrupt */
  93. SOC_INT23_IRQn = 23, /*!< Device Interrupt */
  94. SOC_INT24_IRQn = 24, /*!< Device Interrupt */
  95. SOC_INT25_IRQn = 25, /*!< Device Interrupt */
  96. SOC_INT26_IRQn = 26, /*!< Device Interrupt */
  97. SOC_INT27_IRQn = 27, /*!< Device Interrupt */
  98. SOC_INT28_IRQn = 28, /*!< Device Interrupt */
  99. SOC_INT29_IRQn = 29, /*!< Device Interrupt */
  100. SOC_INT30_IRQn = 30, /*!< Device Interrupt */
  101. SOC_INT31_IRQn = 31, /*!< Device Interrupt */
  102. SOC_INT32_IRQn = 32, /*!< Device Interrupt */
  103. SOC_INT33_IRQn = 33, /*!< Device Interrupt */
  104. SOC_INT34_IRQn = 34, /*!< Device Interrupt */
  105. SOC_INT35_IRQn = 35, /*!< Device Interrupt */
  106. SOC_INT36_IRQn = 36, /*!< Device Interrupt */
  107. SOC_INT37_IRQn = 37, /*!< Device Interrupt */
  108. SOC_INT38_IRQn = 38, /*!< Device Interrupt */
  109. SOC_INT39_IRQn = 39, /*!< Device Interrupt */
  110. SOC_INT40_IRQn = 40, /*!< Device Interrupt */
  111. SOC_INT41_IRQn = 41, /*!< Device Interrupt */
  112. SOC_INT42_IRQn = 42, /*!< Device Interrupt */
  113. SOC_INT43_IRQn = 43, /*!< Device Interrupt */
  114. SOC_INT44_IRQn = 44, /*!< Device Interrupt */
  115. SOC_INT45_IRQn = 45, /*!< Device Interrupt */
  116. SOC_INT46_IRQn = 46, /*!< Device Interrupt */
  117. SOC_INT47_IRQn = 47, /*!< Device Interrupt */
  118. SOC_INT48_IRQn = 48, /*!< Device Interrupt */
  119. SOC_INT49_IRQn = 49, /*!< Device Interrupt */
  120. SOC_INT50_IRQn = 50, /*!< Device Interrupt */
  121. SOC_INT51_IRQn = 51, /*!< Device Interrupt */
  122. SOC_INT52_IRQn = 52, /*!< Device Interrupt */
  123. SOC_INT53_IRQn = 53, /*!< Device Interrupt */
  124. SOC_INT54_IRQn = 54, /*!< Device Interrupt */
  125. SOC_INT55_IRQn = 55, /*!< Device Interrupt */
  126. SOC_INT56_IRQn = 56, /*!< Device Interrupt */
  127. SOC_INT57_IRQn = 57, /*!< Device Interrupt */
  128. SOC_INT58_IRQn = 58, /*!< Device Interrupt */
  129. SOC_INT59_IRQn = 59, /*!< Device Interrupt */
  130. SOC_INT60_IRQn = 60, /*!< Device Interrupt */
  131. SOC_INT61_IRQn = 61, /*!< Device Interrupt */
  132. SOC_INT62_IRQn = 62, /*!< Device Interrupt */
  133. SOC_INT63_IRQn = 63, /*!< Device Interrupt */
  134. #if defined(CFG_IRQ_NUM)
  135. SOC_INT_MAX = CFG_IRQ_NUM + SOC_EXTERNAL_MAP_TO_ECLIC_IRQn_OFFSET,
  136. #else
  137. SOC_INT_MAX,
  138. #endif
  139. PLIC_INT0_IRQn = 0,
  140. PLIC_INT1_IRQn = 1,
  141. PLIC_INT2_IRQn = 2,
  142. PLIC_INT3_IRQn = 3,
  143. PLIC_INT4_IRQn = 4,
  144. PLIC_INT5_IRQn = 5,
  145. PLIC_INT6_IRQn = 6,
  146. PLIC_INT7_IRQn = 7,
  147. PLIC_INT8_IRQn = 8,
  148. PLIC_INT9_IRQn = 9,
  149. PLIC_INT10_IRQn = 10,
  150. PLIC_INT11_IRQn = 11,
  151. PLIC_INT12_IRQn = 12,
  152. PLIC_INT13_IRQn = 13,
  153. PLIC_INT14_IRQn = 14,
  154. PLIC_INT15_IRQn = 15,
  155. PLIC_INT16_IRQn = 16,
  156. PLIC_INT17_IRQn = 17,
  157. PLIC_INT18_IRQn = 18,
  158. PLIC_INT19_IRQn = 19,
  159. PLIC_INT20_IRQn = 20,
  160. PLIC_INT21_IRQn = 21,
  161. PLIC_INT22_IRQn = 22,
  162. PLIC_INT23_IRQn = 23,
  163. PLIC_INT24_IRQn = 24,
  164. PLIC_INT25_IRQn = 25,
  165. PLIC_INT26_IRQn = 26,
  166. PLIC_INT27_IRQn = 27,
  167. PLIC_INT28_IRQn = 28,
  168. PLIC_INT29_IRQn = 29,
  169. PLIC_INT30_IRQn = 30,
  170. PLIC_INT31_IRQn = 31,
  171. PLIC_INT32_IRQn = 32,
  172. PLIC_INT33_IRQn = 33,
  173. PLIC_INT34_IRQn = 34,
  174. PLIC_INT35_IRQn = 35,
  175. PLIC_INT36_IRQn = 36,
  176. PLIC_INT37_IRQn = 37,
  177. PLIC_INT38_IRQn = 38,
  178. PLIC_INT39_IRQn = 39,
  179. PLIC_INT40_IRQn = 40,
  180. PLIC_INT41_IRQn = 41,
  181. PLIC_INT42_IRQn = 42,
  182. PLIC_INT43_IRQn = 43,
  183. #if defined(CFG_IRQ_NUM)
  184. PLIC_INIT_MAX = CFG_IRQ_NUM + 1,
  185. #else
  186. PLIC_INIT_MAX,
  187. #endif
  188. } IRQn_Type;
  189. #if defined(CFG_IRQ_NUM) && (CFG_IRQ_NUM > 38)
  190. #define IRQn_OFFSET 0
  191. #else
  192. #define IRQn_OFFSET 32
  193. #endif
  194. #ifdef CFG_HAS_CLIC
  195. /* UART0 Interrupt */
  196. /* NOTE: Take care the external uart irq may not work, it require a correct evalsoc cpu configuration */
  197. /* NOTE: For latest 200/300 cpu, this UART0_IRQn maybe SOC_INT19_IRQn */
  198. /* Please check Interrupts of Eval_SoC section in Nuclei_Processor_Integration_Guide.pdf */
  199. #define UART0_IRQn (SOC_INT51_IRQn - IRQn_OFFSET)
  200. /* QSPI Interrupt */
  201. #define QSPI0_IRQn (SOC_INT53_IRQn - IRQn_OFFSET)
  202. #define QSPI1_IRQn (SOC_INT54_IRQn - IRQn_OFFSET)
  203. #define QSPI2_IRQn (SOC_INT55_IRQn - IRQn_OFFSET)
  204. #else
  205. /* UART0 Interrupt */
  206. #define UART0_IRQn (PLIC_INT33_IRQn - IRQn_OFFSET)
  207. /* QSPI Interrupt */
  208. #define QSPI0_IRQn (PLIC_INT35_IRQn - IRQn_OFFSET)
  209. #define QSPI1_IRQn (PLIC_INT36_IRQn - IRQn_OFFSET)
  210. #define QSPI2_IRQn (PLIC_INT37_IRQn - IRQn_OFFSET)
  211. #endif
  212. #define PLIC_UART0_IRQn (PLIC_INT33_IRQn - IRQn_OFFSET)
  213. /* =========================================================================================================================== */
  214. /* ================ Exception Code Definition ================ */
  215. /* =========================================================================================================================== */
  216. typedef enum EXCn {
  217. /* ======================================= Nuclei N/NX Specific Exception Code ======================================== */
  218. InsUnalign_EXCn = 0, /*!< Instruction address misaligned */
  219. InsAccFault_EXCn = 1, /*!< Instruction access fault */
  220. IlleIns_EXCn = 2, /*!< Illegal instruction */
  221. Break_EXCn = 3, /*!< Beakpoint */
  222. LdAddrUnalign_EXCn = 4, /*!< Load address misaligned */
  223. LdFault_EXCn = 5, /*!< Load access fault */
  224. StAddrUnalign_EXCn = 6, /*!< Store or AMO address misaligned */
  225. StAccessFault_EXCn = 7, /*!< Store or AMO access fault */
  226. UmodeEcall_EXCn = 8, /*!< Environment call from User mode */
  227. SmodeEcall_EXCn = 9, /*!< Environment call from S-mode */
  228. MmodeEcall_EXCn = 11, /*!< Environment call from Machine mode */
  229. InsPageFault_EXCn = 12, /*!< Instruction page fault */
  230. LdPageFault_EXCn = 13, /*!< Load page fault */
  231. StPageFault_EXCn = 15, /*!< Store or AMO page fault */
  232. StackOverflow_EXCn = 24, /*!< Stack overflow fault */
  233. StackUnderflow_EXCn = 25, /*!< Stack underflow fault */
  234. NMI_EXCn = 0xfff, /*!< NMI interrupt */
  235. } EXCn_Type;
  236. /* =========================================================================================================================== */
  237. /* ================ Processor and Core Peripheral Section ================ */
  238. /* =========================================================================================================================== */
  239. // NOTE: macros __NUCLEI_CORE_REV/__NUCLEI_N_REV/__NUCLEI_NX_REV are removed now
  240. // NOTE: __FPU_PRESENT/__BITMANIP_PRESENT/__DSP_PRESENT/__VECTOR_PRESENT can be probed by compiler's -march= option
  241. // See https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html
  242. /*!< Set to 0, 1, or 2, 0 not present, 1 single floating point unit present, 2 double floating point unit present */
  243. #if !defined(__riscv_flen)
  244. #define __FPU_PRESENT 0
  245. #elif __riscv_flen == 32
  246. #define __FPU_PRESENT 1
  247. #else
  248. #define __FPU_PRESENT 2
  249. #endif
  250. #if defined(__riscv_bitmanip)
  251. #define __BITMANIP_PRESENT 1 /*!< Set to 1 if Bitmainpulation extension is present */
  252. #else
  253. #define __BITMANIP_PRESENT 0 /*!< Set to 1 if Bitmainpulation extension is present */
  254. #endif
  255. #if defined(__riscv_dsp)
  256. #define __DSP_PRESENT 1 /*!< Set to 1 if Partial SIMD(DSP) extension is present */
  257. #else
  258. #define __DSP_PRESENT 0 /*!< Set to 1 if Partial SIMD(DSP) extension is present */
  259. #endif
  260. #if defined(__riscv_vector)
  261. #define __VECTOR_PRESENT 1 /*!< Set to 1 if Vector extension is present */
  262. #else
  263. #define __VECTOR_PRESENT 0 /*!< Set to 1 if Vector extension is present */
  264. #endif
  265. // CPU IREGION Private Peripherals Offset against IREGION base specified by mirgb_info CSR
  266. // These offset information can be found in selected cpu series databook's IREGION section.
  267. // mirgb_info CSR can be found in Nuclei RISC-V ISA Spec
  268. // You can also probe the cpu information using the general application/baremetal/cpuinfo case
  269. // You can find the offset macros(IREGION_*_OFS) in riscv_encoding.h via search IREGION Offsets
  270. // NORMAL CPU Configuration: From Nuclei SDK 0.6.0, we recommend you to update the CPU configuration macros defined in cpufeature.h
  271. // Please don't modify the macros below directly
  272. // NOTE: We use macros defined in cpufeature.h
  273. // WARNING: Please dont modify macros directly below, you can change in cpufeature.h
  274. // CPU Series and Version Configuration
  275. // To set CPU REV and SERIES, just define CFG_CPU_VER/CFG_CPU_SERIES macros in cpufeature.h
  276. #define __NUCLEI_CPU_REV CFG_CPU_VER /*!< Nuclei CPU Core Revision, version X.Y.Z, this is for the CPU Core Version, you get from Nuclei, eg. N300 v3.10.1, it should be 0x030A01 */
  277. #define __NUCLEI_CPU_SERIES CFG_CPU_SERIES /*!< Nuclei CPU Series, such as 200/300/600/900, eg. 900 will be 0x0900 */
  278. // CPU IREGION Base Address
  279. // To set IREGION base, just define macro CFG_IREGION_BASE_ADDR in cpufeature.h
  280. #ifndef CFG_IREGION_BASE_ADDR
  281. // it is defined in system_evalsoc.c, you should not use this variable CpuIRegionBase
  282. // SystemIRegionInfo variable in previous release is removed, you should avoid to use it
  283. // you should use macro __IREGION_BASEADDR defined in evalsoc.h
  284. extern volatile unsigned long CpuIRegionBase;
  285. #define CPU_IREGION_BASE CpuIRegionBase
  286. #else
  287. #define CPU_IREGION_BASE CFG_IREGION_BASE_ADDR
  288. #endif
  289. #define __IREGION_BASEADDR (CPU_IREGION_BASE)
  290. #define __IINFO_BASEADDR (__IREGION_BASEADDR + IREGION_IINFO_OFS)
  291. #define __IINFO_MPASIZE_OFS 0
  292. #define __IINFO_MPASIZE_ADDR (__IINFO_BASEADDR + __IINFO_MPASIZE_OFS)
  293. // ECLIC Configuration
  294. // To enable ECLIC, just define macro CFG_HAS_CLIC/CFG_CLICINTCTLBITS/CFG_IRQ_NUM in cpufeature.h
  295. #ifdef CFG_HAS_CLIC
  296. #define __ECLIC_PRESENT 1
  297. #ifdef CFG_CLICINTCTLBITS
  298. #define __ECLIC_INTCTLBITS CFG_CLICINTCTLBITS
  299. #endif
  300. #define __ECLIC_INTNUM (CFG_IRQ_NUM + SOC_EXTERNAL_MAP_TO_ECLIC_IRQn_OFFSET)
  301. #if defined(CFG_HAS_ECLICV2)
  302. #define __ECLIC_VER 2
  303. #else
  304. #define __ECLIC_VER 1
  305. #endif
  306. #else
  307. #define __ECLIC_PRESENT 0
  308. #endif
  309. #define __ECLIC_BASEADDR (__IREGION_BASEADDR + IREGION_ECLIC_OFS)
  310. // PLIC Configuration
  311. // To enable PLIC, just define macro CFG_HAS_PLIC/CFG_IRQ_NUM in cpufeature.h
  312. #ifdef CFG_HAS_PLIC
  313. #define __PLIC_PRESENT 1
  314. #define __PLIC_INTNUM (CFG_IRQ_NUM + 1)
  315. #else
  316. #define __PLIC_PRESENT 0
  317. #endif
  318. #define __PLIC_BASEADDR (__IREGION_BASEADDR + IREGION_PLIC_OFS)
  319. // CPU System Timer Configuration
  320. // To enable CPU System Timer, just define macro CFG_TMR_PRIVATE in cpufeature.h
  321. #if defined(CFG_TMR_PRIVATE) || defined(CFG_TMR_BASE_ADDR)
  322. #define __SYSTIMER_PRESENT 1
  323. #else
  324. #define __SYSTIMER_PRESENT 0
  325. #endif
  326. #ifdef CFG_TMR_BASE_ADDR // Maybe using timer out of cpu for evalsoc
  327. #define __SYSTIMER_BASEADDR (CFG_TMR_BASE_ADDR)
  328. #else
  329. #define __SYSTIMER_BASEADDR (__IREGION_BASEADDR + IREGION_TIMER_OFS)
  330. #endif
  331. #define __CLINT_TIMER_BASEADDR (__SYSTIMER_BASEADDR + 0x1000)
  332. // CPU System Timer SSTC Configuration
  333. #if defined(CFG_HAS_ISA_SSTC)
  334. #define __SSTC_PRESENT 1
  335. #else
  336. #define __SSTC_PRESENT 0
  337. #endif
  338. // CIDU Configuration
  339. // To enable CIDU, just define macro CFG_HAS_IDU in cpufeature.h
  340. #ifdef CFG_HAS_IDU
  341. #define __CIDU_PRESENT 1
  342. #else
  343. #define __CIDU_PRESENT 0
  344. #endif
  345. #define __CIDU_BASEADDR (__IREGION_BASEADDR + IREGION_IDU_OFS)
  346. // SMP & CC Configuration
  347. // To enable SMP & CC, just define macro CFG_HAS_SMP in cpufeature.h
  348. #ifdef CFG_HAS_SMP
  349. #define __SMPCC_PRESENT 1
  350. #else
  351. #define __SMPCC_PRESENT 0
  352. #endif
  353. #define __SMPCC_BASEADDR (__IREGION_BASEADDR + IREGION_SMP_OFS)
  354. // PMP Configuration
  355. // To enable PMP, just define macro CFG_HAS_PMP/__PMP_ENTRY_NUM in cpufeature.h
  356. #ifdef CFG_HAS_PMP
  357. #define __PMP_PRESENT 1
  358. #define __PMP_ENTRY_NUM CFG_PMP_ENTRY_NUM
  359. #else
  360. #define __PMP_PRESENT 0
  361. #define __PMP_ENTRY_NUM 0
  362. #endif
  363. // TEE/sPMP Configuration
  364. // To enable TEE, just define macro CFG_HAS_TEE in cpufeature.h
  365. // TEE required PMP, please also make sure CFG_HAS_PMP defined
  366. #ifdef CFG_HAS_TEE
  367. #define __TEE_PRESENT 1
  368. #define __SPMP_PRESENT 1
  369. #if CFG_PMP_ENTRY_NUM > 16
  370. #define __SPMP_ENTRY_NUM 16
  371. #else
  372. #define __SPMP_ENTRY_NUM CFG_PMP_ENTRY_NUM
  373. #endif
  374. #ifdef CFG_HAS_SMPU
  375. #define __SMPU_PRESENT 1
  376. #if CFG_PMP_ENTRY_NUM > 16
  377. #define __SMPU_ENTRY_NUM 16
  378. #else
  379. #define __SMPU_ENTRY_NUM CFG_PMP_ENTRY_NUM
  380. #endif
  381. #endif
  382. #else
  383. #define __TEE_PRESENT 0
  384. #define __SPMP_PRESENT 0
  385. #define __SMPU_PRESENT 0
  386. #define __SPMP_ENTRY_NUM 0
  387. #endif
  388. // ICache Configuration
  389. // To enable ICACHE, just define macro CFG_HAS_ICACHE in cpufeature.h
  390. #ifdef CFG_HAS_ICACHE
  391. #define __ICACHE_PRESENT 1
  392. #else
  393. #define __ICACHE_PRESENT 0
  394. #endif
  395. // DCache Configuration
  396. // To enable DCACHE, just define macro CFG_HAS_DCACHE in cpufeature.h
  397. #ifdef CFG_HAS_DCACHE
  398. #define __DCACHE_PRESENT 1
  399. #else
  400. #define __DCACHE_PRESENT 0
  401. #endif
  402. // CCM Configuration
  403. // To enable CCM, just define macro CFG_HAS_IOCC in cpufeature.h
  404. #ifdef CFG_HAS_IOCC
  405. #define __CCM_PRESENT 1
  406. #else
  407. #define __CCM_PRESENT 0
  408. #endif
  409. // PMA Configuration
  410. // To enable PMA, just define macro CFG_HAS_PMA in cpufeature.h
  411. #ifdef CFG_HAS_PMA
  412. #define __PMA_PRESENT 1
  413. #define __PMA_CSR_NUM CFG_PMA_CSR_NUM
  414. #define __PMA_SEC_CSR_NUM CFG_PMA_SEC_CSR_NUM
  415. #ifdef CFG_HAS_PMA_MACRO
  416. #define __PMA_MACRO_PRESENT 1
  417. #else
  418. #define __PMA_MACRO_PRESENT 0
  419. #endif
  420. #else
  421. #define __PMA_PRESENT 0
  422. #define __PMA_MACRO_PRESENT 0
  423. #endif
  424. // HPM Configuration
  425. // To enable HPM, just define macro CFG_HAS_HPM in cpufeature.h
  426. #ifdef CFG_HAS_HPM
  427. #define __HPM_PRESENT 1
  428. #define __HPM_VER CFG_HPM_VER
  429. #endif
  430. // SMODE Configuration
  431. // To enable S-Mode, just define macro CFG_HAS_SMODE in cpufeature.h
  432. #ifdef CFG_HAS_SMODE
  433. #define __SMODE_PRESENT 1
  434. #endif
  435. // NICE Configuration
  436. // To enable NICE, just define macro CFG_HAS_NICE in cpufeature.h
  437. #ifdef CFG_HAS_NICE
  438. #define __NICE_PRESENT 1
  439. #else
  440. #define __NICE_PRESENT 0
  441. #endif
  442. // VNICE Configuration
  443. // To enable Vector NICE, just define macro CFG_HAS_VNICE in cpufeature.h
  444. #ifdef CFG_HAS_VNICE
  445. #define __VNICE_PRESENT 1
  446. #else
  447. #define __VNICE_PRESENT 0
  448. #endif
  449. // Physical Address Size (PASIZE) Configuration
  450. #ifdef CFG_PA_SIZE
  451. #define __CPU_PA_SIZE CFG_PA_SIZE
  452. #else
  453. #define __CPU_PA_SIZE 32
  454. #endif
  455. #ifndef __INC_INTRINSIC_API
  456. #define __INC_INTRINSIC_API 0 /*!< Set to 1 if intrinsic api header files need to be included */
  457. #endif
  458. #define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
  459. #define __Vendor_EXCEPTION 0 /*!< Set to 1 if vendor exception hander is present */
  460. /*!< Set this timer hartid if you have only 1 hart in your cpu, and you know the timer hartid, just set it */
  461. //#define __SYSTIMER_HARTID 0
  462. #ifndef __HARTID_OFFSET
  463. /**
  464. * If your hart index is different to your hartid, you must define this __HARTID_OFFSET macro.
  465. * For example, if your cpu has 4 harts, and hartid start from 3, so the __HARTID_OFFSET should set to 3.
  466. * Which means hartid 3-6 means hart index 0-3, this is useful for the timer software interrupt and timer interrupt trigger register location
  467. */
  468. #define __HARTID_OFFSET 0
  469. #endif
  470. /* Define boot hart id */
  471. #ifndef BOOT_HARTID
  472. /**
  473. * Choosen boot hart id in current cluster when in soc system, need to align with the value defined in startup_<Device>.S,
  474. * should start from 0, taken the mhartid bit 0-7 value
  475. */
  476. #define BOOT_HARTID 0
  477. #endif
  478. /** @} */ /* End of group Configuration_of_NMSIS */
  479. // NOTE: Run Mode Control internally used Nuclei
  480. // RUNMODE_* macros are defined in SoC/evalsoc/runmode.mk, for internal usage not intend for widely usage
  481. #ifdef RUNMODE_IC_EN
  482. #undef __ICACHE_PRESENT
  483. #define __ICACHE_PRESENT RUNMODE_IC_EN /*!< Controlled by macro RUNMODE_IC_EN */
  484. #endif
  485. #ifdef RUNMODE_DC_EN
  486. #undef __DCACHE_PRESENT
  487. #define __DCACHE_PRESENT RUNMODE_DC_EN /*!< Controlled by macro RUNMODE_DC_EN */
  488. #endif
  489. #ifdef RUNMODE_CCM_EN
  490. #undef __CCM_PRESENT
  491. #define __CCM_PRESENT RUNMODE_CCM_EN /*!< Controlled by macro RUNMODE_CCM_EN */
  492. #endif
  493. #include <nmsis_core.h> /*!< Nuclei N/NX class processor and core peripherals */
  494. #include "system_evalsoc.h" /*!< evalsoc System */
  495. /* ======================================== Start of section using anonymous unions ======================================== */
  496. #ifdef EVALSOC_RTC_FREQ
  497. #define RTC_FREQ EVALSOC_RTC_FREQ
  498. #else
  499. #define RTC_FREQ 32768
  500. #endif
  501. // The TIMER frequency is just the RTC frequency
  502. #define SOC_TIMER_FREQ RTC_FREQ
  503. /* =========================================================================================================================== */
  504. /* ================ Device Specific Peripheral Section ================ */
  505. /* =========================================================================================================================== */
  506. /** @addtogroup Device_Peripheral_peripherals
  507. * @{
  508. */
  509. /****************************************************************************
  510. * Platform definitions
  511. *****************************************************************************/
  512. // Interrupt Numbers, will be removed in future, please use SOC_INT_MAX - SOC_EXTERNAL_MAP_TO_ECLIC_IRQn_OFFSET
  513. #define SOC_ECLIC_NUM_INTERRUPTS (SOC_INT_MAX - SOC_EXTERNAL_MAP_TO_ECLIC_IRQn_OFFSET)
  514. // Interrupt Handler Definitions
  515. #define SOC_MTIMER_HANDLER eclic_mtip_handler
  516. #define SOC_SOFTINT_HANDLER eclic_msip_handler
  517. /**
  518. * @brief UART
  519. */
  520. typedef struct {
  521. __IOM uint32_t TXFIFO;
  522. __IOM uint32_t RXFIFO;
  523. __IOM uint32_t TXCTRL;
  524. __IOM uint32_t RXCTRL;
  525. __IOM uint32_t IE;
  526. __IOM uint32_t IP;
  527. __IOM uint32_t DIV;
  528. } UART_TypeDef;
  529. /**
  530. * @brief QSPI
  531. */
  532. typedef struct {
  533. __IOM uint32_t SCKDIV;
  534. __IOM uint32_t SCKMODE;
  535. __IOM uint32_t RESERVED0[1];
  536. __IOM uint32_t FORCE;
  537. __IOM uint32_t CSID;
  538. __IOM uint32_t CSDEF;
  539. __IOM uint32_t CSMODE;
  540. __IOM uint32_t VERSION;
  541. __IOM uint32_t RESERVED1[2];
  542. __IOM uint32_t DELAY0;
  543. __IOM uint32_t DELAY1;
  544. __IOM uint32_t RESERVED2[4];
  545. __IOM uint32_t FMT;
  546. __IOM uint32_t RESERVED3;
  547. __IOM uint32_t TXDATA;
  548. __IOM uint32_t RXDATA;
  549. __IOM uint32_t TXMARK;
  550. __IOM uint32_t RXMARK;
  551. __IOM uint32_t RESERVED4[2];
  552. __IOM uint32_t FCTRL;
  553. __IOM uint32_t FFMT;
  554. __IOM uint32_t RESERVED5[2];
  555. __IOM uint32_t IE;
  556. __IOM uint32_t IP;
  557. __IOM uint32_t FFMT1;
  558. __IOM uint32_t STATUS;
  559. } QSPI_TypeDef;
  560. /*@}*/ /* end of group evalsoc_Peripherals */
  561. /* ========================================= End of section using anonymous unions ========================================= */
  562. /* Macros for memory access operations */
  563. #define _REG8P(p, i) ((volatile uint8_t *) ((uintptr_t)((p) + (i))))
  564. #define _REG16P(p, i) ((volatile uint16_t *) ((uintptr_t)((p) + (i))))
  565. #define _REG32P(p, i) ((volatile uint32_t *) ((uintptr_t)((p) + (i))))
  566. #define _REG64P(p, i) ((volatile uint64_t *) ((uintptr_t)((p) + (i))))
  567. #define _REG8(p, i) (*(_REG8P(p, i)))
  568. #define _REG16(p, i) (*(_REG16P(p, i)))
  569. #define _REG32(p, i) (*(_REG32P(p, i)))
  570. #define _REG64(p, i) (*(_REG64P(p, i)))
  571. #define REG8(addr) _REG8((addr), 0)
  572. #define REG16(addr) _REG16((addr), 0)
  573. #define REG32(addr) _REG32((addr), 0)
  574. #define REG64(addr) _REG64((addr), 0)
  575. /* Macros for address type convert and access operations */
  576. #define ADDR16(addr) ((uint16_t)(uintptr_t)(addr))
  577. #define ADDR32(addr) ((uint32_t)(uintptr_t)(addr))
  578. #define ADDR64(addr) ((uint64_t)(uintptr_t)(addr))
  579. #define ADDR8P(addr) ((uint8_t *)(uintptr_t)(addr))
  580. #define ADDR16P(addr) ((uint16_t *)(uintptr_t)(addr))
  581. #define ADDR32P(addr) ((uint32_t *)(uintptr_t)(addr))
  582. #define ADDR64P(addr) ((uint64_t *)(uintptr_t)(addr))
  583. /* Macros for Bit Operations */
  584. #if __riscv_xlen == 32
  585. #define BITMASK_MAX 0xFFFFFFFFUL
  586. #define BITOFS_MAX 31
  587. #else
  588. #define BITMASK_MAX 0xFFFFFFFFFFFFFFFFULL
  589. #define BITOFS_MAX 63
  590. #endif
  591. // BIT/BITS only support bit mask for __riscv_xlen
  592. // For RISC-V 32 bit, it support mask 32 bit wide
  593. // For RISC-V 64 bit, it support mask 64 bit wide
  594. #define BIT(ofs) (0x1UL << (ofs))
  595. #define BITS(start, end) ((BITMASK_MAX) << (start) & (BITMASK_MAX) >> (BITOFS_MAX - (end)))
  596. #define GET_BIT(regval, bitofs) (((regval) >> (bitofs)) & 0x1)
  597. #define SET_BIT(regval, bitofs) ((regval) |= BIT(bitofs))
  598. #define CLR_BIT(regval, bitofs) ((regval) &= (~BIT(bitofs)))
  599. #define FLIP_BIT(regval, bitofs) ((regval) ^= BIT(bitofs))
  600. #define WRITE_BIT(regval, bitofs, val) CLR_BIT(regval, bitofs); ((regval) |= ((val) << bitofs) & BIT(bitofs))
  601. #define CHECK_BIT(regval, bitofs) (!!((regval) & (0x1UL<<(bitofs))))
  602. #define GET_BITS(regval, start, end) (((regval) & BITS((start), (end))) >> (start))
  603. #define SET_BITS(regval, start, end) ((regval) |= BITS((start), (end)))
  604. #define CLR_BITS(regval, start, end) ((regval) &= (~BITS((start), (end))))
  605. #define FLIP_BITS(regval, start, end) ((regval) ^= BITS((start), (end)))
  606. #define WRITE_BITS(regval, start, end, val) CLR_BITS(regval, start, end); ((regval) |= ((val) << start) & BITS((start), (end)))
  607. #define CHECK_BITS_ALL(regval, start, end) (!((~(regval)) & BITS((start), (end))))
  608. #define CHECK_BITS_ANY(regval, start, end) ((regval) & BITS((start), (end)))
  609. #define BITMASK_SET(regval, mask) ((regval) |= (mask))
  610. #define BITMASK_CLR(regval, mask) ((regval) &= (~(mask)))
  611. #define BITMASK_FLIP(regval, mask) ((regval) ^= (mask))
  612. #define BITMASK_CHECK_ALL(regval, mask) (!((~(regval)) & (mask)))
  613. #define BITMASK_CHECK_ANY(regval, mask) ((regval) & (mask))
  614. /* =========================================================================================================================== */
  615. /* ================ Device Specific Peripheral Address Map ================ */
  616. /* =========================================================================================================================== */
  617. /* ToDo: add here your device peripherals base addresses
  618. following is an example for timer */
  619. /** @addtogroup Device_Peripheral_peripheralAddr
  620. * @{
  621. */
  622. /* ILM/DLM/FLASHXIP and Peripheral base address */
  623. #ifndef EVALSOC_FLASH_XIP_BASE
  624. #define QSPI_FLASH_BASE (0x20000000UL) /*!< (FLASH ) Base Address */
  625. #else
  626. #define QSPI_FLASH_BASE (EVALSOC_FLASH_XIP_BASE) /*!< (FLASH ) Base Address */
  627. #endif
  628. #ifndef CFG_ILM_BASE_ADDR
  629. #define ONCHIP_ILM_BASE (0x80000000UL) /*!< (ILM ) Base Address */
  630. #else
  631. #define ONCHIP_ILM_BASE (CFG_ILM_BASE_ADDR) /*!< (ILM ) Base Address */
  632. #endif
  633. #ifndef CFG_DLM_BASE_ADDR
  634. #define ONCHIP_DLM_BASE (0x90000000UL) /*!< (DLM ) Base Address */
  635. #else
  636. #define ONCHIP_DLM_BASE (CFG_DLM_BASE_ADDR) /*!< (DLM ) Base Address */
  637. #endif
  638. #ifndef EVALSOC_SYSMEM_BASE
  639. #define ONCHIP_SRAM_BASE (0xA0000000UL) /*!< (SRAM ) Base Address */
  640. #else
  641. #define ONCHIP_SRAM_BASE (EVALSOC_SYSMEM_BASE) /*!< (SRAM ) Base Address */
  642. #endif
  643. #ifndef EVALSOC_PERIPS_BASE
  644. #define EVALSOC_PERIPH_BASE (0x10000000UL) /*!< (Peripheral) Base Address */
  645. #else
  646. #define EVALSOC_PERIPH_BASE (EVALSOC_PERIPS_BASE) /*!< (Peripheral) Base Address */
  647. #endif
  648. /* Peripheral memory map */
  649. #define UART0_BASE (EVALSOC_PERIPH_BASE + 0x13000) /*!< (UART0) Base Address */
  650. #define QSPI0_BASE (EVALSOC_PERIPH_BASE + 0x14000) /*!< (QSPI0) Base Address */
  651. #define UART1_BASE (EVALSOC_PERIPH_BASE + 0x23000) /*!< (UART1) Base Address */
  652. #define QSPI1_BASE (EVALSOC_PERIPH_BASE + 0x24000) /*!< (QSPI1) Base Address */
  653. #define QSPI2_BASE (EVALSOC_PERIPH_BASE + 0x34000) /*!< (QSPI2) Base Address */
  654. /** @} */ /* End of group Device_Peripheral_peripheralAddr */
  655. /* =========================================================================================================================== */
  656. /* ================ Peripheral declaration ================ */
  657. /* =========================================================================================================================== */
  658. /* ToDo: add here your device peripherals pointer definitions
  659. following is an example for timer */
  660. /** @addtogroup Device_Peripheral_declaration
  661. * @{
  662. */
  663. #define UART0 ((UART_TypeDef *) UART0_BASE)
  664. #define QSPI0 ((QSPI_TypeDef *) QSPI0_BASE)
  665. #define UART1 ((UART_TypeDef *) UART1_BASE)
  666. #define QSPI1 ((QSPI_TypeDef *) QSPI1_BASE)
  667. #define QSPI2 ((QSPI_TypeDef *) QSPI2_BASE)
  668. #define SPI0_REG(offset) _REG32(QSPI0_BASE, offset)
  669. #define SPI1_REG(offset) _REG32(QSPI1_BASE, offset)
  670. #define SPI2_REG(offset) _REG32(QSPI2_BASE, offset)
  671. #define UART0_REG(offset) _REG32(UART0_BASE, offset)
  672. #define UART1_REG(offset) _REG32(UART1_BASE, offset)
  673. // Misc
  674. // Only used by Nuclei Internally, please dont use it
  675. #define SIMULATION_EXIT(ret) { __WMB(); UART0->RXFIFO = (ret); \
  676. while (UART0->TXFIFO & (1<<31)); \
  677. UART0->TXFIFO = 4; }
  678. extern uint32_t get_cpu_freq(void);
  679. extern void delay_1ms(uint32_t count);
  680. /** @} */ /* End of group evalsoc */
  681. /** @} */ /* End of group Nuclei */
  682. #ifdef __cplusplus
  683. }
  684. #endif
  685. #endif /* __EVALSOC_H__ */