evalsoc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 N100 SDK 0.1.0
  32. // TODO: please update this cpufeature.h header file content according to your SoC specification
  33. #include "cpufeature.h"
  34. /** @addtogroup Nuclei
  35. * @{
  36. */
  37. /** @addtogroup evalsoc
  38. * @{
  39. */
  40. /** @addtogroup Configuration_of_NMSIS
  41. * @{
  42. */
  43. /** \brief SoC Download mode definition */
  44. typedef enum {
  45. DOWNLOAD_MODE_FLASHXIP = 0, /*!< Flashxip download mode */
  46. DOWNLOAD_MODE_FLASH = 1, /*!< Flash download mode */
  47. DOWNLOAD_MODE_ILM = 2, /*!< ilm download mode */
  48. DOWNLOAD_MODE_DDR = 3, /*!< ddr download mode */
  49. DOWNLOAD_MODE_SRAM = 4, /*!< sram download mode */
  50. DOWNLOAD_MODE_MAX,
  51. } DownloadMode_Type;
  52. /* Simulation mode macros, internal usage */
  53. #define SIMULATION_MODE_XLSPIKE 0 /*!< xlspike simulation mode */
  54. #define SIMULATION_MODE_QEMU 1 /*!< qemu simulation mode */
  55. /* =========================================================================================================================== */
  56. /* ================ Interrupt Number Definition ================ */
  57. /* =========================================================================================================================== */
  58. typedef enum IRQn {
  59. /* ======================================= Nuclei N100 Core Internal Specific Interrupt Numbers ======================================== */
  60. SysTimerSW_IRQn = 0, /*!< CPU Timer SW interrupt for m-mode in IRQC */
  61. SysTimer_IRQn = 1, /*!< CPU Timer Interrupt for m-mode in IRQC */
  62. /* =========================================== evalsoc Specific Interrupt Numbers ========================================= */
  63. /* ToDo: add here your device specific external interrupt numbers.2~31 is reserved number for user. Maxmum interrupt supported
  64. could get from irqcinfo.NUM_INTERRUPT. According the interrupt handlers defined in system_<Device>.c
  65. eg.: Interrupt for Timer#1 irqc_tim1_handler -> TIM1_IRQn */
  66. SOC_INT2_IRQn = 2, /*!< Device Interrupt */
  67. SOC_INT3_IRQn = 3, /*!< Device Interrupt */
  68. SOC_INT4_IRQn = 4, /*!< Device Interrupt */
  69. SOC_INT5_IRQn = 5, /*!< Device Interrupt */
  70. SOC_INT6_IRQn = 6, /*!< Device Interrupt */
  71. SOC_INT7_IRQn = 7, /*!< Device Interrupt */
  72. SOC_INT8_IRQn = 8, /*!< Device Interrupt */
  73. SOC_INT9_IRQn = 9, /*!< Device Interrupt */
  74. SOC_INT10_IRQn = 10, /*!< Device Interrupt */
  75. SOC_INT11_IRQn = 11, /*!< Device Interrupt */
  76. SOC_INT12_IRQn = 12, /*!< Device Interrupt */
  77. SOC_INT13_IRQn = 13, /*!< Device Interrupt */
  78. SOC_INT14_IRQn = 14, /*!< Device Interrupt */
  79. SOC_INT15_IRQn = 15, /*!< Device Interrupt */
  80. SOC_INT16_IRQn = 16, /*!< Device Interrupt */
  81. SOC_INT17_IRQn = 17, /*!< Device Interrupt */
  82. #ifdef CFG_IRQ_NUM
  83. SOC_INT_MAX = 2 + CFG_IRQ_NUM, /*!< Two fixed cpu interrupt and max 30 external interrupt */
  84. #else
  85. SOC_INT_MAX,
  86. #endif
  87. } IRQn_Type;
  88. // TODO need to adapt for n100 soc
  89. #define UART0_IRQn SOC_INT2_IRQn
  90. //#define UART1_IRQn SOC_INT3_IRQn
  91. #define QSPI0_IRQn SOC_INT4_IRQn
  92. #define QSPI1_IRQn SOC_INT5_IRQn
  93. #define QSPI2_IRQn SOC_INT6_IRQn
  94. /* =========================================================================================================================== */
  95. /* ================ Exception Code Definition ================ */
  96. /* =========================================================================================================================== */
  97. typedef enum EXCn {
  98. /* ======================================= Nuclei N/NX Specific Exception Code ======================================== */
  99. InsUnalign_EXCn = 0, /*!< Instruction address misaligned */
  100. InsAccFault_EXCn = 1, /*!< Instruction access fault */
  101. IlleIns_EXCn = 2, /*!< Illegal instruction */
  102. Break_EXCn = 3, /*!< Beakpoint */
  103. LdAddrUnalign_EXCn = 4, /*!< Load address misaligned */
  104. LdFault_EXCn = 5, /*!< Load access fault */
  105. StAddrUnalign_EXCn = 6, /*!< Store or AMO address misaligned */
  106. StAccessFault_EXCn = 7, /*!< Store or AMO access fault */
  107. UmodeEcall_EXCn = 8, /*!< Environment call from User mode */
  108. SmodeEcall_EXCn = 9, /*!< Environment call from S-mode */
  109. MmodeEcall_EXCn = 11, /*!< Environment call from Machine mode */
  110. InsPageFault_EXCn = 12, /*!< Instruction page fault */
  111. LdPageFault_EXCn = 13, /*!< Load page fault */
  112. StPageFault_EXCn = 15, /*!< Store or AMO page fault */
  113. StackOverflow_EXCn = 24, /*!< Stack overflow fault */
  114. StackUnderflow_EXCn = 25, /*!< Stack underflow fault */
  115. NMI_EXCn = 0xfff, /*!< NMI interrupt */
  116. } EXCn_Type;
  117. /* =========================================================================================================================== */
  118. /* ================ Processor and Core Peripheral Section ================ */
  119. /* =========================================================================================================================== */
  120. // NOTE: We use macros defined in cpufeature.h
  121. // WARNING: Please dont modify macros directly below, you can change in cpufeature.h
  122. // CPU Series and Version Configuration
  123. // To set CPU REV and SERIES, just define CFG_CPU_VER/CFG_CPU_SERIES macros in cpufeature.h
  124. #define __NUCLEI_CPU_REV CFG_CPU_VER /*!< Nuclei CPU Core Revision, version X.Y.Z */
  125. #define __NUCLEI_CPU_SERIES CFG_CPU_SERIES /*!< Nuclei CPU Series */
  126. // IRQC Configuration
  127. // To enable IRQC, just define macro CFG_HAS_IRQC/CFG_IRQ_NUM in cpufeature.h
  128. #ifdef CFG_HAS_IRQC
  129. #define __IRQC_PRESENT 1
  130. #define __IRQC_INTNUM (CFG_IRQ_NUM + 2)
  131. #else
  132. #define __IRQC_PRESENT 0
  133. #endif
  134. // Exception Configuration
  135. // To enable Exception, just define macro CFG_HAS_EXCP in cpufeature.h
  136. #ifdef CFG_HAS_EXCP
  137. #define __EXCP_PRESENT 1
  138. #else
  139. #define __EXCP_PRESENT 0
  140. #endif
  141. // Performance Monitor Configuration
  142. // To enable PMON, just define macro CFG_HAS_PMONITOR in cpufeature.h
  143. #ifdef CFG_HAS_PMONITOR
  144. #define __PMON_PRESENT 1
  145. #else
  146. #define __PMON_PRESENT 0
  147. #endif
  148. // TIMER Configuration
  149. // To enable TIMER, just define macro CFG_TMR_PRIVATE in cpufeature.h
  150. #ifdef CFG_TMR_PRIVATE
  151. #define __TIMER_PRESENT 1
  152. #else
  153. #define __TIMER_PRESENT 0
  154. #endif
  155. #define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
  156. #define __Vendor_EXCEPTION 0 /*!< Set to 1 if vendor exception hander is present */
  157. /** @} */ /* End of group Configuration_of_NMSIS */
  158. #include <nmsis_core.h> /*!< Nuclei N/NX class processor and core peripherals */
  159. /* ToDo: include your system_evalsoc.h file
  160. replace 'Device' with your device name */
  161. #include "system_evalsoc.h" /*!< evalsoc System */
  162. /* ======================================== Start of section using anonymous unions ======================================== */
  163. #ifdef EVALSOC_RTC_FREQ
  164. #define RTC_FREQ EVALSOC_RTC_FREQ
  165. #else
  166. #define RTC_FREQ 32768
  167. #endif
  168. // The TIMER frequency is just the RTC frequency
  169. // TODO change it for your real soc timer frequency
  170. #define SOC_TIMER_FREQ RTC_FREQ
  171. /* =========================================================================================================================== */
  172. /* ================ Device Specific Peripheral Section ================ */
  173. /* =========================================================================================================================== */
  174. /** @addtogroup Device_Peripheral_peripherals
  175. * @{
  176. */
  177. /****************************************************************************
  178. * Platform definitions
  179. *****************************************************************************/
  180. // Interrupt Numbers
  181. // Interrupt Handler Definitions
  182. #define SOC_MTIMER_HANDLER irqc_mtip_handler
  183. #define SOC_SOFTINT_HANDLER irqc_msip_handler
  184. /**
  185. * @brief UART
  186. */
  187. typedef struct {
  188. __IOM uint32_t TXFIFO;
  189. __IOM uint32_t RXFIFO;
  190. __IOM uint32_t TXCTRL;
  191. __IOM uint32_t RXCTRL;
  192. __IOM uint32_t IE;
  193. __IOM uint32_t IP;
  194. __IOM uint32_t DIV;
  195. } UART_TypeDef;
  196. /**
  197. * @brief QSPI
  198. */
  199. typedef struct {
  200. __IOM uint32_t SCKDIV;
  201. __IOM uint32_t SCKMODE;
  202. __IOM uint32_t RESERVED0[1];
  203. __IOM uint32_t FORCE;
  204. __IOM uint32_t CSID;
  205. __IOM uint32_t CSDEF;
  206. __IOM uint32_t CSMODE;
  207. __IOM uint32_t VERSION;
  208. __IOM uint32_t RESERVED1[2];
  209. __IOM uint32_t DELAY0;
  210. __IOM uint32_t DELAY1;
  211. __IOM uint32_t RESERVED2[4];
  212. __IOM uint32_t FMT;
  213. __IOM uint32_t RESERVED3;
  214. __IOM uint32_t TXDATA;
  215. __IOM uint32_t RXDATA;
  216. __IOM uint32_t TXMARK;
  217. __IOM uint32_t RXMARK;
  218. __IOM uint32_t RESERVED4[2];
  219. __IOM uint32_t FCTRL;
  220. __IOM uint32_t FFMT;
  221. __IOM uint32_t RESERVED5[2];
  222. __IOM uint32_t IE;
  223. __IOM uint32_t IP;
  224. __IOM uint32_t FFMT1;
  225. __IOM uint32_t STATUS;
  226. } QSPI_TypeDef;
  227. /*@}*/ /* end of group evalsoc_Peripherals */
  228. /* ========================================= End of section using anonymous unions ========================================= */
  229. /* Macros for memory access operations */
  230. #define _REG8P(p, i) ((volatile uint8_t *) ((uintptr_t)((p) + (i))))
  231. #define _REG16P(p, i) ((volatile uint16_t *) ((uintptr_t)((p) + (i))))
  232. #define _REG32P(p, i) ((volatile uint32_t *) ((uintptr_t)((p) + (i))))
  233. #define _REG64P(p, i) ((volatile uint64_t *) ((uintptr_t)((p) + (i))))
  234. #define _REG8(p, i) (*(_REG8P(p, i)))
  235. #define _REG16(p, i) (*(_REG16P(p, i)))
  236. #define _REG32(p, i) (*(_REG32P(p, i)))
  237. #define _REG64(p, i) (*(_REG64P(p, i)))
  238. #define REG8(addr) _REG8((addr), 0)
  239. #define REG16(addr) _REG16((addr), 0)
  240. #define REG32(addr) _REG32((addr), 0)
  241. #define REG64(addr) _REG64((addr), 0)
  242. /* Macros for address type convert and access operations */
  243. #define ADDR16(addr) ((uint16_t)(uintptr_t)(addr))
  244. #define ADDR32(addr) ((uint32_t)(uintptr_t)(addr))
  245. #define ADDR64(addr) ((uint64_t)(uintptr_t)(addr))
  246. #define ADDR8P(addr) ((uint8_t *)(uintptr_t)(addr))
  247. #define ADDR16P(addr) ((uint16_t *)(uintptr_t)(addr))
  248. #define ADDR32P(addr) ((uint32_t *)(uintptr_t)(addr))
  249. #define ADDR64P(addr) ((uint64_t *)(uintptr_t)(addr))
  250. /* Macros for Bit Operations */
  251. #if __riscv_xlen == 32
  252. #define BITMASK_MAX 0xFFFFFFFFUL
  253. #define BITOFS_MAX 31
  254. #else
  255. #define BITMASK_MAX 0xFFFFFFFFFFFFFFFFULL
  256. #define BITOFS_MAX 63
  257. #endif
  258. // BIT/BITS only support bit mask for __riscv_xlen
  259. // For RISC-V 32 bit, it support mask 32 bit wide
  260. // For RISC-V 64 bit, it support mask 64 bit wide
  261. #define BIT(ofs) (0x1UL << (ofs))
  262. #define BITS(start, end) ((BITMASK_MAX) << (start) & (BITMASK_MAX) >> (BITOFS_MAX - (end)))
  263. #define GET_BIT(regval, bitofs) (((regval) >> (bitofs)) & 0x1)
  264. #define SET_BIT(regval, bitofs) ((regval) |= BIT(bitofs))
  265. #define CLR_BIT(regval, bitofs) ((regval) &= (~BIT(bitofs)))
  266. #define FLIP_BIT(regval, bitofs) ((regval) ^= BIT(bitofs))
  267. #define WRITE_BIT(regval, bitofs, val) CLR_BIT(regval, bitofs); ((regval) |= ((val) << bitofs) & BIT(bitofs))
  268. #define CHECK_BIT(regval, bitofs) (!!((regval) & (0x1UL<<(bitofs))))
  269. #define GET_BITS(regval, start, end) (((regval) & BITS((start), (end))) >> (start))
  270. #define SET_BITS(regval, start, end) ((regval) |= BITS((start), (end)))
  271. #define CLR_BITS(regval, start, end) ((regval) &= (~BITS((start), (end))))
  272. #define FLIP_BITS(regval, start, end) ((regval) ^= BITS((start), (end)))
  273. #define WRITE_BITS(regval, start, end, val) CLR_BITS(regval, start, end); ((regval) |= ((val) << start) & BITS((start), (end)))
  274. #define CHECK_BITS_ALL(regval, start, end) (!((~(regval)) & BITS((start), (end))))
  275. #define CHECK_BITS_ANY(regval, start, end) ((regval) & BITS((start), (end)))
  276. #define BITMASK_SET(regval, mask) ((regval) |= (mask))
  277. #define BITMASK_CLR(regval, mask) ((regval) &= (~(mask)))
  278. #define BITMASK_FLIP(regval, mask) ((regval) ^= (mask))
  279. #define BITMASK_CHECK_ALL(regval, mask) (!((~(regval)) & (mask)))
  280. #define BITMASK_CHECK_ANY(regval, mask) ((regval) & (mask))
  281. /* =========================================================================================================================== */
  282. /* ================ Device Specific Peripheral Address Map ================ */
  283. /* =========================================================================================================================== */
  284. /* ToDo: add here your device peripherals base addresses
  285. following is an example for timer */
  286. /** @addtogroup Device_Peripheral_peripheralAddr
  287. * @{
  288. */
  289. /* ILM/DLM/FLASHXIP and Peripheral base address */
  290. #ifndef EVALSOC_FLASH_XIP_BASE
  291. #define QSPI_FLASH_BASE (0x20000000UL) /*!< (FLASH ) Base Address */
  292. #else
  293. #define QSPI_FLASH_BASE (EVALSOC_FLASH_XIP_BASE) /*!< (FLASH ) Base Address */
  294. #endif
  295. #ifndef CFG_ILM_BASE_ADDR
  296. #define ONCHIP_ILM_BASE (0x80000000UL) /*!< (ILM ) Base Address */
  297. #else
  298. #define ONCHIP_ILM_BASE (CFG_ILM_BASE_ADDR) /*!< (ILM ) Base Address */
  299. #endif
  300. #ifndef CFG_DLM_BASE_ADDR
  301. #define ONCHIP_DLM_BASE (0x90000000UL) /*!< (DLM ) Base Address */
  302. #else
  303. #define ONCHIP_DLM_BASE (CFG_DLM_BASE_ADDR) /*!< (DLM ) Base Address */
  304. #endif
  305. #ifndef EVALSOC_SYSMEM_BASE
  306. #define ONCHIP_SRAM_BASE (0xA0000000UL) /*!< (SRAM ) Base Address */
  307. #else
  308. #define ONCHIP_SRAM_BASE (EVALSOC_SYSMEM_BASE) /*!< (SRAM ) Base Address */
  309. #endif
  310. #ifndef EVALSOC_PERIPS_BASE
  311. #define EVALSOC_PERIPH_BASE (0x10000000UL) /*!< (Peripheral) Base Address */
  312. #else
  313. #define EVALSOC_PERIPH_BASE (EVALSOC_PERIPS_BASE) /*!< (Peripheral) Base Address */
  314. #endif
  315. /* Peripheral memory map */
  316. #define UART0_BASE (EVALSOC_PERIPH_BASE + 0x13000) /*!< (UART0) Base Address */
  317. #define QSPI0_BASE (EVALSOC_PERIPH_BASE + 0x14000) /*!< (QSPI0) Base Address */
  318. #define UART1_BASE (EVALSOC_PERIPH_BASE + 0x23000) /*!< (UART1) Base Address */
  319. #define QSPI1_BASE (EVALSOC_PERIPH_BASE + 0x24000) /*!< (QSPI1) Base Address */
  320. #define QSPI2_BASE (EVALSOC_PERIPH_BASE + 0x34000) /*!< (QSPI2) Base Address */
  321. /** @} */ /* End of group Device_Peripheral_peripheralAddr */
  322. /* =========================================================================================================================== */
  323. /* ================ Peripheral declaration ================ */
  324. /* =========================================================================================================================== */
  325. /* ToDo: add here your device peripherals pointer definitions
  326. following is an example for timer */
  327. /** @addtogroup Device_Peripheral_declaration
  328. * @{
  329. */
  330. #define UART0 ((UART_TypeDef *) UART0_BASE)
  331. #define QSPI0 ((QSPI_TypeDef *) QSPI0_BASE)
  332. #define UART1 ((UART_TypeDef *) UART1_BASE)
  333. #define QSPI1 ((QSPI_TypeDef *) QSPI1_BASE)
  334. #define QSPI2 ((QSPI_TypeDef *) QSPI2_BASE)
  335. #define SPI0_REG(offset) _REG32(QSPI0_BASE, offset)
  336. #define SPI1_REG(offset) _REG32(QSPI1_BASE, offset)
  337. #define SPI2_REG(offset) _REG32(QSPI2_BASE, offset)
  338. #define UART0_REG(offset) _REG32(UART0_BASE, offset)
  339. #define UART1_REG(offset) _REG32(UART1_BASE, offset)
  340. // Misc
  341. // Only used by Nuclei Internally, please dont use it
  342. // TODO: If you don't have simulation mode, please change it to {}
  343. #define SIMULATION_EXIT(ret) { __WMB(); UART0->RXFIFO = (ret); \
  344. while (UART0->TXFIFO & (1<<31)); \
  345. UART0->TXFIFO = 4; }
  346. extern uint32_t get_cpu_freq(void);
  347. extern void delay_1ms(uint32_t count);
  348. /** @} */ /* End of group evalsoc */
  349. /** @} */ /* End of group Nuclei */
  350. #ifdef __cplusplus
  351. }
  352. #endif
  353. #endif /* __EVALSOC_H__ */