evalsoc.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. Reserved1_IRQn = 1, /*!< Internal reserved */
  68. Reserved2_IRQn = 2, /*!< Internal reserved */
  69. SysTimerSW_IRQn = 3, /*!< System Timer SW interrupt for both M/S mode in ECLIC */
  70. Reserved3_IRQn = 4, /*!< Internal reserved */
  71. Reserved4_IRQn = 5, /*!< Internal reserved */
  72. Reserved5_IRQn = 6, /*!< Internal reserved */
  73. SysTimer_IRQn = 7, /*!< System Timer Interrupt for both M/S mode in ECLIC */
  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. #ifdef CFG_HAS_CLIC
  190. /* UART0 Interrupt */
  191. /* NOTE: Take care the external uart irq may not work, it require a correct evalsoc cpu configuration */
  192. /* NOTE: For latest 200/300 cpu, this UART0_IRQn maybe SOC_INT19_IRQn */
  193. #define UART0_IRQn SOC_INT51_IRQn
  194. /* QSPI Interrupt */
  195. #define QSPI0_IRQn SOC_INT53_IRQn
  196. #define QSPI1_IRQn SOC_INT54_IRQn
  197. #define QSPI2_IRQn SOC_INT55_IRQn
  198. #else
  199. /* UART0 Interrupt */
  200. #define UART0_IRQn PLIC_INT33_IRQn
  201. /* QSPI Interrupt */
  202. #define QSPI0_IRQn PLIC_INT35_IRQn
  203. #define QSPI1_IRQn PLIC_INT36_IRQn
  204. #define QSPI2_IRQn PLIC_INT37_IRQn
  205. #endif
  206. #define PLIC_UART0_IRQn PLIC_INT33_IRQn
  207. /* =========================================================================================================================== */
  208. /* ================ Exception Code Definition ================ */
  209. /* =========================================================================================================================== */
  210. typedef enum EXCn {
  211. /* ======================================= Nuclei N/NX Specific Exception Code ======================================== */
  212. InsUnalign_EXCn = 0, /*!< Instruction address misaligned */
  213. InsAccFault_EXCn = 1, /*!< Instruction access fault */
  214. IlleIns_EXCn = 2, /*!< Illegal instruction */
  215. Break_EXCn = 3, /*!< Beakpoint */
  216. LdAddrUnalign_EXCn = 4, /*!< Load address misaligned */
  217. LdFault_EXCn = 5, /*!< Load access fault */
  218. StAddrUnalign_EXCn = 6, /*!< Store or AMO address misaligned */
  219. StAccessFault_EXCn = 7, /*!< Store or AMO access fault */
  220. UmodeEcall_EXCn = 8, /*!< Environment call from User mode */
  221. SmodeEcall_EXCn = 9, /*!< Environment call from S-mode */
  222. MmodeEcall_EXCn = 11, /*!< Environment call from Machine mode */
  223. InsPageFault_EXCn = 12, /*!< Instruction page fault */
  224. LdPageFault_EXCn = 13, /*!< Load page fault */
  225. StPageFault_EXCn = 15, /*!< Store or AMO page fault */
  226. StackOverflow_EXCn = 24, /*!< Stack overflow fault */
  227. StackUnderflow_EXCn = 25, /*!< Stack underflow fault */
  228. NMI_EXCn = 0xfff, /*!< NMI interrupt */
  229. } EXCn_Type;
  230. /* =========================================================================================================================== */
  231. /* ================ Processor and Core Peripheral Section ================ */
  232. /* =========================================================================================================================== */
  233. // NOTE: macros __NUCLEI_CORE_REV/__NUCLEI_N_REV/__NUCLEI_NX_REV are removed now
  234. // NOTE: __FPU_PRESENT/__BITMANIP_PRESENT/__DSP_PRESENT/__VECTOR_PRESENT can be probed by compiler's -march= option
  235. // See https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html
  236. /*!< Set to 0, 1, or 2, 0 not present, 1 single floating point unit present, 2 double floating point unit present */
  237. #if !defined(__riscv_flen)
  238. #define __FPU_PRESENT 0
  239. #elif __riscv_flen == 32
  240. #define __FPU_PRESENT 1
  241. #else
  242. #define __FPU_PRESENT 2
  243. #endif
  244. #if defined(__riscv_bitmanip)
  245. #define __BITMANIP_PRESENT 1 /*!< Set to 1 if Bitmainpulation extension is present */
  246. #else
  247. #define __BITMANIP_PRESENT 0 /*!< Set to 1 if Bitmainpulation extension is present */
  248. #endif
  249. #if defined(__riscv_dsp)
  250. #define __DSP_PRESENT 1 /*!< Set to 1 if Partial SIMD(DSP) extension is present */
  251. #else
  252. #define __DSP_PRESENT 0 /*!< Set to 1 if Partial SIMD(DSP) extension is present */
  253. #endif
  254. #if defined(__riscv_vector)
  255. #define __VECTOR_PRESENT 1 /*!< Set to 1 if Vector extension is present */
  256. #else
  257. #define __VECTOR_PRESENT 0 /*!< Set to 1 if Vector extension is present */
  258. #endif
  259. // CPU IREGION Private Peripherals Offset against IREGION base specified by mirgb_info CSR
  260. // These offset information can be found in selected cpu series databook's IREGION section.
  261. // mirgb_info CSR can be found in Nuclei RISC-V ISA Spec
  262. // You can also probe the cpu information using the general application/baremetal/cpuinfo case
  263. // You can find the offset macros(IREGION_*_OFS) in riscv_encoding.h via search IREGION Offsets
  264. // NORMAL CPU Configuration: From Nuclei SDK 0.6.0, we recommend you to update the CPU configuration macros defined in cpufeature.h
  265. // Please don't modify the macros below directly
  266. // NOTE: We use macros defined in cpufeature.h
  267. // WARNING: Please dont modify macros directly below, you can change in cpufeature.h
  268. // CPU Series and Version Configuration
  269. // To set CPU REV and SERIES, just define CFG_CPU_VER/CFG_CPU_SERIES macros in cpufeature.h
  270. #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 */
  271. #define __NUCLEI_CPU_SERIES CFG_CPU_SERIES /*!< Nuclei CPU Series, such as 200/300/600/900, eg. 900 will be 0x0900 */
  272. // CPU IREGION Base Address
  273. // To set IREGION base, just define macro CFG_IREGION_BASE_ADDR in cpufeature.h
  274. #ifndef CFG_IREGION_BASE_ADDR
  275. // it is defined in system_evalsoc.c, you should not use this variable CpuIRegionBase
  276. // SystemIRegionInfo variable in previous release is removed, you should avoid to use it
  277. // you should use macro __IREGION_BASEADDR defined in evalsoc.h
  278. extern volatile unsigned long CpuIRegionBase;
  279. #define CPU_IREGION_BASE CpuIRegionBase
  280. #else
  281. #define CPU_IREGION_BASE CFG_IREGION_BASE_ADDR
  282. #endif
  283. #define __IREGION_BASEADDR (CPU_IREGION_BASE)
  284. // ECLIC Configuration
  285. // To enable ECLIC, just define macro CFG_HAS_CLIC/CFG_CLICINTCTLBITS/CFG_IRQ_NUM in cpufeature.h
  286. #ifdef CFG_HAS_CLIC
  287. #define __ECLIC_PRESENT 1
  288. #ifdef CFG_CLICINTCTLBITS
  289. #define __ECLIC_INTCTLBITS CFG_CLICINTCTLBITS
  290. #endif
  291. #define __ECLIC_INTNUM (CFG_IRQ_NUM + SOC_EXTERNAL_MAP_TO_ECLIC_IRQn_OFFSET)
  292. #else
  293. #define __ECLIC_PRESENT 0
  294. #endif
  295. #define __ECLIC_BASEADDR (__IREGION_BASEADDR + IREGION_ECLIC_OFS)
  296. // PLIC Configuration
  297. // To enable PLIC, just define macro CFG_HAS_PLIC/CFG_IRQ_NUM in cpufeature.h
  298. #ifdef CFG_HAS_PLIC
  299. #define __PLIC_PRESENT 1
  300. #define __PLIC_INTNUM (CFG_IRQ_NUM + 1)
  301. #else
  302. #define __PLIC_PRESENT 0
  303. #endif
  304. #define __PLIC_BASEADDR (__IREGION_BASEADDR + IREGION_PLIC_OFS)
  305. // CPU System Timer Configuration
  306. // To enable CPU System Timer, just define macro CFG_TMR_PRIVATE in cpufeature.h
  307. #if defined(CFG_TMR_PRIVATE) || defined(CFG_TMR_BASE_ADDR)
  308. #define __SYSTIMER_PRESENT 1
  309. #else
  310. #define __SYSTIMER_PRESENT 0
  311. #endif
  312. #ifdef CFG_TMR_BASE_ADDR // Maybe using timer out of cpu for evalsoc
  313. #define __SYSTIMER_BASEADDR (CFG_TMR_BASE_ADDR)
  314. #else
  315. #define __SYSTIMER_BASEADDR (__IREGION_BASEADDR + IREGION_TIMER_OFS)
  316. #endif
  317. #define __CLINT_TIMER_BASEADDR (__SYSTIMER_BASEADDR + 0x1000)
  318. // CIDU Configuration
  319. // To enable CIDU, just define macro CFG_HAS_IDU in cpufeature.h
  320. #ifdef CFG_HAS_IDU
  321. #define __CIDU_PRESENT 1
  322. #else
  323. #define __CIDU_PRESENT 0
  324. #endif
  325. #define __CIDU_BASEADDR (__IREGION_BASEADDR + IREGION_IDU_OFS)
  326. // SMP & CC Configuration
  327. // To enable SMP & CC, just define macro CFG_HAS_SMP in cpufeature.h
  328. #ifdef CFG_HAS_SMP
  329. #define __SMPCC_PRESENT 1
  330. #else
  331. #define __SMPCC_PRESENT 0
  332. #endif
  333. #define __SMPCC_BASEADDR (__IREGION_BASEADDR + IREGION_SMP_OFS)
  334. // PMP Configuration
  335. // To enable PMP, just define macro CFG_HAS_PMP/__PMP_ENTRY_NUM in cpufeature.h
  336. #ifdef CFG_HAS_PMP
  337. #define __PMP_PRESENT 1
  338. #define __PMP_ENTRY_NUM CFG_PMP_ENTRY_NUM
  339. #else
  340. #define __PMP_PRESENT 0
  341. #define __PMP_ENTRY_NUM 0
  342. #endif
  343. // TEE/sPMP Configuration
  344. // To enable TEE, just define macro CFG_HAS_TEE in cpufeature.h
  345. // TEE required PMP, please also make sure CFG_HAS_PMP defined
  346. #ifdef CFG_HAS_TEE
  347. #define __TEE_PRESENT 1
  348. #define __SPMP_PRESENT 1
  349. #define __SPMP_ENTRY_NUM CFG_PMP_ENTRY_NUM
  350. #ifdef CFG_HAS_SMPU
  351. #define __SMPU_PRESENT 1
  352. #define __SMPU_ENTRY_NUM __SPMP_ENTRY_NUM
  353. #endif
  354. #else
  355. #define __TEE_PRESENT 0
  356. #define __SPMP_PRESENT 0
  357. #define __SMPU_PRESENT 0
  358. #define __SPMP_ENTRY_NUM 0
  359. #endif
  360. // ICache Configuration
  361. // To enable ICACHE, just define macro CFG_HAS_ICACHE in cpufeature.h
  362. #ifdef CFG_HAS_ICACHE
  363. #define __ICACHE_PRESENT 1
  364. #else
  365. #define __ICACHE_PRESENT 0
  366. #endif
  367. // DCache Configuration
  368. // To enable DCACHE, just define macro CFG_HAS_DCACHE in cpufeature.h
  369. #ifdef CFG_HAS_DCACHE
  370. #define __DCACHE_PRESENT 1
  371. #else
  372. #define __DCACHE_PRESENT 0
  373. #endif
  374. // CCM Configuration
  375. // To enable CCM, just define macro CFG_HAS_IOCC in cpufeature.h
  376. #ifdef CFG_HAS_IOCC
  377. #define __CCM_PRESENT 1
  378. #else
  379. #define __CCM_PRESENT 0
  380. #endif
  381. // NICE Configuration
  382. // To enable NICE, just define macro CFG_HAS_NICE in cpufeature.h
  383. #ifdef CFG_HAS_NICE
  384. #define __NICE_PRESENT 1
  385. #else
  386. #define __NICE_PRESENT 0
  387. #endif
  388. // VNICE Configuration
  389. // To enable Vector NICE, just define macro CFG_HAS_VNICE in cpufeature.h
  390. #ifdef CFG_HAS_VNICE
  391. #define __VNICE_PRESENT 1
  392. #else
  393. #define __VNICE_PRESENT 0
  394. #endif
  395. #ifndef __INC_INTRINSIC_API
  396. #define __INC_INTRINSIC_API 0 /*!< Set to 1 if intrinsic api header files need to be included */
  397. #endif
  398. #define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
  399. #define __Vendor_EXCEPTION 0 /*!< Set to 1 if vendor exception hander is present */
  400. /*!< Set this timer hartid if you have only 1 hart in your cpu, and you know the timer hartid, just set it */
  401. //#define __SYSTIMER_HARTID 0
  402. #ifndef __HARTID_OFFSET
  403. /**
  404. * If your hart index is different to your hartid, you must define this __HARTID_OFFSET macro.
  405. * For example, if your cpu has 4 harts, and hartid start from 3, so the __HARTID_OFFSET should set to 3.
  406. * Which means hartid 3-6 means hart index 0-3, this is useful for the timer software interrupt and timer interrupt trigger register location
  407. */
  408. #define __HARTID_OFFSET 0
  409. #endif
  410. /* Define boot hart id */
  411. #ifndef BOOT_HARTID
  412. /**
  413. * Choosen boot hart id in current cluster when in soc system, need to align with the value defined in startup_<Device>.S,
  414. * should start from 0, taken the mhartid bit 0-7 value
  415. */
  416. #define BOOT_HARTID 0
  417. #endif
  418. /** @} */ /* End of group Configuration_of_NMSIS */
  419. // NOTE: Run Mode Control internally used Nuclei
  420. // RUNMODE_* macros are defined in SoC/evalsoc/runmode.mk, for internal usage not intend for widely usage
  421. #ifdef RUNMODE_IC_EN
  422. #undef __ICACHE_PRESENT
  423. #define __ICACHE_PRESENT RUNMODE_IC_EN /*!< Controlled by macro RUNMODE_IC_EN */
  424. #endif
  425. #ifdef RUNMODE_DC_EN
  426. #undef __DCACHE_PRESENT
  427. #define __DCACHE_PRESENT RUNMODE_DC_EN /*!< Controlled by macro RUNMODE_DC_EN */
  428. #endif
  429. #ifdef RUNMODE_CCM_EN
  430. #undef __CCM_PRESENT
  431. #define __CCM_PRESENT RUNMODE_CCM_EN /*!< Controlled by macro RUNMODE_CCM_EN */
  432. #endif
  433. #include <nmsis_core.h> /*!< Nuclei N/NX class processor and core peripherals */
  434. #include "system_evalsoc.h" /*!< evalsoc System */
  435. /* ======================================== Start of section using anonymous unions ======================================== */
  436. #ifdef EVALSOC_RTC_FREQ
  437. #define RTC_FREQ EVALSOC_RTC_FREQ
  438. #else
  439. #define RTC_FREQ 32768
  440. #endif
  441. // The TIMER frequency is just the RTC frequency
  442. #define SOC_TIMER_FREQ RTC_FREQ
  443. /* =========================================================================================================================== */
  444. /* ================ Device Specific Peripheral Section ================ */
  445. /* =========================================================================================================================== */
  446. /** @addtogroup Device_Peripheral_peripherals
  447. * @{
  448. */
  449. /****************************************************************************
  450. * Platform definitions
  451. *****************************************************************************/
  452. // Interrupt Numbers, will be removed in future, please use SOC_INT_MAX - SOC_EXTERNAL_MAP_TO_ECLIC_IRQn_OFFSET
  453. #define SOC_ECLIC_NUM_INTERRUPTS (SOC_INT_MAX - SOC_EXTERNAL_MAP_TO_ECLIC_IRQn_OFFSET)
  454. // Interrupt Handler Definitions
  455. #define SOC_MTIMER_HANDLER eclic_mtip_handler
  456. #define SOC_SOFTINT_HANDLER eclic_msip_handler
  457. /**
  458. * @brief UART
  459. */
  460. typedef struct {
  461. __IOM uint32_t TXFIFO;
  462. __IOM uint32_t RXFIFO;
  463. __IOM uint32_t TXCTRL;
  464. __IOM uint32_t RXCTRL;
  465. __IOM uint32_t IE;
  466. __IOM uint32_t IP;
  467. __IOM uint32_t DIV;
  468. } UART_TypeDef;
  469. /**
  470. * @brief QSPI
  471. */
  472. typedef struct {
  473. __IOM uint32_t SCKDIV;
  474. __IOM uint32_t SCKMODE;
  475. __IOM uint32_t RESERVED0[1];
  476. __IOM uint32_t FORCE;
  477. __IOM uint32_t CSID;
  478. __IOM uint32_t CSDEF;
  479. __IOM uint32_t CSMODE;
  480. __IOM uint32_t VERSION;
  481. __IOM uint32_t RESERVED1[2];
  482. __IOM uint32_t DELAY0;
  483. __IOM uint32_t DELAY1;
  484. __IOM uint32_t RESERVED2[4];
  485. __IOM uint32_t FMT;
  486. __IOM uint32_t RESERVED3;
  487. __IOM uint32_t TXDATA;
  488. __IOM uint32_t RXDATA;
  489. __IOM uint32_t TXMARK;
  490. __IOM uint32_t RXMARK;
  491. __IOM uint32_t RESERVED4[2];
  492. __IOM uint32_t FCTRL;
  493. __IOM uint32_t FFMT;
  494. __IOM uint32_t RESERVED5[2];
  495. __IOM uint32_t IE;
  496. __IOM uint32_t IP;
  497. __IOM uint32_t FFMT1;
  498. __IOM uint32_t STATUS;
  499. } QSPI_TypeDef;
  500. /*@}*/ /* end of group evalsoc_Peripherals */
  501. /* ========================================= End of section using anonymous unions ========================================= */
  502. /* Macros for memory access operations */
  503. #define _REG8P(p, i) ((volatile uint8_t *) ((uintptr_t)((p) + (i))))
  504. #define _REG16P(p, i) ((volatile uint16_t *) ((uintptr_t)((p) + (i))))
  505. #define _REG32P(p, i) ((volatile uint32_t *) ((uintptr_t)((p) + (i))))
  506. #define _REG64P(p, i) ((volatile uint64_t *) ((uintptr_t)((p) + (i))))
  507. #define _REG8(p, i) (*(_REG8P(p, i)))
  508. #define _REG16(p, i) (*(_REG16P(p, i)))
  509. #define _REG32(p, i) (*(_REG32P(p, i)))
  510. #define _REG64(p, i) (*(_REG64P(p, i)))
  511. #define REG8(addr) _REG8((addr), 0)
  512. #define REG16(addr) _REG16((addr), 0)
  513. #define REG32(addr) _REG32((addr), 0)
  514. #define REG64(addr) _REG64((addr), 0)
  515. /* Macros for address type convert and access operations */
  516. #define ADDR16(addr) ((uint16_t)(uintptr_t)(addr))
  517. #define ADDR32(addr) ((uint32_t)(uintptr_t)(addr))
  518. #define ADDR64(addr) ((uint64_t)(uintptr_t)(addr))
  519. #define ADDR8P(addr) ((uint8_t *)(uintptr_t)(addr))
  520. #define ADDR16P(addr) ((uint16_t *)(uintptr_t)(addr))
  521. #define ADDR32P(addr) ((uint32_t *)(uintptr_t)(addr))
  522. #define ADDR64P(addr) ((uint64_t *)(uintptr_t)(addr))
  523. /* Macros for Bit Operations */
  524. #if __riscv_xlen == 32
  525. #define BITMASK_MAX 0xFFFFFFFFUL
  526. #define BITOFS_MAX 31
  527. #else
  528. #define BITMASK_MAX 0xFFFFFFFFFFFFFFFFULL
  529. #define BITOFS_MAX 63
  530. #endif
  531. // BIT/BITS only support bit mask for __riscv_xlen
  532. // For RISC-V 32 bit, it support mask 32 bit wide
  533. // For RISC-V 64 bit, it support mask 64 bit wide
  534. #define BIT(ofs) (0x1UL << (ofs))
  535. #define BITS(start, end) ((BITMASK_MAX) << (start) & (BITMASK_MAX) >> (BITOFS_MAX - (end)))
  536. #define GET_BIT(regval, bitofs) (((regval) >> (bitofs)) & 0x1)
  537. #define SET_BIT(regval, bitofs) ((regval) |= BIT(bitofs))
  538. #define CLR_BIT(regval, bitofs) ((regval) &= (~BIT(bitofs)))
  539. #define FLIP_BIT(regval, bitofs) ((regval) ^= BIT(bitofs))
  540. #define WRITE_BIT(regval, bitofs, val) CLR_BIT(regval, bitofs); ((regval) |= ((val) << bitofs) & BIT(bitofs))
  541. #define CHECK_BIT(regval, bitofs) (!!((regval) & (0x1UL<<(bitofs))))
  542. #define GET_BITS(regval, start, end) (((regval) & BITS((start), (end))) >> (start))
  543. #define SET_BITS(regval, start, end) ((regval) |= BITS((start), (end)))
  544. #define CLR_BITS(regval, start, end) ((regval) &= (~BITS((start), (end))))
  545. #define FLIP_BITS(regval, start, end) ((regval) ^= BITS((start), (end)))
  546. #define WRITE_BITS(regval, start, end, val) CLR_BITS(regval, start, end); ((regval) |= ((val) << start) & BITS((start), (end)))
  547. #define CHECK_BITS_ALL(regval, start, end) (!((~(regval)) & BITS((start), (end))))
  548. #define CHECK_BITS_ANY(regval, start, end) ((regval) & BITS((start), (end)))
  549. #define BITMASK_SET(regval, mask) ((regval) |= (mask))
  550. #define BITMASK_CLR(regval, mask) ((regval) &= (~(mask)))
  551. #define BITMASK_FLIP(regval, mask) ((regval) ^= (mask))
  552. #define BITMASK_CHECK_ALL(regval, mask) (!((~(regval)) & (mask)))
  553. #define BITMASK_CHECK_ANY(regval, mask) ((regval) & (mask))
  554. /* =========================================================================================================================== */
  555. /* ================ Device Specific Peripheral Address Map ================ */
  556. /* =========================================================================================================================== */
  557. /* ToDo: add here your device peripherals base addresses
  558. following is an example for timer */
  559. /** @addtogroup Device_Peripheral_peripheralAddr
  560. * @{
  561. */
  562. /* ILM/DLM/FLASHXIP and Peripheral base address */
  563. #ifndef EVALSOC_FLASH_XIP_BASE
  564. #define QSPI_FLASH_BASE (0x20000000UL) /*!< (FLASH ) Base Address */
  565. #else
  566. #define QSPI_FLASH_BASE (EVALSOC_FLASH_XIP_BASE) /*!< (FLASH ) Base Address */
  567. #endif
  568. #ifndef CFG_ILM_BASE_ADDR
  569. #define ONCHIP_ILM_BASE (0x80000000UL) /*!< (ILM ) Base Address */
  570. #else
  571. #define ONCHIP_ILM_BASE (CFG_ILM_BASE_ADDR) /*!< (ILM ) Base Address */
  572. #endif
  573. #ifndef CFG_DLM_BASE_ADDR
  574. #define ONCHIP_DLM_BASE (0x90000000UL) /*!< (DLM ) Base Address */
  575. #else
  576. #define ONCHIP_DLM_BASE (CFG_DLM_BASE_ADDR) /*!< (DLM ) Base Address */
  577. #endif
  578. #ifndef EVALSOC_SYSMEM_BASE
  579. #define ONCHIP_SRAM_BASE (0xA0000000UL) /*!< (SRAM ) Base Address */
  580. #else
  581. #define ONCHIP_SRAM_BASE (EVALSOC_SYSMEM_BASE) /*!< (SRAM ) Base Address */
  582. #endif
  583. #ifndef EVALSOC_PERIPS_BASE
  584. #define EVALSOC_PERIPH_BASE (0x10000000UL) /*!< (Peripheral) Base Address */
  585. #else
  586. #define EVALSOC_PERIPH_BASE (EVALSOC_PERIPS_BASE) /*!< (Peripheral) Base Address */
  587. #endif
  588. /* Peripheral memory map */
  589. #define UART0_BASE (EVALSOC_PERIPH_BASE + 0x13000) /*!< (UART0) Base Address */
  590. #define QSPI0_BASE (EVALSOC_PERIPH_BASE + 0x14000) /*!< (QSPI0) Base Address */
  591. #define UART1_BASE (EVALSOC_PERIPH_BASE + 0x23000) /*!< (UART1) Base Address */
  592. #define QSPI1_BASE (EVALSOC_PERIPH_BASE + 0x24000) /*!< (QSPI1) Base Address */
  593. #define QSPI2_BASE (EVALSOC_PERIPH_BASE + 0x34000) /*!< (QSPI2) Base Address */
  594. /** @} */ /* End of group Device_Peripheral_peripheralAddr */
  595. /* =========================================================================================================================== */
  596. /* ================ Peripheral declaration ================ */
  597. /* =========================================================================================================================== */
  598. /* ToDo: add here your device peripherals pointer definitions
  599. following is an example for timer */
  600. /** @addtogroup Device_Peripheral_declaration
  601. * @{
  602. */
  603. #define UART0 ((UART_TypeDef *) UART0_BASE)
  604. #define QSPI0 ((QSPI_TypeDef *) QSPI0_BASE)
  605. #define UART1 ((UART_TypeDef *) UART1_BASE)
  606. #define QSPI1 ((QSPI_TypeDef *) QSPI1_BASE)
  607. #define QSPI2 ((QSPI_TypeDef *) QSPI2_BASE)
  608. #define SPI0_REG(offset) _REG32(QSPI0_BASE, offset)
  609. #define SPI1_REG(offset) _REG32(QSPI1_BASE, offset)
  610. #define SPI2_REG(offset) _REG32(QSPI2_BASE, offset)
  611. #define UART0_REG(offset) _REG32(UART0_BASE, offset)
  612. #define UART1_REG(offset) _REG32(UART1_BASE, offset)
  613. // Misc
  614. // Only used by Nuclei Internally, please dont use it
  615. #define SIMULATION_EXIT(ret) { __WMB(); UART0->RXFIFO = (ret); \
  616. while (UART0->TXFIFO & (1<<31)); \
  617. UART0->TXFIFO = 4; }
  618. extern uint32_t get_cpu_freq(void);
  619. extern void delay_1ms(uint32_t count);
  620. /** @} */ /* End of group evalsoc */
  621. /** @} */ /* End of group Nuclei */
  622. #ifdef __cplusplus
  623. }
  624. #endif
  625. #endif /* __EVALSOC_H__ */