hc32_ll_clk.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_clk.h
  4. * @brief This file contains all the functions prototypes of the CLK driver
  5. * library.
  6. @verbatim
  7. Change Logs:
  8. Date Author Notes
  9. 2022-12-31 CDT First version
  10. @endverbatim
  11. *******************************************************************************
  12. * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  13. *
  14. * This software component is licensed by XHSC under BSD 3-Clause license
  15. * (the "License"); You may not use this file except in compliance with the
  16. * License. You may obtain a copy of the License at:
  17. * opensource.org/licenses/BSD-3-Clause
  18. *
  19. *******************************************************************************
  20. */
  21. #ifndef __HC32_LL_CLK_H__
  22. #define __HC32_LL_CLK_H__
  23. /* C binding of definitions if building with C++ compiler */
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /*******************************************************************************
  29. * Include files
  30. ******************************************************************************/
  31. #include "hc32_ll_def.h"
  32. #include "hc32f4xx.h"
  33. #include "hc32f4xx_conf.h"
  34. /**
  35. * @addtogroup LL_Driver
  36. * @{
  37. */
  38. /**
  39. * @addtogroup LL_CLK
  40. * @{
  41. */
  42. #if (LL_CLK_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup CLK_Global_Types CLK Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief CLK XTAL configuration structure definition
  52. */
  53. typedef struct {
  54. uint8_t u8State; /*!< The new state of the XTAL.
  55. This parameter can be a value of @ref CLK_XTAL_Config */
  56. uint8_t u8Drv; /*!< The XTAL drive ability.
  57. This parameter can be a value of @ref CLK_XTAL_Config */
  58. uint8_t u8Mode; /*!< The XTAL mode selection osc or exclk.
  59. This parameter can be a value of @ref CLK_XTAL_Config */
  60. uint8_t u8StableTime; /*!< The XTAL stable time selection.
  61. This parameter can be a value of @ref CLK_XTAL_Config */
  62. } stc_clock_xtal_init_t;
  63. /**
  64. * @brief CLK XTAL fault detect configuration structure definition
  65. */
  66. typedef struct {
  67. uint8_t u8State; /*!< Specifies the new state of XTALSTD.
  68. This parameter can be a value of @ref CLK_XTALSTD_Config */
  69. uint8_t u8Mode; /*!< Specifies the XTALSTD mode.
  70. This parameter can be a value of @ref CLK_XTALSTD_Config */
  71. uint8_t u8Int; /*!< Specifies the XTALSTD interrupt on or off.
  72. This parameter can be a value of @ref CLK_XTALSTD_Config */
  73. uint8_t u8Reset; /*!< Specifies the XTALSTD reset on or off.
  74. This parameter can be a value of @ref CLK_XTALSTD_Config */
  75. } stc_clock_xtalstd_init_t;
  76. /**
  77. * @brief CLK XTAL divide structure definition
  78. */
  79. typedef struct {
  80. uint32_t u32State; /*!< The new state of the XTAL divide.
  81. This parameter can be a value of @ref CLK_XTALDIV_State */
  82. uint32_t u32Num; /*!< The numerator of XTAL divide. */
  83. uint32_t u32Den; /*!< The denominator of XTAL divide. */
  84. } stc_clock_xtaldiv_init_t;
  85. /**
  86. * @brief CLK XTAL32 configuration structure definition
  87. */
  88. typedef struct {
  89. uint8_t u8State; /*!< Xtal32 new state,
  90. @ref CLK_XTAL32_Config for details */
  91. uint8_t u8Drv; /*!< Xtal32 drive capacity setting,
  92. @ref CLK_XTAL32_Config for details */
  93. uint8_t u8Filter; /*!< Xtal32 noise filter setting,
  94. @ref CLK_XTAL32_Config for details */
  95. } stc_clock_xtal32_init_t;
  96. /**
  97. * @brief CLK clock frequency configuration structure definition
  98. */
  99. typedef struct {
  100. union {
  101. uint32_t SCFGR; /*!< clock frequency config register */
  102. struct {
  103. uint32_t PCLK0S : 3; /*!< PCLK0 */
  104. uint32_t resvd0 : 1; /*!< reserved */
  105. uint32_t PCLK1S : 3; /*!< PCLK1 */
  106. uint32_t resvd1 : 1; /*!< reserved */
  107. uint32_t PCLK2S : 3; /*!< PCLK2 */
  108. uint32_t resvd2 : 1; /*!< reserved */
  109. uint32_t PCLK3S : 3; /*!< PCLK3 */
  110. uint32_t resvd3 : 1; /*!< reserved */
  111. uint32_t PCLK4S : 3; /*!< PCLK4 */
  112. uint32_t resvd4 : 1; /*!< reserved */
  113. uint32_t EXCKS : 3; /*!< EXCLK */
  114. uint32_t resvd5 : 1; /*!< reserved */
  115. uint32_t HCLKS : 3; /*!< HCLK */
  116. uint32_t resvd6 : 5; /*!< reserved */
  117. } SCFGR_f;
  118. };
  119. } stc_clock_scale_t;
  120. /**
  121. * @brief CLK PLL configuration structure definition
  122. */
  123. typedef struct {
  124. uint8_t u8PLLState; /*!< PLL new state, @ref CLK_PLL_Config for details */
  125. union {
  126. uint32_t PLLCFGR; /*!< PLL config register */
  127. struct {
  128. uint32_t PLLM : 2; /*!< PLL M divide */
  129. uint32_t resvd0 : 5; /*!< reserved */
  130. uint32_t PLLSRC : 1; /*!< PLL/PLLA source clock select */
  131. uint32_t PLLN : 9; /*!< PLL N multi */
  132. uint32_t resvd1 : 3; /*!< reserved */
  133. uint32_t PLLR : 4; /*!< PLL R divide */
  134. uint32_t PLLQ : 4; /*!< PLL Q divide */
  135. uint32_t PLLP : 4; /*!< PLL P divide */
  136. } PLLCFGR_f;
  137. };
  138. } stc_clock_pll_init_t;
  139. /**
  140. * @brief CLK bus frequency structure definition
  141. */
  142. typedef struct {
  143. uint32_t u32SysclkFreq; /*!< System clock frequency. */
  144. uint32_t u32HclkFreq; /*!< Hclk frequency. */
  145. uint32_t u32Pclk0Freq; /*!< Pclk0 frequency. */
  146. uint32_t u32Pclk1Freq; /*!< Pclk1 frequency. */
  147. uint32_t u32Pclk2Freq; /*!< Pclk2 frequency. */
  148. uint32_t u32Pclk3Freq; /*!< Pclk3 frequency. */
  149. uint32_t u32Pclk4Freq; /*!< Pclk4 frequency. */
  150. uint32_t u32ExclkFreq; /*!< Exclk frequency. */
  151. } stc_clock_freq_t;
  152. /**
  153. * @brief CLK PLL clock frequency structure definition
  154. */
  155. typedef struct {
  156. uint32_t u32PllVcin; /*!< PLL vcin clock frequency. */
  157. uint32_t u32PllVco; /*!< PLL vco clock frequency. */
  158. uint32_t u32PllP; /*!< PLLp clock frequency. */
  159. uint32_t u32PllQ; /*!< PLLq clock frequency. */
  160. uint32_t u32PllR; /*!< PLLr clock frequency. */
  161. } stc_pll_clock_freq_t;
  162. /**
  163. * @}
  164. */
  165. /*******************************************************************************
  166. * Global pre-processor symbols/macros ('#define')
  167. ******************************************************************************/
  168. /**
  169. * @defgroup CLK_Global_Macros CLK Global Macros
  170. * @{
  171. */
  172. /**
  173. * @defgroup CLK_PLL_Config PLL Config
  174. * @{
  175. */
  176. /**
  177. * @brief PLL function config.
  178. */
  179. #define CLK_PLL_OFF (0x01U)
  180. #define CLK_PLL_ON (0x00U)
  181. /**
  182. * @brief PLL source clock selection.
  183. */
  184. #define CLK_PLL_SRC_XTAL (0x00UL)
  185. #define CLK_PLL_SRC_HRC (0x01UL)
  186. /**
  187. * @}
  188. */
  189. /**
  190. * @defgroup CLK_XTAL_Config XTAL Config
  191. * @{
  192. */
  193. /**
  194. * @brief XTAL function config.
  195. */
  196. #define CLK_XTAL_OFF (CMU_XTALCR_XTALSTP)
  197. #define CLK_XTAL_ON (0x00U)
  198. /**
  199. * @brief XTAL driver ability
  200. * @note
  201. @verbatim
  202. * High | Mid | Low | ULow |
  203. * [20~25] | [16~20) | (8~16) | [4~8] |
  204. @endverbatim
  205. */
  206. #define CLK_XTAL_DRV_HIGH (0x00U << CMU_XTALCFGR_XTALDRV_POS)
  207. #define CLK_XTAL_DRV_MID (0x01U << CMU_XTALCFGR_XTALDRV_POS)
  208. #define CLK_XTAL_DRV_LOW (0x02U << CMU_XTALCFGR_XTALDRV_POS)
  209. #define CLK_XTAL_DRV_ULOW (0x03U << CMU_XTALCFGR_XTALDRV_POS)
  210. /**
  211. * @brief XTAL mode selection osc or exclk
  212. */
  213. #define CLK_XTAL_MD_OSC (0x00U)
  214. #define CLK_XTAL_MD_EXCLK (CMU_XTALCFGR_XTALMS)
  215. /**
  216. * @brief XTAL stable time selection.
  217. * @note a cycle of stable counter = a cycle of LRC divide by 8
  218. */
  219. #define CLK_XTAL_STB_133US (0x01U) /*!< 35 stable count cycle, approx. 133us */
  220. #define CLK_XTAL_STB_255US (0x02U) /*!< 67 stable count cycle, approx. 255us */
  221. #define CLK_XTAL_STB_499US (0x03U) /*!< 131 stable count cycle, approx. 499us */
  222. #define CLK_XTAL_STB_988US (0x04U) /*!< 259 stable count cycle, approx. 988us */
  223. #define CLK_XTAL_STB_2MS (0x05U) /*!< 547 stable count cycle, approx. 2ms */
  224. #define CLK_XTAL_STB_4MS (0x06U) /*!< 1059 stable count cycle, approx. 4ms */
  225. #define CLK_XTAL_STB_8MS (0x07U) /*!< 2147 stable count cycle, approx. 8ms */
  226. #define CLK_XTAL_STB_16MS (0x08U) /*!< 4291 stable count cycle, approx. 16ms */
  227. #define CLK_XTAL_STB_31MS (0x09U) /*!< 8163 stable count cycle, approx. 32ms */
  228. /**
  229. * @}
  230. */
  231. /**
  232. * @defgroup CLK_XTALDIV_State XTAL divide state Config
  233. * @{
  234. */
  235. #define CLK_XTALDIV_OFF (0x00UL)
  236. #define CLK_XTALDIV_ON (CMU_XTALDIVCR_FRADIVEN)
  237. /**
  238. * @}
  239. */
  240. /**
  241. * @defgroup CLK_XTALSTD_Config XTALSTD Config
  242. * @{
  243. */
  244. /**
  245. * @brief XTAL error detection on or off
  246. */
  247. #define CLK_XTALSTD_OFF (0x00U)
  248. #define CLK_XTALSTD_ON (CMU_XTALSTDCR_XTALSTDE)
  249. /**
  250. * @brief XTALSTD mode selection
  251. */
  252. #define CLK_XTALSTD_MD_RST (CMU_XTALSTDCR_XTALSTDRIS)
  253. #define CLK_XTALSTD_MD_INT (0x00U)
  254. /**
  255. * @brief XTALSTD reset on or off
  256. */
  257. #define CLK_XTALSTD_RST_OFF (0x00U)
  258. #define CLK_XTALSTD_RST_ON (CMU_XTALSTDCR_XTALSTDRE)
  259. /**
  260. * @brief XTALSTD interrupt on or off
  261. */
  262. #define CLK_XTALSTD_INT_OFF (0x00U)
  263. #define CLK_XTALSTD_INT_ON (CMU_XTALSTDCR_XTALSTDIE)
  264. /**
  265. * @}
  266. */
  267. /**
  268. * @defgroup CLK_XTAL32_Config XTAL32 Config
  269. * @{
  270. */
  271. /**
  272. * @brief XTAL32 function config.
  273. */
  274. #define CLK_XTAL32_OFF (CMU_XTAL32CR_XTAL32STP)
  275. #define CLK_XTAL32_ON (0x00U)
  276. /**
  277. * @brief XTAL32 driver ability.
  278. */
  279. #define CLK_XTAL32_DRV_MID (0x00U)
  280. #define CLK_XTAL32_DRV_HIGH (0x01U)
  281. /**
  282. * @brief XTAL32 filtering selection.
  283. */
  284. #define CLK_XTAL32_FILTER_ALL_MD (0x00U) /*!< Valid in run,stop,power down mode. */
  285. #define CLK_XTAL32_FILTER_RUN_MD (0x01U) /*!< Valid in run mode. */
  286. #define CLK_XTAL32_FILTER_OFF (0x03U) /*!< Invalid in run,stop,power down mode. */
  287. /**
  288. * @}
  289. */
  290. /**
  291. * @defgroup CLK_HRC_Config HRC Config
  292. * @{
  293. */
  294. #define CLK_HRC_OFF (CMU_HRCCR_HRCSTP)
  295. #define CLK_HRC_ON (0x00U)
  296. /**
  297. * @}
  298. */
  299. /**
  300. * @defgroup CLK_STB_Flag CLK Stable Flags
  301. * @{
  302. */
  303. #define CLK_STB_FLAG_HRC (CMU_OSCSTBSR_HRCSTBF)
  304. #define CLK_STB_FLAG_XTAL (CMU_OSCSTBSR_XTALSTBF)
  305. #define CLK_STB_FLAG_PLL (CMU_OSCSTBSR_PLLHSTBF)
  306. #define CLK_STB_FLAG_MASK (CMU_OSCSTBSR_HRCSTBF | CMU_OSCSTBSR_XTALSTBF | CMU_OSCSTBSR_PLLHSTBF)
  307. /**
  308. * @}
  309. */
  310. /**
  311. * @defgroup CLK_System_Clock_Source System Clock Source
  312. * @{
  313. */
  314. #define CLK_SYSCLK_SRC_HRC (0x00U)
  315. #define CLK_SYSCLK_SRC_MRC (0x01U)
  316. #define CLK_SYSCLK_SRC_LRC (0x02U)
  317. #define CLK_SYSCLK_SRC_XTAL (0x03U)
  318. #define CLK_SYSCLK_SRC_XTAL32 (0x04U)
  319. #define CLK_SYSCLK_SRC_PLL (0x05U)
  320. /**
  321. * @}
  322. */
  323. /**
  324. * @defgroup CLK_Bus_Clock_Sel Clock Bus Clock Category Selection
  325. * @{
  326. */
  327. #define CLK_BUS_PCLK0 (CMU_SCFGR_PCLK0S)
  328. #define CLK_BUS_PCLK1 (CMU_SCFGR_PCLK1S)
  329. #define CLK_BUS_PCLK2 (CMU_SCFGR_PCLK2S)
  330. #define CLK_BUS_PCLK3 (CMU_SCFGR_PCLK3S)
  331. #define CLK_BUS_PCLK4 (CMU_SCFGR_PCLK4S)
  332. #define CLK_BUS_EXCLK (CMU_SCFGR_EXCKS)
  333. #define CLK_BUS_HCLK (CMU_SCFGR_HCLKS)
  334. #define CLK_BUS_CLK_ALL (CLK_BUS_PCLK0 | CLK_BUS_PCLK1 | CLK_BUS_PCLK2 | CLK_BUS_PCLK3 | \
  335. CLK_BUS_PCLK4 | CLK_BUS_EXCLK | CLK_BUS_HCLK)
  336. /**
  337. * @}
  338. */
  339. /**
  340. * @defgroup CLK_Clock_Divider Clock Divider
  341. * @{
  342. */
  343. /**
  344. * @defgroup CLK_System_Clock_Divider System Clock Divider
  345. * @{
  346. */
  347. #define CLK_SYSCLK_DIV1 (0x00U)
  348. #define CLK_SYSCLK_DIV2 (0x01U)
  349. #define CLK_SYSCLK_DIV4 (0x02U)
  350. #define CLK_SYSCLK_DIV8 (0x03U)
  351. #define CLK_SYSCLK_DIV16 (0x04U)
  352. #define CLK_SYSCLK_DIV32 (0x05U)
  353. #define CLK_SYSCLK_DIV64 (0x06U)
  354. /**
  355. * @}
  356. */
  357. /**
  358. * @defgroup CLK_HCLK_Divider CLK HCLK Divider
  359. * @{
  360. */
  361. #define CLK_HCLK_DIV1 (CLK_SYSCLK_DIV1 << CMU_SCFGR_HCLKS_POS)
  362. #define CLK_HCLK_DIV2 (CLK_SYSCLK_DIV2 << CMU_SCFGR_HCLKS_POS)
  363. #define CLK_HCLK_DIV4 (CLK_SYSCLK_DIV4 << CMU_SCFGR_HCLKS_POS)
  364. #define CLK_HCLK_DIV8 (CLK_SYSCLK_DIV8 << CMU_SCFGR_HCLKS_POS)
  365. #define CLK_HCLK_DIV16 (CLK_SYSCLK_DIV16 << CMU_SCFGR_HCLKS_POS)
  366. #define CLK_HCLK_DIV32 (CLK_SYSCLK_DIV32 << CMU_SCFGR_HCLKS_POS)
  367. #define CLK_HCLK_DIV64 (CLK_SYSCLK_DIV64 << CMU_SCFGR_HCLKS_POS)
  368. /**
  369. * @}
  370. */
  371. /**
  372. * @defgroup CLK_PCLK1_Divider CLK PCLK1 Divider
  373. * @{
  374. */
  375. #define CLK_PCLK1_DIV1 (CLK_SYSCLK_DIV1 << CMU_SCFGR_PCLK1S_POS)
  376. #define CLK_PCLK1_DIV2 (CLK_SYSCLK_DIV2 << CMU_SCFGR_PCLK1S_POS)
  377. #define CLK_PCLK1_DIV4 (CLK_SYSCLK_DIV4 << CMU_SCFGR_PCLK1S_POS)
  378. #define CLK_PCLK1_DIV8 (CLK_SYSCLK_DIV8 << CMU_SCFGR_PCLK1S_POS)
  379. #define CLK_PCLK1_DIV16 (CLK_SYSCLK_DIV16 << CMU_SCFGR_PCLK1S_POS)
  380. #define CLK_PCLK1_DIV32 (CLK_SYSCLK_DIV32 << CMU_SCFGR_PCLK1S_POS)
  381. #define CLK_PCLK1_DIV64 (CLK_SYSCLK_DIV64 << CMU_SCFGR_PCLK1S_POS)
  382. /**
  383. * @}
  384. */
  385. /**
  386. * @defgroup CLK_PCLK4_Divider CLK PCLK4 Divider
  387. * @{
  388. */
  389. #define CLK_PCLK4_DIV1 (CLK_SYSCLK_DIV1 << CMU_SCFGR_PCLK4S_POS)
  390. #define CLK_PCLK4_DIV2 (CLK_SYSCLK_DIV2 << CMU_SCFGR_PCLK4S_POS)
  391. #define CLK_PCLK4_DIV4 (CLK_SYSCLK_DIV4 << CMU_SCFGR_PCLK4S_POS)
  392. #define CLK_PCLK4_DIV8 (CLK_SYSCLK_DIV8 << CMU_SCFGR_PCLK4S_POS)
  393. #define CLK_PCLK4_DIV16 (CLK_SYSCLK_DIV16 << CMU_SCFGR_PCLK4S_POS)
  394. #define CLK_PCLK4_DIV32 (CLK_SYSCLK_DIV32 << CMU_SCFGR_PCLK4S_POS)
  395. #define CLK_PCLK4_DIV64 (CLK_SYSCLK_DIV64 << CMU_SCFGR_PCLK4S_POS)
  396. /**
  397. * @}
  398. */
  399. /**
  400. * @defgroup CLK_PCLK3_Divider CLK PCLK3 Divider
  401. * @{
  402. */
  403. #define CLK_PCLK3_DIV1 (CLK_SYSCLK_DIV1 << CMU_SCFGR_PCLK3S_POS)
  404. #define CLK_PCLK3_DIV2 (CLK_SYSCLK_DIV2 << CMU_SCFGR_PCLK3S_POS)
  405. #define CLK_PCLK3_DIV4 (CLK_SYSCLK_DIV4 << CMU_SCFGR_PCLK3S_POS)
  406. #define CLK_PCLK3_DIV8 (CLK_SYSCLK_DIV8 << CMU_SCFGR_PCLK3S_POS)
  407. #define CLK_PCLK3_DIV16 (CLK_SYSCLK_DIV16 << CMU_SCFGR_PCLK3S_POS)
  408. #define CLK_PCLK3_DIV32 (CLK_SYSCLK_DIV32 << CMU_SCFGR_PCLK3S_POS)
  409. #define CLK_PCLK3_DIV64 (CLK_SYSCLK_DIV64 << CMU_SCFGR_PCLK3S_POS)
  410. /**
  411. * @}
  412. */
  413. /**
  414. * @defgroup CLK_EXCLK_Divider CLK EXCLK Divider
  415. * @{
  416. */
  417. #define CLK_EXCLK_DIV1 (CLK_SYSCLK_DIV1 << CMU_SCFGR_EXCKS_POS)
  418. #define CLK_EXCLK_DIV2 (CLK_SYSCLK_DIV2 << CMU_SCFGR_EXCKS_POS)
  419. #define CLK_EXCLK_DIV4 (CLK_SYSCLK_DIV4 << CMU_SCFGR_EXCKS_POS)
  420. #define CLK_EXCLK_DIV8 (CLK_SYSCLK_DIV8 << CMU_SCFGR_EXCKS_POS)
  421. #define CLK_EXCLK_DIV16 (CLK_SYSCLK_DIV16 << CMU_SCFGR_EXCKS_POS)
  422. #define CLK_EXCLK_DIV32 (CLK_SYSCLK_DIV32 << CMU_SCFGR_EXCKS_POS)
  423. #define CLK_EXCLK_DIV64 (CLK_SYSCLK_DIV64 << CMU_SCFGR_EXCKS_POS)
  424. /**
  425. * @}
  426. */
  427. /**
  428. * @defgroup CLK_PCLK2_Divider CLK PCLK2 Divider
  429. * @{
  430. */
  431. #define CLK_PCLK2_DIV1 (CLK_SYSCLK_DIV1 << CMU_SCFGR_PCLK2S_POS)
  432. #define CLK_PCLK2_DIV2 (CLK_SYSCLK_DIV2 << CMU_SCFGR_PCLK2S_POS)
  433. #define CLK_PCLK2_DIV4 (CLK_SYSCLK_DIV4 << CMU_SCFGR_PCLK2S_POS)
  434. #define CLK_PCLK2_DIV8 (CLK_SYSCLK_DIV8 << CMU_SCFGR_PCLK2S_POS)
  435. #define CLK_PCLK2_DIV16 (CLK_SYSCLK_DIV16 << CMU_SCFGR_PCLK2S_POS)
  436. #define CLK_PCLK2_DIV32 (CLK_SYSCLK_DIV32 << CMU_SCFGR_PCLK2S_POS)
  437. #define CLK_PCLK2_DIV64 (CLK_SYSCLK_DIV64 << CMU_SCFGR_PCLK2S_POS)
  438. /**
  439. * @}
  440. */
  441. /**
  442. * @defgroup CLK_PCLK0_Divider CLK PCLK0 Divider
  443. * @{
  444. */
  445. #define CLK_PCLK0_DIV1 (CLK_SYSCLK_DIV1 << CMU_SCFGR_PCLK0S_POS)
  446. #define CLK_PCLK0_DIV2 (CLK_SYSCLK_DIV2 << CMU_SCFGR_PCLK0S_POS)
  447. #define CLK_PCLK0_DIV4 (CLK_SYSCLK_DIV4 << CMU_SCFGR_PCLK0S_POS)
  448. #define CLK_PCLK0_DIV8 (CLK_SYSCLK_DIV8 << CMU_SCFGR_PCLK0S_POS)
  449. #define CLK_PCLK0_DIV16 (CLK_SYSCLK_DIV16 << CMU_SCFGR_PCLK0S_POS)
  450. #define CLK_PCLK0_DIV32 (CLK_SYSCLK_DIV32 << CMU_SCFGR_PCLK0S_POS)
  451. #define CLK_PCLK0_DIV64 (CLK_SYSCLK_DIV64 << CMU_SCFGR_PCLK0S_POS)
  452. /**
  453. * @}
  454. */
  455. /**
  456. * @}
  457. */
  458. /**
  459. * @defgroup CLK_CANCLK_Sel CLK CAN Clock Selection
  460. * @{
  461. */
  462. #define CLK_MCANCLK_SYSCLK_DIV2 (0x01U)
  463. #define CLK_MCANCLK_SYSCLK_DIV3 (0x02U)
  464. #define CLK_MCANCLK_SYSCLK_DIV4 (0x03U)
  465. #define CLK_MCANCLK_SYSCLK_DIV5 (0x04U)
  466. #define CLK_MCANCLK_SYSCLK_DIV6 (0x05U)
  467. #define CLK_MCANCLK_SYSCLK_DIV7 (0x06U)
  468. #define CLK_MCANCLK_SYSCLK_DIV8 (0x07U)
  469. #define CLK_MCANCLK_PLLQ (0x08U)
  470. #define CLK_MCANCLK_PLLR (0x09U)
  471. #define CLK_MCANCLK_XTAL (0x0DU)
  472. /**
  473. * @}
  474. */
  475. /**
  476. * @defgroup CLK_CAN_Sel CLK CAN Channel Selection
  477. * @{
  478. */
  479. #define CLK_MCAN1 (0x01U)
  480. #define CLK_MCAN2 (0x02U)
  481. /**
  482. * @}
  483. */
  484. /**
  485. * @defgroup CLK_PERIPH_Sel CLK Peripheral Clock Selection
  486. * @note ADC,I2S,DAC,TRNG
  487. * @{
  488. */
  489. #define CLK_PERIPHCLK_PCLK (0x0000U) /* PCLK2 is used for ADC clock, PCLK4 is used for DAC/TRNG clock */
  490. #define CLK_PERIPHCLK_PLLQ (0x0008U)
  491. #define CLK_PERIPHCLK_PLLR (0x0009U)
  492. /**
  493. * @}
  494. */
  495. /**
  496. * @defgroup CLK_TPIU_Divider TPIU clock divider
  497. * @{
  498. */
  499. #define CLK_TPIUCLK_DIV1 (0x00U)
  500. #define CLK_TPIUCLK_DIV2 (0x01U)
  501. #define CLK_TPIUCLK_DIV4 (0x02U)
  502. /**
  503. * @}
  504. */
  505. /**
  506. * @defgroup CLK_MCO_Channel_Sel CLK MCO Channel Select
  507. * @{
  508. */
  509. #define CLK_MCO1 (0x00U)
  510. #define CLK_MCO2 (0x01U)
  511. /**
  512. * @}
  513. */
  514. /**
  515. * @defgroup CLK_MCO_Clock_Source CLK MCO Clock Source
  516. * @{
  517. */
  518. #define CLK_MCO_SRC_HRC (0x00U)
  519. #define CLK_MCO_SRC_MRC (0x01U)
  520. #define CLK_MCO_SRC_LRC (0x02U)
  521. #define CLK_MCO_SRC_XTAL (0x03U)
  522. #define CLK_MCO_SRC_XTAL32 (0x04U)
  523. #define CLK_MCO_SRC_PLLP (0x06U)
  524. #define CLK_MCO_SRC_PLLQ (0x08U)
  525. #define CLK_MCO_SRC_HCLK (0x0BU)
  526. /**
  527. * @}
  528. */
  529. /**
  530. * @defgroup CLK_MCO_Clock_Prescaler CLK MCO Clock Prescaler
  531. * @{
  532. */
  533. #define CLK_MCO_DIV1 (0x00U << CMU_MCOCFGR_MCODIV_POS)
  534. #define CLK_MCO_DIV2 (0x01U << CMU_MCOCFGR_MCODIV_POS)
  535. #define CLK_MCO_DIV4 (0x02U << CMU_MCOCFGR_MCODIV_POS)
  536. #define CLK_MCO_DIV8 (0x03U << CMU_MCOCFGR_MCODIV_POS)
  537. #define CLK_MCO_DIV16 (0x04U << CMU_MCOCFGR_MCODIV_POS)
  538. #define CLK_MCO_DIV32 (0x05U << CMU_MCOCFGR_MCODIV_POS)
  539. #define CLK_MCO_DIV64 (0x06U << CMU_MCOCFGR_MCODIV_POS)
  540. #define CLK_MCO_DIV128 (0x07U << CMU_MCOCFGR_MCODIV_POS)
  541. /**
  542. * @}
  543. */
  544. /**
  545. * @}
  546. */
  547. /*******************************************************************************
  548. * Global variable definitions ('extern')
  549. ******************************************************************************/
  550. /*******************************************************************************
  551. Global function prototypes (definition in C source)
  552. ******************************************************************************/
  553. /**
  554. * @addtogroup CLK_Global_Functions
  555. * @{
  556. */
  557. int32_t CLK_HrcCmd(en_functional_state_t enNewState);
  558. int32_t CLK_MrcCmd(en_functional_state_t enNewState);
  559. int32_t CLK_LrcCmd(en_functional_state_t enNewState);
  560. void CLK_HrcTrim(int8_t i8TrimVal);
  561. void CLK_MrcTrim(int8_t i8TrimVal);
  562. void CLK_LrcTrim(int8_t i8TrimVal);
  563. int32_t CLK_XtalStructInit(stc_clock_xtal_init_t *pstcXtalInit);
  564. int32_t CLK_XtalInit(const stc_clock_xtal_init_t *pstcXtalInit);
  565. int32_t CLK_XtalCmd(en_functional_state_t enNewState);
  566. void CLK_XtalDivCmd(en_functional_state_t enNewState);
  567. int32_t CLK_XtalDivStructInit(stc_clock_xtaldiv_init_t *pstcXtalDivInit);
  568. int32_t CLK_XtalDivInit(const stc_clock_xtaldiv_init_t *pstcXtalDivInit);
  569. int32_t CLK_XtalStdStructInit(stc_clock_xtalstd_init_t *pstcXtalStdInit);
  570. int32_t CLK_XtalStdInit(const stc_clock_xtalstd_init_t *pstcXtalStdInit);
  571. void CLK_ClearXtalStdStatus(void);
  572. en_flag_status_t CLK_GetXtalStdStatus(void);
  573. int32_t CLK_Xtal32StructInit(stc_clock_xtal32_init_t *pstcXtal32Init);
  574. int32_t CLK_Xtal32Init(const stc_clock_xtal32_init_t *pstcXtal32Init);
  575. int32_t CLK_Xtal32Cmd(en_functional_state_t enNewState);
  576. void CLK_SetPLLSrc(uint32_t u32PllSrc);
  577. int32_t CLK_PLLStructInit(stc_clock_pll_init_t *pstcPLLInit);
  578. int32_t CLK_PLLInit(const stc_clock_pll_init_t *pstcPLLInit);
  579. int32_t CLK_PLLCmd(en_functional_state_t enNewState);
  580. int32_t CLK_GetPLLClockFreq(stc_pll_clock_freq_t *pstcPllClkFreq);
  581. void CLK_MCOConfig(uint8_t u8Ch, uint8_t u8Src, uint8_t u8Div);
  582. void CLK_MCOCmd(uint8_t u8Ch, en_functional_state_t enNewState);
  583. en_flag_status_t CLK_GetStableStatus(uint8_t u8Flag);
  584. void CLK_SetSysClockSrc(uint8_t u8Src);
  585. void CLK_SetClockDiv(uint32_t u32Clock, uint32_t u32Div);
  586. int32_t CLK_GetClockFreq(stc_clock_freq_t *pstcClockFreq);
  587. uint32_t CLK_GetBusClockFreq(uint32_t u32Clock);
  588. void CLK_SetPeriClockSrc(uint16_t u16Src);
  589. void CLK_SetCANClockSrc(uint8_t u8Unit, uint8_t u8Src);
  590. void CLK_TpiuClockCmd(en_functional_state_t enNewState);
  591. void CLK_SetTpiuClockDiv(uint8_t u8Div);
  592. /**
  593. * @}
  594. */
  595. #endif /* LL_CLK_ENABLE */
  596. /**
  597. * @}
  598. */
  599. /**
  600. * @}
  601. */
  602. #ifdef __cplusplus
  603. }
  604. #endif
  605. #endif /* __HC32_LL_CLK_H__ */
  606. /*******************************************************************************
  607. * EOF (not truncated)
  608. ******************************************************************************/