sysctl.h 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /* Copyright 2018 Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _DRIVER_SYSCTL_H
  16. #define _DRIVER_SYSCTL_H
  17. #include <stdint.h>
  18. #include "platform.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @brief System controller register
  24. *
  25. * @note System controller register table
  26. *
  27. * | Offset | Name | Description |
  28. * |-----------|----------------|-------------------------------------|
  29. * | 0x00 | git_id | Git short commit id |
  30. * | 0x04 | clk_freq | System clock base frequency |
  31. * | 0x08 | pll0 | PLL0 controller |
  32. * | 0x0c | pll1 | PLL1 controller |
  33. * | 0x10 | pll2 | PLL2 controller |
  34. * | 0x14 | resv5 | Reserved |
  35. * | 0x18 | pll_lock | PLL lock tester |
  36. * | 0x1c | rom_error | AXI ROM detector |
  37. * | 0x20 | clk_sel0 | Clock select controller0 |
  38. * | 0x24 | clk_sel1 | Clock select controller1 |
  39. * | 0x28 | clk_en_cent | Central clock enable |
  40. * | 0x2c | clk_en_peri | Peripheral clock enable |
  41. * | 0x30 | soft_reset | Soft reset ctrl |
  42. * | 0x34 | peri_reset | Peripheral reset controller |
  43. * | 0x38 | clk_th0 | Clock threshold controller 0 |
  44. * | 0x3c | clk_th1 | Clock threshold controller 1 |
  45. * | 0x40 | clk_th2 | Clock threshold controller 2 |
  46. * | 0x44 | clk_th3 | Clock threshold controller 3 |
  47. * | 0x48 | clk_th4 | Clock threshold controller 4 |
  48. * | 0x4c | clk_th5 | Clock threshold controller 5 |
  49. * | 0x50 | clk_th6 | Clock threshold controller 6 |
  50. * | 0x54 | misc | Miscellaneous controller |
  51. * | 0x58 | peri | Peripheral controller |
  52. * | 0x5c | spi_sleep | SPI sleep controller |
  53. * | 0x60 | reset_status | Reset source status |
  54. * | 0x64 | dma_sel0 | DMA handshake selector |
  55. * | 0x68 | dma_sel1 | DMA handshake selector |
  56. * | 0x6c | power_sel | IO Power Mode Select controller |
  57. * | 0x70 | resv28 | Reserved |
  58. * | 0x74 | resv29 | Reserved |
  59. * | 0x78 | resv30 | Reserved |
  60. * | 0x7c | resv31 | Reserved |
  61. *
  62. */
  63. typedef enum _sysctl_pll_t
  64. {
  65. SYSCTL_PLL0,
  66. SYSCTL_PLL1,
  67. SYSCTL_PLL2,
  68. SYSCTL_PLL_MAX
  69. } sysctl_pll_t;
  70. typedef enum _sysctl_clock_source_t
  71. {
  72. SYSCTL_SOURCE_IN0,
  73. SYSCTL_SOURCE_PLL0,
  74. SYSCTL_SOURCE_PLL1,
  75. SYSCTL_SOURCE_PLL2,
  76. SYSCTL_SOURCE_ACLK,
  77. SYSCTL_SOURCE_MAX
  78. } sysctl_clock_source_t;
  79. typedef enum _sysctl_dma_channel_t
  80. {
  81. SYSCTL_DMA_CHANNEL_0,
  82. SYSCTL_DMA_CHANNEL_1,
  83. SYSCTL_DMA_CHANNEL_2,
  84. SYSCTL_DMA_CHANNEL_3,
  85. SYSCTL_DMA_CHANNEL_4,
  86. SYSCTL_DMA_CHANNEL_5,
  87. SYSCTL_DMA_CHANNEL_MAX
  88. } sysctl_dma_channel_t;
  89. typedef enum _sysctl_dma_select_t
  90. {
  91. SYSCTL_DMA_SELECT_SSI0_RX_REQ,
  92. SYSCTL_DMA_SELECT_SSI0_TX_REQ,
  93. SYSCTL_DMA_SELECT_SSI1_RX_REQ,
  94. SYSCTL_DMA_SELECT_SSI1_TX_REQ,
  95. SYSCTL_DMA_SELECT_SSI2_RX_REQ,
  96. SYSCTL_DMA_SELECT_SSI2_TX_REQ,
  97. SYSCTL_DMA_SELECT_SSI3_RX_REQ,
  98. SYSCTL_DMA_SELECT_SSI3_TX_REQ,
  99. SYSCTL_DMA_SELECT_I2C0_RX_REQ,
  100. SYSCTL_DMA_SELECT_I2C0_TX_REQ,
  101. SYSCTL_DMA_SELECT_I2C1_RX_REQ,
  102. SYSCTL_DMA_SELECT_I2C1_TX_REQ,
  103. SYSCTL_DMA_SELECT_I2C2_RX_REQ,
  104. SYSCTL_DMA_SELECT_I2C2_TX_REQ,
  105. SYSCTL_DMA_SELECT_UART1_RX_REQ,
  106. SYSCTL_DMA_SELECT_UART1_TX_REQ,
  107. SYSCTL_DMA_SELECT_UART2_RX_REQ,
  108. SYSCTL_DMA_SELECT_UART2_TX_REQ,
  109. SYSCTL_DMA_SELECT_UART3_RX_REQ,
  110. SYSCTL_DMA_SELECT_UART3_TX_REQ,
  111. SYSCTL_DMA_SELECT_AES_REQ,
  112. SYSCTL_DMA_SELECT_SHA_RX_REQ,
  113. SYSCTL_DMA_SELECT_AI_RX_REQ,
  114. SYSCTL_DMA_SELECT_FFT_RX_REQ,
  115. SYSCTL_DMA_SELECT_FFT_TX_REQ,
  116. SYSCTL_DMA_SELECT_I2S0_TX_REQ,
  117. SYSCTL_DMA_SELECT_I2S0_RX_REQ,
  118. SYSCTL_DMA_SELECT_I2S1_TX_REQ,
  119. SYSCTL_DMA_SELECT_I2S1_RX_REQ,
  120. SYSCTL_DMA_SELECT_I2S2_TX_REQ,
  121. SYSCTL_DMA_SELECT_I2S2_RX_REQ,
  122. SYSCTL_DMA_SELECT_I2S0_BF_DIR_REQ,
  123. SYSCTL_DMA_SELECT_I2S0_BF_VOICE_REQ,
  124. SYSCTL_DMA_SELECT_MAX
  125. } sysctl_dma_select_t;
  126. /**
  127. * @brief System controller clock id
  128. */
  129. typedef enum _sysctl_clock_t
  130. {
  131. SYSCTL_CLOCK_PLL0,
  132. SYSCTL_CLOCK_PLL1,
  133. SYSCTL_CLOCK_PLL2,
  134. SYSCTL_CLOCK_CPU,
  135. SYSCTL_CLOCK_SRAM0,
  136. SYSCTL_CLOCK_SRAM1,
  137. SYSCTL_CLOCK_APB0,
  138. SYSCTL_CLOCK_APB1,
  139. SYSCTL_CLOCK_APB2,
  140. SYSCTL_CLOCK_ROM,
  141. SYSCTL_CLOCK_DMA,
  142. SYSCTL_CLOCK_AI,
  143. SYSCTL_CLOCK_DVP,
  144. SYSCTL_CLOCK_FFT,
  145. SYSCTL_CLOCK_GPIO,
  146. SYSCTL_CLOCK_SPI0,
  147. SYSCTL_CLOCK_SPI1,
  148. SYSCTL_CLOCK_SPI2,
  149. SYSCTL_CLOCK_SPI3,
  150. SYSCTL_CLOCK_I2S0,
  151. SYSCTL_CLOCK_I2S1,
  152. SYSCTL_CLOCK_I2S2,
  153. SYSCTL_CLOCK_I2C0,
  154. SYSCTL_CLOCK_I2C1,
  155. SYSCTL_CLOCK_I2C2,
  156. SYSCTL_CLOCK_UART1,
  157. SYSCTL_CLOCK_UART2,
  158. SYSCTL_CLOCK_UART3,
  159. SYSCTL_CLOCK_AES,
  160. SYSCTL_CLOCK_FPIOA,
  161. SYSCTL_CLOCK_TIMER0,
  162. SYSCTL_CLOCK_TIMER1,
  163. SYSCTL_CLOCK_TIMER2,
  164. SYSCTL_CLOCK_WDT0,
  165. SYSCTL_CLOCK_WDT1,
  166. SYSCTL_CLOCK_SHA,
  167. SYSCTL_CLOCK_OTP,
  168. SYSCTL_CLOCK_RTC,
  169. SYSCTL_CLOCK_ACLK = 40,
  170. SYSCTL_CLOCK_HCLK,
  171. SYSCTL_CLOCK_IN0,
  172. SYSCTL_CLOCK_MAX
  173. } sysctl_clock_t;
  174. /**
  175. * @brief System controller clock select id
  176. */
  177. typedef enum _sysctl_clock_select_t
  178. {
  179. SYSCTL_CLOCK_SELECT_PLL0_BYPASS,
  180. SYSCTL_CLOCK_SELECT_PLL1_BYPASS,
  181. SYSCTL_CLOCK_SELECT_PLL2_BYPASS,
  182. SYSCTL_CLOCK_SELECT_PLL2,
  183. SYSCTL_CLOCK_SELECT_ACLK,
  184. SYSCTL_CLOCK_SELECT_SPI3,
  185. SYSCTL_CLOCK_SELECT_TIMER0,
  186. SYSCTL_CLOCK_SELECT_TIMER1,
  187. SYSCTL_CLOCK_SELECT_TIMER2,
  188. SYSCTL_CLOCK_SELECT_SPI3_SAMPLE,
  189. SYSCTL_CLOCK_SELECT_MAX = 11
  190. } sysctl_clock_select_t;
  191. /**
  192. * @brief System controller clock threshold id
  193. */
  194. typedef enum _sysctl_threshold_t
  195. {
  196. SYSCTL_THRESHOLD_ACLK,
  197. SYSCTL_THRESHOLD_APB0,
  198. SYSCTL_THRESHOLD_APB1,
  199. SYSCTL_THRESHOLD_APB2,
  200. SYSCTL_THRESHOLD_SRAM0,
  201. SYSCTL_THRESHOLD_SRAM1,
  202. SYSCTL_THRESHOLD_AI,
  203. SYSCTL_THRESHOLD_DVP,
  204. SYSCTL_THRESHOLD_ROM,
  205. SYSCTL_THRESHOLD_SPI0,
  206. SYSCTL_THRESHOLD_SPI1,
  207. SYSCTL_THRESHOLD_SPI2,
  208. SYSCTL_THRESHOLD_SPI3,
  209. SYSCTL_THRESHOLD_TIMER0,
  210. SYSCTL_THRESHOLD_TIMER1,
  211. SYSCTL_THRESHOLD_TIMER2,
  212. SYSCTL_THRESHOLD_I2S0,
  213. SYSCTL_THRESHOLD_I2S1,
  214. SYSCTL_THRESHOLD_I2S2,
  215. SYSCTL_THRESHOLD_I2S0_M,
  216. SYSCTL_THRESHOLD_I2S1_M,
  217. SYSCTL_THRESHOLD_I2S2_M,
  218. SYSCTL_THRESHOLD_I2C0,
  219. SYSCTL_THRESHOLD_I2C1,
  220. SYSCTL_THRESHOLD_I2C2,
  221. SYSCTL_THRESHOLD_WDT0,
  222. SYSCTL_THRESHOLD_WDT1,
  223. SYSCTL_THRESHOLD_MAX = 28
  224. } sysctl_threshold_t;
  225. /**
  226. * @brief System controller reset control id
  227. */
  228. typedef enum _sysctl_reset_t
  229. {
  230. SYSCTL_RESET_SOC,
  231. SYSCTL_RESET_ROM,
  232. SYSCTL_RESET_DMA,
  233. SYSCTL_RESET_AI,
  234. SYSCTL_RESET_DVP,
  235. SYSCTL_RESET_FFT,
  236. SYSCTL_RESET_GPIO,
  237. SYSCTL_RESET_SPI0,
  238. SYSCTL_RESET_SPI1,
  239. SYSCTL_RESET_SPI2,
  240. SYSCTL_RESET_SPI3,
  241. SYSCTL_RESET_I2S0,
  242. SYSCTL_RESET_I2S1,
  243. SYSCTL_RESET_I2S2,
  244. SYSCTL_RESET_I2C0,
  245. SYSCTL_RESET_I2C1,
  246. SYSCTL_RESET_I2C2,
  247. SYSCTL_RESET_UART1,
  248. SYSCTL_RESET_UART2,
  249. SYSCTL_RESET_UART3,
  250. SYSCTL_RESET_AES,
  251. SYSCTL_RESET_FPIOA,
  252. SYSCTL_RESET_TIMER0,
  253. SYSCTL_RESET_TIMER1,
  254. SYSCTL_RESET_TIMER2,
  255. SYSCTL_RESET_WDT0,
  256. SYSCTL_RESET_WDT1,
  257. SYSCTL_RESET_SHA,
  258. SYSCTL_RESET_RTC,
  259. SYSCTL_RESET_MAX = 31
  260. } sysctl_reset_t;
  261. /**
  262. * @brief System controller power bank id
  263. */
  264. typedef enum _sysctl_power_bank
  265. {
  266. SYSCTL_POWER_BANK0,
  267. SYSCTL_POWER_BANK1,
  268. SYSCTL_POWER_BANK2,
  269. SYSCTL_POWER_BANK3,
  270. SYSCTL_POWER_BANK4,
  271. SYSCTL_POWER_BANK5,
  272. SYSCTL_POWER_BANK6,
  273. SYSCTL_POWER_BANK7,
  274. SYSCTL_POWER_BANK_MAX,
  275. } sysctl_power_bank_t;
  276. /**
  277. * @brief System controller reset control id
  278. */
  279. typedef enum _sysctl_io_power_mode
  280. {
  281. SYSCTL_POWER_V33,
  282. SYSCTL_POWER_V18
  283. } sysctl_io_power_mode_t;
  284. /**
  285. * @brief System reset status
  286. */
  287. typedef enum _sysctl_reset_enum_status
  288. {
  289. SYSCTL_RESET_STATUS_HARD,
  290. SYSCTL_RESET_STATUS_SOFT,
  291. SYSCTL_RESET_STATUS_WDT0,
  292. SYSCTL_RESET_STATUS_WDT1,
  293. SYSCTL_RESET_STATUS_MAX,
  294. } sysctl_reset_enum_status_t;
  295. /**
  296. * @brief Git short commit id
  297. *
  298. * No. 0 Register (0x00)
  299. */
  300. typedef struct _sysctl_git_id
  301. {
  302. uint32_t git_id : 32;
  303. } __attribute__((packed, aligned(4))) sysctl_git_id_t;
  304. /**
  305. * @brief System clock base frequency
  306. *
  307. * No. 1 Register (0x04)
  308. */
  309. typedef struct _sysctl_clk_freq
  310. {
  311. uint32_t clk_freq : 32;
  312. } __attribute__((packed, aligned(4))) sysctl_clk_freq_t;
  313. /**
  314. * @brief PLL0 controller
  315. *
  316. * No. 2 Register (0x08)
  317. */
  318. typedef struct _sysctl_pll0
  319. {
  320. uint32_t clkr0 : 4;
  321. uint32_t clkf0 : 6;
  322. uint32_t clkod0 : 4;
  323. uint32_t bwadj0 : 6;
  324. uint32_t pll_reset0 : 1;
  325. uint32_t pll_pwrd0 : 1;
  326. uint32_t pll_intfb0 : 1;
  327. uint32_t pll_bypass0 : 1;
  328. uint32_t pll_test0 : 1;
  329. uint32_t pll_out_en0 : 1;
  330. uint32_t pll_test_en : 1;
  331. uint32_t reserved : 5;
  332. } __attribute__((packed, aligned(4))) sysctl_pll0_t;
  333. /**
  334. * @brief PLL1 controller
  335. *
  336. * No. 3 Register (0x0c)
  337. */
  338. typedef struct _sysctl_pll1
  339. {
  340. uint32_t clkr1 : 4;
  341. uint32_t clkf1 : 6;
  342. uint32_t clkod1 : 4;
  343. uint32_t bwadj1 : 6;
  344. uint32_t pll_reset1 : 1;
  345. uint32_t pll_pwrd1 : 1;
  346. uint32_t pll_intfb1 : 1;
  347. uint32_t pll_bypass1 : 1;
  348. uint32_t pll_test1 : 1;
  349. uint32_t pll_out_en1 : 1;
  350. uint32_t reserved : 6;
  351. } __attribute__((packed, aligned(4))) sysctl_pll1_t;
  352. /**
  353. * @brief PLL2 controller
  354. *
  355. * No. 4 Register (0x10)
  356. */
  357. typedef struct _sysctl_pll2
  358. {
  359. uint32_t clkr2 : 4;
  360. uint32_t clkf2 : 6;
  361. uint32_t clkod2 : 4;
  362. uint32_t bwadj2 : 6;
  363. uint32_t pll_reset2 : 1;
  364. uint32_t pll_pwrd2 : 1;
  365. uint32_t pll_intfb2 : 1;
  366. uint32_t pll_bypass2 : 1;
  367. uint32_t pll_test2 : 1;
  368. uint32_t pll_out_en2 : 1;
  369. uint32_t pll_ckin_sel2 : 2;
  370. uint32_t reserved : 4;
  371. } __attribute__((packed, aligned(4))) sysctl_pll2_t;
  372. /**
  373. * @brief PLL lock tester
  374. *
  375. * No. 6 Register (0x18)
  376. */
  377. typedef struct _sysctl_pll_lock
  378. {
  379. uint32_t pll_lock0 : 2;
  380. uint32_t pll_slip_clear0 : 1;
  381. uint32_t test_clk_out0 : 1;
  382. uint32_t reserved0 : 4;
  383. uint32_t pll_lock1 : 2;
  384. uint32_t pll_slip_clear1 : 1;
  385. uint32_t test_clk_out1 : 1;
  386. uint32_t reserved1 : 4;
  387. uint32_t pll_lock2 : 2;
  388. uint32_t pll_slip_clear2 : 1;
  389. uint32_t test_clk_out2 : 1;
  390. uint32_t reserved2 : 12;
  391. } __attribute__((packed, aligned(4))) sysctl_pll_lock_t;
  392. /**
  393. * @brief AXI ROM detector
  394. *
  395. * No. 7 Register (0x1c)
  396. */
  397. typedef struct _sysctl_rom_error
  398. {
  399. uint32_t rom_mul_error : 1;
  400. uint32_t rom_one_error : 1;
  401. uint32_t reserved : 30;
  402. } __attribute__((packed, aligned(4))) sysctl_rom_error_t;
  403. /**
  404. * @brief Clock select controller0
  405. *
  406. * No. 8 Register (0x20)
  407. */
  408. typedef struct _sysctl_clk_sel0
  409. {
  410. uint32_t aclk_sel : 1;
  411. uint32_t aclk_divider_sel : 2;
  412. uint32_t apb0_clk_sel : 3;
  413. uint32_t apb1_clk_sel : 3;
  414. uint32_t apb2_clk_sel : 3;
  415. uint32_t spi3_clk_sel : 1;
  416. uint32_t timer0_clk_sel : 1;
  417. uint32_t timer1_clk_sel : 1;
  418. uint32_t timer2_clk_sel : 1;
  419. uint32_t reserved : 16;
  420. } __attribute__((packed, aligned(4))) sysctl_clk_sel0_t;
  421. /**
  422. * @brief Clock select controller1
  423. *
  424. * No. 9 Register (0x24)
  425. */
  426. typedef struct _sysctl_clk_sel1
  427. {
  428. uint32_t spi3_sample_clk_sel : 1;
  429. uint32_t reserved0 : 30;
  430. uint32_t reserved1 : 1;
  431. } __attribute__((packed, aligned(4))) sysctl_clk_sel1_t;
  432. /**
  433. * @brief Central clock enable
  434. *
  435. * No. 10 Register (0x28)
  436. */
  437. typedef struct _sysctl_clk_en_cent
  438. {
  439. uint32_t cpu_clk_en : 1;
  440. uint32_t sram0_clk_en : 1;
  441. uint32_t sram1_clk_en : 1;
  442. uint32_t apb0_clk_en : 1;
  443. uint32_t apb1_clk_en : 1;
  444. uint32_t apb2_clk_en : 1;
  445. uint32_t reserved : 26;
  446. } __attribute__((packed, aligned(4))) sysctl_clk_en_cent_t;
  447. /**
  448. * @brief Peripheral clock enable
  449. *
  450. * No. 11 Register (0x2c)
  451. */
  452. typedef struct _sysctl_clk_en_peri
  453. {
  454. uint32_t rom_clk_en : 1;
  455. uint32_t dma_clk_en : 1;
  456. uint32_t ai_clk_en : 1;
  457. uint32_t dvp_clk_en : 1;
  458. uint32_t fft_clk_en : 1;
  459. uint32_t gpio_clk_en : 1;
  460. uint32_t spi0_clk_en : 1;
  461. uint32_t spi1_clk_en : 1;
  462. uint32_t spi2_clk_en : 1;
  463. uint32_t spi3_clk_en : 1;
  464. uint32_t i2s0_clk_en : 1;
  465. uint32_t i2s1_clk_en : 1;
  466. uint32_t i2s2_clk_en : 1;
  467. uint32_t i2c0_clk_en : 1;
  468. uint32_t i2c1_clk_en : 1;
  469. uint32_t i2c2_clk_en : 1;
  470. uint32_t uart1_clk_en : 1;
  471. uint32_t uart2_clk_en : 1;
  472. uint32_t uart3_clk_en : 1;
  473. uint32_t aes_clk_en : 1;
  474. uint32_t fpioa_clk_en : 1;
  475. uint32_t timer0_clk_en : 1;
  476. uint32_t timer1_clk_en : 1;
  477. uint32_t timer2_clk_en : 1;
  478. uint32_t wdt0_clk_en : 1;
  479. uint32_t wdt1_clk_en : 1;
  480. uint32_t sha_clk_en : 1;
  481. uint32_t otp_clk_en : 1;
  482. uint32_t reserved : 1;
  483. uint32_t rtc_clk_en : 1;
  484. uint32_t reserved0 : 2;
  485. } __attribute__((packed, aligned(4))) sysctl_clk_en_peri_t;
  486. /**
  487. * @brief Soft reset ctrl
  488. *
  489. * No. 12 Register (0x30)
  490. */
  491. typedef struct _sysctl_soft_reset
  492. {
  493. uint32_t soft_reset : 1;
  494. uint32_t reserved : 31;
  495. } __attribute__((packed, aligned(4))) sysctl_soft_reset_t;
  496. /**
  497. * @brief Peripheral reset controller
  498. *
  499. * No. 13 Register (0x34)
  500. */
  501. typedef struct _sysctl_peri_reset
  502. {
  503. uint32_t rom_reset : 1;
  504. uint32_t dma_reset : 1;
  505. uint32_t ai_reset : 1;
  506. uint32_t dvp_reset : 1;
  507. uint32_t fft_reset : 1;
  508. uint32_t gpio_reset : 1;
  509. uint32_t spi0_reset : 1;
  510. uint32_t spi1_reset : 1;
  511. uint32_t spi2_reset : 1;
  512. uint32_t spi3_reset : 1;
  513. uint32_t i2s0_reset : 1;
  514. uint32_t i2s1_reset : 1;
  515. uint32_t i2s2_reset : 1;
  516. uint32_t i2c0_reset : 1;
  517. uint32_t i2c1_reset : 1;
  518. uint32_t i2c2_reset : 1;
  519. uint32_t uart1_reset : 1;
  520. uint32_t uart2_reset : 1;
  521. uint32_t uart3_reset : 1;
  522. uint32_t aes_reset : 1;
  523. uint32_t fpioa_reset : 1;
  524. uint32_t timer0_reset : 1;
  525. uint32_t timer1_reset : 1;
  526. uint32_t timer2_reset : 1;
  527. uint32_t wdt0_reset : 1;
  528. uint32_t wdt1_reset : 1;
  529. uint32_t sha_reset : 1;
  530. uint32_t reserved : 2;
  531. uint32_t rtc_reset : 1;
  532. uint32_t reserved0 : 2;
  533. } __attribute__((packed, aligned(4))) sysctl_peri_reset_t;
  534. /**
  535. * @brief Clock threshold controller 0
  536. *
  537. * No. 14 Register (0x38)
  538. */
  539. typedef struct _sysctl_clk_th0
  540. {
  541. uint32_t sram0_gclk_threshold : 4;
  542. uint32_t sram1_gclk_threshold : 4;
  543. uint32_t ai_gclk_threshold : 4;
  544. uint32_t dvp_gclk_threshold : 4;
  545. uint32_t rom_gclk_threshold : 4;
  546. uint32_t reserved : 12;
  547. } __attribute__((packed, aligned(4))) sysctl_clk_th0_t;
  548. /**
  549. * @brief Clock threshold controller 1
  550. *
  551. * No. 15 Register (0x3c)
  552. */
  553. typedef struct _sysctl_clk_th1
  554. {
  555. uint32_t spi0_clk_threshold : 8;
  556. uint32_t spi1_clk_threshold : 8;
  557. uint32_t spi2_clk_threshold : 8;
  558. uint32_t spi3_clk_threshold : 8;
  559. } __attribute__((packed, aligned(4))) sysctl_clk_th1_t;
  560. /**
  561. * @brief Clock threshold controller 2
  562. *
  563. * No. 16 Register (0x40)
  564. */
  565. typedef struct _sysctl_clk_th2
  566. {
  567. uint32_t timer0_clk_threshold : 8;
  568. uint32_t timer1_clk_threshold : 8;
  569. uint32_t timer2_clk_threshold : 8;
  570. uint32_t reserved : 8;
  571. } __attribute__((packed, aligned(4))) sysctl_clk_th2_t;
  572. /**
  573. * @brief Clock threshold controller 3
  574. *
  575. * No. 17 Register (0x44)
  576. */
  577. typedef struct _sysctl_clk_th3
  578. {
  579. uint32_t i2s0_clk_threshold : 16;
  580. uint32_t i2s1_clk_threshold : 16;
  581. } __attribute__((packed, aligned(4))) sysctl_clk_th3_t;
  582. /**
  583. * @brief Clock threshold controller 4
  584. *
  585. * No. 18 Register (0x48)
  586. */
  587. typedef struct _sysctl_clk_th4
  588. {
  589. uint32_t i2s2_clk_threshold : 16;
  590. uint32_t i2s0_mclk_threshold : 8;
  591. uint32_t i2s1_mclk_threshold : 8;
  592. } __attribute__((packed, aligned(4))) sysctl_clk_th4_t;
  593. /**
  594. * @brief Clock threshold controller 5
  595. *
  596. * No. 19 Register (0x4c)
  597. */
  598. typedef struct _sysctl_clk_th5
  599. {
  600. uint32_t i2s2_mclk_threshold : 8;
  601. uint32_t i2c0_clk_threshold : 8;
  602. uint32_t i2c1_clk_threshold : 8;
  603. uint32_t i2c2_clk_threshold : 8;
  604. } __attribute__((packed, aligned(4))) sysctl_clk_th5_t;
  605. /**
  606. * @brief Clock threshold controller 6
  607. *
  608. * No. 20 Register (0x50)
  609. */
  610. typedef struct _sysctl_clk_th6
  611. {
  612. uint32_t wdt0_clk_threshold : 8;
  613. uint32_t wdt1_clk_threshold : 8;
  614. uint32_t reserved0 : 8;
  615. uint32_t reserved1 : 8;
  616. } __attribute__((packed, aligned(4))) sysctl_clk_th6_t;
  617. /**
  618. * @brief Miscellaneous controller
  619. *
  620. * No. 21 Register (0x54)
  621. */
  622. typedef struct _sysctl_misc
  623. {
  624. uint32_t debug_sel : 6;
  625. uint32_t reserved0 : 4;
  626. uint32_t spi_dvp_data_enable : 1;
  627. uint32_t reserved1 : 21;
  628. } __attribute__((packed, aligned(4))) sysctl_misc_t;
  629. /**
  630. * @brief Peripheral controller
  631. *
  632. * No. 22 Register (0x58)
  633. */
  634. typedef struct _sysctl_peri
  635. {
  636. uint32_t timer0_pause : 1;
  637. uint32_t timer1_pause : 1;
  638. uint32_t timer2_pause : 1;
  639. uint32_t timer3_pause : 1;
  640. uint32_t timer4_pause : 1;
  641. uint32_t timer5_pause : 1;
  642. uint32_t timer6_pause : 1;
  643. uint32_t timer7_pause : 1;
  644. uint32_t timer8_pause : 1;
  645. uint32_t timer9_pause : 1;
  646. uint32_t timer10_pause : 1;
  647. uint32_t timer11_pause : 1;
  648. uint32_t spi0_xip_en : 1;
  649. uint32_t spi1_xip_en : 1;
  650. uint32_t spi2_xip_en : 1;
  651. uint32_t spi3_xip_en : 1;
  652. uint32_t spi0_clk_bypass : 1;
  653. uint32_t spi1_clk_bypass : 1;
  654. uint32_t spi2_clk_bypass : 1;
  655. uint32_t i2s0_clk_bypass : 1;
  656. uint32_t i2s1_clk_bypass : 1;
  657. uint32_t i2s2_clk_bypass : 1;
  658. uint32_t jtag_clk_bypass : 1;
  659. uint32_t dvp_clk_bypass : 1;
  660. uint32_t debug_clk_bypass : 1;
  661. uint32_t reserved0 : 1;
  662. uint32_t reserved1 : 6;
  663. } __attribute__((packed, aligned(4))) sysctl_peri_t;
  664. /**
  665. * @brief SPI sleep controller
  666. *
  667. * No. 23 Register (0x5c)
  668. */
  669. typedef struct _sysctl_spi_sleep
  670. {
  671. uint32_t ssi0_sleep : 1;
  672. uint32_t ssi1_sleep : 1;
  673. uint32_t ssi2_sleep : 1;
  674. uint32_t ssi3_sleep : 1;
  675. uint32_t reserved : 28;
  676. } __attribute__((packed, aligned(4))) sysctl_spi_sleep_t;
  677. /**
  678. * @brief Reset source status
  679. *
  680. * No. 24 Register (0x60)
  681. */
  682. typedef struct _sysctl_reset_status
  683. {
  684. uint32_t reset_sts_clr : 1;
  685. uint32_t pin_reset_sts : 1;
  686. uint32_t wdt0_reset_sts : 1;
  687. uint32_t wdt1_reset_sts : 1;
  688. uint32_t soft_reset_sts : 1;
  689. uint32_t reserved : 27;
  690. } __attribute__((packed, aligned(4))) sysctl_reset_status_t;
  691. /**
  692. * @brief DMA handshake selector
  693. *
  694. * No. 25 Register (0x64)
  695. */
  696. typedef struct _sysctl_dma_sel0
  697. {
  698. uint32_t dma_sel0 : 6;
  699. uint32_t dma_sel1 : 6;
  700. uint32_t dma_sel2 : 6;
  701. uint32_t dma_sel3 : 6;
  702. uint32_t dma_sel4 : 6;
  703. uint32_t reserved : 2;
  704. } __attribute__((packed, aligned(4))) sysctl_dma_sel0_t;
  705. /**
  706. * @brief DMA handshake selector
  707. *
  708. * No. 26 Register (0x68)
  709. */
  710. typedef struct _sysctl_dma_sel1
  711. {
  712. uint32_t dma_sel5 : 6;
  713. uint32_t reserved : 26;
  714. } __attribute__((packed, aligned(4))) sysctl_dma_sel1_t;
  715. /**
  716. * @brief IO Power Mode Select controller
  717. *
  718. * No. 27 Register (0x6c)
  719. */
  720. typedef struct _sysctl_power_sel
  721. {
  722. uint32_t power_mode_sel0 : 1;
  723. uint32_t power_mode_sel1 : 1;
  724. uint32_t power_mode_sel2 : 1;
  725. uint32_t power_mode_sel3 : 1;
  726. uint32_t power_mode_sel4 : 1;
  727. uint32_t power_mode_sel5 : 1;
  728. uint32_t power_mode_sel6 : 1;
  729. uint32_t power_mode_sel7 : 1;
  730. uint32_t reserved : 24;
  731. } __attribute__((packed, aligned(4))) sysctl_power_sel_t;
  732. /**
  733. * @brief System controller object
  734. *
  735. * The System controller is a peripheral device mapped in the
  736. * internal memory map, discoverable in the Configuration String.
  737. * It is responsible for low-level configuration of all system
  738. * related peripheral device. It contain PLL controller, clock
  739. * controller, reset controller, DMA handshake controller, SPI
  740. * controller, timer controller, WDT controller and sleep
  741. * controller.
  742. */
  743. typedef struct _sysctl
  744. {
  745. /* No. 0 (0x00): Git short commit id */
  746. sysctl_git_id_t git_id;
  747. /* No. 1 (0x04): System clock base frequency */
  748. sysctl_clk_freq_t clk_freq;
  749. /* No. 2 (0x08): PLL0 controller */
  750. sysctl_pll0_t pll0;
  751. /* No. 3 (0x0c): PLL1 controller */
  752. sysctl_pll1_t pll1;
  753. /* No. 4 (0x10): PLL2 controller */
  754. sysctl_pll2_t pll2;
  755. /* No. 5 (0x14): Reserved */
  756. uint32_t resv5;
  757. /* No. 6 (0x18): PLL lock tester */
  758. sysctl_pll_lock_t pll_lock;
  759. /* No. 7 (0x1c): AXI ROM detector */
  760. sysctl_rom_error_t rom_error;
  761. /* No. 8 (0x20): Clock select controller0 */
  762. sysctl_clk_sel0_t clk_sel0;
  763. /* No. 9 (0x24): Clock select controller1 */
  764. sysctl_clk_sel1_t clk_sel1;
  765. /* No. 10 (0x28): Central clock enable */
  766. sysctl_clk_en_cent_t clk_en_cent;
  767. /* No. 11 (0x2c): Peripheral clock enable */
  768. sysctl_clk_en_peri_t clk_en_peri;
  769. /* No. 12 (0x30): Soft reset ctrl */
  770. sysctl_soft_reset_t soft_reset;
  771. /* No. 13 (0x34): Peripheral reset controller */
  772. sysctl_peri_reset_t peri_reset;
  773. /* No. 14 (0x38): Clock threshold controller 0 */
  774. sysctl_clk_th0_t clk_th0;
  775. /* No. 15 (0x3c): Clock threshold controller 1 */
  776. sysctl_clk_th1_t clk_th1;
  777. /* No. 16 (0x40): Clock threshold controller 2 */
  778. sysctl_clk_th2_t clk_th2;
  779. /* No. 17 (0x44): Clock threshold controller 3 */
  780. sysctl_clk_th3_t clk_th3;
  781. /* No. 18 (0x48): Clock threshold controller 4 */
  782. sysctl_clk_th4_t clk_th4;
  783. /* No. 19 (0x4c): Clock threshold controller 5 */
  784. sysctl_clk_th5_t clk_th5;
  785. /* No. 20 (0x50): Clock threshold controller 6 */
  786. sysctl_clk_th6_t clk_th6;
  787. /* No. 21 (0x54): Miscellaneous controller */
  788. sysctl_misc_t misc;
  789. /* No. 22 (0x58): Peripheral controller */
  790. sysctl_peri_t peri;
  791. /* No. 23 (0x5c): SPI sleep controller */
  792. sysctl_spi_sleep_t spi_sleep;
  793. /* No. 24 (0x60): Reset source status */
  794. sysctl_reset_status_t reset_status;
  795. /* No. 25 (0x64): DMA handshake selector */
  796. sysctl_dma_sel0_t dma_sel0;
  797. /* No. 26 (0x68): DMA handshake selector */
  798. sysctl_dma_sel1_t dma_sel1;
  799. /* No. 27 (0x6c): IO Power Mode Select controller */
  800. sysctl_power_sel_t power_sel;
  801. /* No. 28 (0x70): Reserved */
  802. uint32_t resv28;
  803. /* No. 29 (0x74): Reserved */
  804. uint32_t resv29;
  805. /* No. 30 (0x78): Reserved */
  806. uint32_t resv30;
  807. /* No. 31 (0x7c): Reserved */
  808. uint32_t resv31;
  809. } __attribute__((packed, aligned(4))) sysctl_t;
  810. /**
  811. * @brief Abstruct PLL struct
  812. */
  813. typedef struct _sysctl_general_pll
  814. {
  815. uint32_t clkr : 4;
  816. uint32_t clkf : 6;
  817. uint32_t clkod : 4;
  818. uint32_t bwadj : 6;
  819. uint32_t pll_reset : 1;
  820. uint32_t pll_pwrd : 1;
  821. uint32_t pll_intfb : 1;
  822. uint32_t pll_bypass : 1;
  823. uint32_t pll_test : 1;
  824. uint32_t pll_out_en : 1;
  825. uint32_t pll_ckin_sel : 2;
  826. uint32_t reserved : 4;
  827. } __attribute__((packed, aligned(4))) sysctl_general_pll_t;
  828. /**
  829. * @brief System controller object instanse
  830. */
  831. extern volatile sysctl_t *const sysctl;
  832. /**
  833. * @brief Enable clock for peripheral
  834. *
  835. * @param[in] clock The clock to be enable
  836. *
  837. * @return result
  838. * - 0 Success
  839. * - Other Fail
  840. */
  841. int sysctl_clock_enable(sysctl_clock_t clock);
  842. /**
  843. * @brief Enable clock for peripheral
  844. *
  845. * @param[in] clock The clock to be disable
  846. *
  847. * @return result
  848. * - 0 Success
  849. * - Other Fail
  850. */
  851. int sysctl_clock_disable(sysctl_clock_t clock);
  852. /**
  853. * @brief Sysctl clock set threshold
  854. *
  855. * @param[in] which Which threshold to set
  856. * @param[in] threshold The threshold value
  857. *
  858. * @return result
  859. * - 0 Success
  860. * - Other Fail
  861. */
  862. int sysctl_clock_set_threshold(sysctl_threshold_t which, int threshold);
  863. /**
  864. * @brief Sysctl clock get threshold
  865. *
  866. * @param[in] which Which threshold to get
  867. *
  868. * @return The threshold value
  869. * - Other Value of threshold
  870. * - -1 Fail
  871. */
  872. int sysctl_clock_get_threshold(sysctl_threshold_t which);
  873. /**
  874. * @brief Sysctl clock set clock select
  875. *
  876. * @param[in] which Which clock select to set
  877. * @param[in] select The clock select value
  878. *
  879. * @return result
  880. * - 0 Success
  881. * - Other Fail
  882. */
  883. int sysctl_clock_set_clock_select(sysctl_clock_select_t which, int select);
  884. /**
  885. * @brief Sysctl clock get clock select
  886. *
  887. * @param[in] which Which clock select to get
  888. *
  889. * @return The clock select value
  890. * - Other Value of clock select
  891. * - -1 Fail
  892. */
  893. int sysctl_clock_get_clock_select(sysctl_clock_select_t which);
  894. /**
  895. * @brief Get PLL frequency
  896. *
  897. * @param[in] pll The PLL id
  898. *
  899. * @return The frequency of PLL
  900. */
  901. uint32_t sysctl_pll_get_freq(sysctl_pll_t pll);
  902. /**
  903. * @brief Get base clock frequency by clock id
  904. *
  905. * @param[in] clock The clock id
  906. *
  907. * @return The clock frequency
  908. */
  909. uint32_t sysctl_clock_get_freq(sysctl_clock_t clock);
  910. /**
  911. * @brief Reset device by reset controller
  912. *
  913. * @param[in] reset The reset signal
  914. */
  915. void sysctl_reset(sysctl_reset_t reset);
  916. /**
  917. * @brief Enable the PLL and power on with reset
  918. *
  919. * @param[in] pll The pll id
  920. *
  921. * @return Result
  922. * - 0 Success
  923. * - Other Fail
  924. */
  925. int sysctl_pll_enable(sysctl_pll_t pll);
  926. /**
  927. * @brief Disable the PLL and power off
  928. *
  929. * @param[in] pll The pll id
  930. *
  931. * @return Result
  932. * - 0 Success
  933. * - Other Fail
  934. */
  935. int sysctl_pll_disable(sysctl_pll_t pll);
  936. /**
  937. * @brief Select DMA channel handshake peripheral signal
  938. *
  939. * @param[in] channel The DMA channel
  940. * @param[in] select The peripheral select
  941. *
  942. * @return Result
  943. * - 0 Success
  944. * - Other Fail
  945. */
  946. int sysctl_dma_select(sysctl_dma_channel_t channel, sysctl_dma_select_t select);
  947. /**
  948. * @brief Set SPI0_D0-D7 DVP_D0-D7 as spi and dvp data pin
  949. *
  950. * @param[in] en Enable or not
  951. *
  952. * @return Result
  953. * - 0 Success
  954. * - Other Fail
  955. */
  956. uint32_t sysctl_set_spi0_dvp_data(uint8_t en);
  957. /**
  958. * @brief Set io power mode
  959. *
  960. * @param[in] power_bank IO power bank
  961. * @param[in] io_power_mode Set power mode 3.3v or 1.8
  962. *
  963. * @return Result
  964. * - 0 Success
  965. * - Other Fail
  966. */
  967. void sysctl_set_power_mode(sysctl_power_bank_t power_bank, sysctl_io_power_mode_t io_power_mode);
  968. /**
  969. * @brief get the frequency of CPU
  970. *
  971. * @return The frequency of CPU
  972. */
  973. uint32_t sysctl_cpu_get_freq(void);
  974. /**
  975. * @brief Set frequency of CPU
  976. * @param[in] freq The desired frequency in Hz
  977. *
  978. * @return The actual frequency of CPU after set
  979. */
  980. uint32_t sysctl_cpu_set_freq(uint32_t freq);
  981. /**
  982. * @brief Init PLL freqency
  983. * @param[in] pll The PLL id
  984. * @param[in] pll_freq The desired frequency in Hz
  985. */
  986. uint32_t sysctl_pll_set_freq(sysctl_pll_t pll, uint32_t pll_freq);
  987. /**
  988. * @brief Enable interrupt
  989. */
  990. void sysctl_enable_irq(void);
  991. /**
  992. * @brief Disable interrupt
  993. */
  994. void sysctl_disable_irq(void);
  995. /**
  996. * @brief Get the time start up to now
  997. *
  998. * @return The time of microsecond
  999. */
  1000. uint64_t sysctl_get_time_us(void);
  1001. /**
  1002. * @brief Get reset status
  1003. *
  1004. * @return The status of reset
  1005. */
  1006. sysctl_reset_enum_status_t sysctl_get_reset_status(void);
  1007. #ifdef __cplusplus
  1008. }
  1009. #endif
  1010. #endif /* _DRIVER_SYSCTL_H */