hc32_ll_icg.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_icg.h
  4. * @brief This file contains all the Macro Definitions of the ICG 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_ICG_H__
  22. #define __HC32_LL_ICG_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_ICG
  40. * @{
  41. */
  42. #if (LL_ICG_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /*******************************************************************************
  47. * Global pre-processor symbols/macros ('#define')
  48. ******************************************************************************/
  49. /**
  50. * @defgroup ICG_Global_Macros ICG Global Macros
  51. * @{
  52. */
  53. /**
  54. * @defgroup ICG_SWDT_Reset_State ICG SWDT Reset State
  55. * @{
  56. */
  57. #define ICG_SWDT_RST_START (0UL) /*!< SWDT auto start after reset */
  58. #define ICG_SWDT_RST_STOP (ICG_ICG0_SWDTAUTS) /*!< SWDT stop after reset */
  59. /**
  60. * @}
  61. */
  62. /**
  63. * @defgroup ICG_SWDT_Exception_Type ICG SWDT Exception Type
  64. * @{
  65. */
  66. #define ICG_SWDT_EXP_TYPE_INT (0UL) /*!< SWDT trigger interrupt */
  67. #define ICG_SWDT_EXP_TYPE_RST (ICG_ICG0_SWDTITS) /*!< SWDT trigger reset */
  68. /**
  69. * @}
  70. */
  71. /**
  72. * @defgroup ICG_SWDT_Count_Period ICG SWDT Count Period
  73. * @{
  74. */
  75. #define ICG_SWDT_CNT_PERIOD256 (0UL) /*!< 256 clock cycle */
  76. #define ICG_SWDT_CNT_PERIOD4096 (ICG_ICG0_SWDTPERI_0) /*!< 4096 clock cycle */
  77. #define ICG_SWDT_CNT_PERIOD16384 (ICG_ICG0_SWDTPERI_1) /*!< 16384 clock cycle */
  78. #define ICG_SWDT_CNT_PERIOD65536 (ICG_ICG0_SWDTPERI) /*!< 65536 clock cycle */
  79. /**
  80. * @}
  81. */
  82. /**
  83. * @defgroup ICG_SWDT_Clock_Division ICG SWDT Clock Division
  84. * @{
  85. */
  86. #define ICG_SWDT_CLK_DIV1 (0UL) /*!< CLK */
  87. #define ICG_SWDT_CLK_DIV16 (0x04UL << ICG_ICG0_SWDTCKS_POS) /*!< CLK/16 */
  88. #define ICG_SWDT_CLK_DIV32 (0x05UL << ICG_ICG0_SWDTCKS_POS) /*!< CLK/32 */
  89. #define ICG_SWDT_CLK_DIV64 (0x06UL << ICG_ICG0_SWDTCKS_POS) /*!< CLK/64 */
  90. #define ICG_SWDT_CLK_DIV128 (0x07UL << ICG_ICG0_SWDTCKS_POS) /*!< CLK/128 */
  91. #define ICG_SWDT_CLK_DIV256 (0x08UL << ICG_ICG0_SWDTCKS_POS) /*!< CLK/256 */
  92. #define ICG_SWDT_CLK_DIV2048 (0x0BUL << ICG_ICG0_SWDTCKS_POS) /*!< CLK/2048 */
  93. /**
  94. * @}
  95. */
  96. /**
  97. * @defgroup ICG_SWDT_Refresh_Range ICG SWDT Refresh Range
  98. * @{
  99. */
  100. #define ICG_SWDT_RANGE_0TO25PCT (0x01UL << ICG_ICG0_SWDTWDPT_POS) /*!< 0%~25% */
  101. #define ICG_SWDT_RANGE_25TO50PCT (0x02UL << ICG_ICG0_SWDTWDPT_POS) /*!< 25%~50% */
  102. #define ICG_SWDT_RANGE_0TO50PCT (0x03UL << ICG_ICG0_SWDTWDPT_POS) /*!< 0%~50% */
  103. #define ICG_SWDT_RANGE_50TO75PCT (0x04UL << ICG_ICG0_SWDTWDPT_POS) /*!< 50%~75% */
  104. #define ICG_SWDT_RANGE_0TO25PCT_50TO75PCT (0x05UL << ICG_ICG0_SWDTWDPT_POS) /*!< 0%~25% & 50%~75% */
  105. #define ICG_SWDT_RANGE_25TO75PCT (0x06UL << ICG_ICG0_SWDTWDPT_POS) /*!< 25%~75% */
  106. #define ICG_SWDT_RANGE_0TO75PCT (0x07UL << ICG_ICG0_SWDTWDPT_POS) /*!< 0%~75% */
  107. #define ICG_SWDT_RANGE_75TO100PCT (0x08UL << ICG_ICG0_SWDTWDPT_POS) /*!< 75%~100% */
  108. #define ICG_SWDT_RANGE_0TO25PCT_75TO100PCT (0x09UL << ICG_ICG0_SWDTWDPT_POS) /*!< 0%~25% & 75%~100% */
  109. #define ICG_SWDT_RANGE_25TO50PCT_75TO100PCT (0x0AUL << ICG_ICG0_SWDTWDPT_POS) /*!< 25%~50% & 75%~100% */
  110. #define ICG_SWDT_RANGE_0TO50PCT_75TO100PCT (0x0BUL << ICG_ICG0_SWDTWDPT_POS) /*!< 0%~50% & 75%~100% */
  111. #define ICG_SWDT_RANGE_50TO100PCT (0x0CUL << ICG_ICG0_SWDTWDPT_POS) /*!< 50%~100% */
  112. #define ICG_SWDT_RANGE_0TO25PCT_50TO100PCT (0x0DUL << ICG_ICG0_SWDTWDPT_POS) /*!< 0%~25% & 50%~100% */
  113. #define ICG_SWDT_RANGE_25TO100PCT (0x0EUL << ICG_ICG0_SWDTWDPT_POS) /*!< 25%~100% */
  114. #define ICG_SWDT_RANGE_0TO100PCT (0x0FUL << ICG_ICG0_SWDTWDPT_POS) /*!< 0%~100% */
  115. /**
  116. * @}
  117. */
  118. /**
  119. * @defgroup ICG_SWDT_LPM_Count ICG SWDT Low Power Mode Count
  120. * @brief Counting control of SWDT in sleep/stop mode
  121. * @{
  122. */
  123. #define ICG_SWDT_LPM_CNT_CONTINUE (0UL) /*!< Continue counting in sleep/stop mode */
  124. #define ICG_SWDT_LPM_CNT_STOP (ICG_ICG0_SWDTSLPOFF) /*!< Stop counting in sleep/stop mode */
  125. /**
  126. * @}
  127. */
  128. /**
  129. * @defgroup ICG_WDT_Reset_State ICG WDT Reset State
  130. * @{
  131. */
  132. #define ICG_WDT_RST_START (0UL) /*!< WDT auto start after reset */
  133. #define ICG_WDT_RST_STOP (ICG_ICG0_WDTAUTS) /*!< WDT stop after reset */
  134. /**
  135. * @}
  136. */
  137. /**
  138. * @defgroup ICG_WDT_Exception_Type ICG WDT Exception Type
  139. * @{
  140. */
  141. #define ICG_WDT_EXP_TYPE_INT (0UL) /*!< WDT trigger interrupt */
  142. #define ICG_WDT_EXP_TYPE_RST (ICG_ICG0_WDTITS) /*!< WDT trigger reset */
  143. /**
  144. * @}
  145. */
  146. /**
  147. * @defgroup ICG_WDT_Count_Period ICG WDT Count Period
  148. * @{
  149. */
  150. #define REDEF_ICG_WDTPERI_POS ICG_ICG0_WDTPERI_POS
  151. #define ICG_WDT_CNT_PERIOD256 (0UL) /*!< 256 clock cycle */
  152. #define ICG_WDT_CNT_PERIOD4096 (0x01UL << REDEF_ICG_WDTPERI_POS) /*!< 4096 clock cycle */
  153. #define ICG_WDT_CNT_PERIOD16384 (0x02UL << REDEF_ICG_WDTPERI_POS) /*!< 16384 clock cycle */
  154. #define ICG_WDT_CNT_PERIOD65536 (0x03UL << REDEF_ICG_WDTPERI_POS) /*!< 65536 clock cycle */
  155. /**
  156. * @}
  157. */
  158. /**
  159. * @defgroup ICG_WDT_Clock_Division ICG WDT Clock Division
  160. * @{
  161. */
  162. #define REDEF_ICG_WDTCKS_POS ICG_ICG0_WDTCKS_POS
  163. #define ICG_WDT_CLK_DIV4 (0x02UL << REDEF_ICG_WDTCKS_POS) /*!< CLK/4 */
  164. #define ICG_WDT_CLK_DIV64 (0x06UL << REDEF_ICG_WDTCKS_POS) /*!< CLK/64 */
  165. #define ICG_WDT_CLK_DIV128 (0x07UL << REDEF_ICG_WDTCKS_POS) /*!< CLK/128 */
  166. #define ICG_WDT_CLK_DIV256 (0x08UL << REDEF_ICG_WDTCKS_POS) /*!< CLK/256 */
  167. #define ICG_WDT_CLK_DIV512 (0x09UL << REDEF_ICG_WDTCKS_POS) /*!< CLK/512 */
  168. #define ICG_WDT_CLK_DIV1024 (0x0AUL << REDEF_ICG_WDTCKS_POS) /*!< CLK/1024 */
  169. #define ICG_WDT_CLK_DIV2048 (0x0BUL << REDEF_ICG_WDTCKS_POS) /*!< CLK/2048 */
  170. #define ICG_WDT_CLK_DIV8192 (0x0DUL << REDEF_ICG_WDTCKS_POS) /*!< CLK/8192 */
  171. /**
  172. * @}
  173. */
  174. /**
  175. * @defgroup ICG_WDT_Refresh_Range ICG WDT Refresh Range
  176. * @{
  177. */
  178. #define REDEF_ICG_WDTWDPT_POS ICG_ICG0_WDTWDPT_POS
  179. #define ICG_WDT_RANGE_0TO25PCT (0x01UL << REDEF_ICG_WDTWDPT_POS) /*!< 0%~25% */
  180. #define ICG_WDT_RANGE_25TO50PCT (0x02UL << REDEF_ICG_WDTWDPT_POS) /*!< 25%~50% */
  181. #define ICG_WDT_RANGE_0TO50PCT (0x03UL << REDEF_ICG_WDTWDPT_POS) /*!< 0%~50% */
  182. #define ICG_WDT_RANGE_50TO75PCT (0x04UL << REDEF_ICG_WDTWDPT_POS) /*!< 50%~75% */
  183. #define ICG_WDT_RANGE_0TO25PCT_50TO75PCT (0x05UL << REDEF_ICG_WDTWDPT_POS) /*!< 0%~25% & 50%~75% */
  184. #define ICG_WDT_RANGE_25TO75PCT (0x06UL << REDEF_ICG_WDTWDPT_POS) /*!< 25%~75% */
  185. #define ICG_WDT_RANGE_0TO75PCT (0x07UL << REDEF_ICG_WDTWDPT_POS) /*!< 0%~75% */
  186. #define ICG_WDT_RANGE_75TO100PCT (0x08UL << REDEF_ICG_WDTWDPT_POS) /*!< 75%~100% */
  187. #define ICG_WDT_RANGE_0TO25PCT_75TO100PCT (0x09UL << REDEF_ICG_WDTWDPT_POS) /*!< 0%~25% & 75%~100% */
  188. #define ICG_WDT_RANGE_25TO50PCT_75TO100PCT (0x0AUL << REDEF_ICG_WDTWDPT_POS) /*!< 25%~50% & 75%~100% */
  189. #define ICG_WDT_RANGE_0TO50PCT_75TO100PCT (0x0BUL << REDEF_ICG_WDTWDPT_POS) /*!< 0%~50% & 75%~100% */
  190. #define ICG_WDT_RANGE_50TO100PCT (0x0CUL << REDEF_ICG_WDTWDPT_POS) /*!< 50%~100% */
  191. #define ICG_WDT_RANGE_0TO25PCT_50TO100PCT (0x0DUL << REDEF_ICG_WDTWDPT_POS) /*!< 0%~25% & 50%~100% */
  192. #define ICG_WDT_RANGE_25TO100PCT (0x0EUL << REDEF_ICG_WDTWDPT_POS) /*!< 25%~100% */
  193. #define ICG_WDT_RANGE_0TO100PCT (0x0FUL << REDEF_ICG_WDTWDPT_POS) /*!< 0%~100% */
  194. /**
  195. * @}
  196. */
  197. /**
  198. * @defgroup ICG_WDT_LPM_Count ICG WDT Low Power Mode Count
  199. * @brief Counting control of WDT in sleep mode
  200. * @{
  201. */
  202. #define ICG_WDT_LPM_CNT_CONTINUE (0UL) /*!< Continue counting in sleep mode */
  203. #define ICG_WDT_LPM_CNT_STOP (ICG_ICG0_WDTSLPOFF) /*!< Stop counting in sleep mode */
  204. /**
  205. * @}
  206. */
  207. /**
  208. * @defgroup ICG_BOR_Voltage_Threshold ICG BOR Voltage Threshold
  209. * @{
  210. */
  211. #define ICG_BOR_VOL_THRESHOLD_LVL0 (0UL) /*!< BOR voltage threshold 1.9V */
  212. #define ICG_BOR_VOL_THRESHOLD_LVL1 (ICG_ICG1_BOR_LEV_0) /*!< BOR voltage threshold 2.0V */
  213. #define ICG_BOR_VOL_THRESHOLD_LVL2 (ICG_ICG1_BOR_LEV_1) /*!< BOR voltage threshold 2.1V */
  214. #define ICG_BOR_VOL_THRESHOLD_LVL3 (ICG_ICG1_BOR_LEV) /*!< BOR voltage threshold 2.3V */
  215. /**
  216. * @}
  217. */
  218. /**
  219. * @defgroup ICG_BOR_Reset_State ICG BOR Reset State
  220. * @{
  221. */
  222. #define ICG_BOR_RST_ENABLE (0UL) /*!< Enable BOR voltage detection after reset */
  223. #define ICG_BOR_RST_DISABLE (ICG_ICG1_BORDIS) /*!< Disable BOR voltage detection after reset */
  224. /**
  225. * @}
  226. */
  227. /**
  228. * @defgroup ICG_HRC_Frequency_Select ICG HRC Frequency Select
  229. * @{
  230. */
  231. #define ICG_HRC_20M (0UL) /*!< HRC = 20MHZ */
  232. #define ICG_HRC_16M (ICG_ICG1_HRCFREQSEL) /*!< HRC = 16MHZ */
  233. /**
  234. * @}
  235. */
  236. /**
  237. * @defgroup ICG_HRC_Reset_State ICG HRC Reset State
  238. * @{
  239. */
  240. #define ICG_HRC_RST_OSCILLATION (0UL) /*!< HRC Oscillation after reset */
  241. #define ICG_HRC_RST_STOP (ICG_ICG1_HRCSTOP) /*!< HRC stop after reset */
  242. /**
  243. * @}
  244. */
  245. /**
  246. * @defgroup ICG_FLASH_Protect_Reset_State ICG FLASH Protect Reset State
  247. * @brief Enable or disable D-BUS read protection for addresses 0x00000000 - 0x0001FFFF
  248. * @{
  249. */
  250. #define ICG_FLASH_PROTECT_RST_DISABLE (0xFFFFFFFFUL) /*!< Disable D-BUS read protection after reset */
  251. #define ICG_FLASH_PROTECT_RST_ENABLE (0x00004450UL) /*!< Enable D-BUS read protection after reset */
  252. /**
  253. * @}
  254. */
  255. /**
  256. * @}
  257. */
  258. /**
  259. * @defgroup ICG_Register_Configuration ICG Register Configuration
  260. * @{
  261. */
  262. /**
  263. * @defgroup ICG_SWDT_Preload_Configuration ICG SWDT Preload Configuration
  264. * @{
  265. */
  266. /* SWDT register config */
  267. #define ICG_RB_SWDT_AUTS (ICG_SWDT_RST_STOP)
  268. #define ICG_RB_SWDT_ITS (ICG_SWDT_EXP_TYPE_RST)
  269. #define ICG_RB_SWDT_PERI (ICG_SWDT_CNT_PERIOD65536)
  270. #define ICG_RB_SWDT_CKS (ICG_SWDT_CLK_DIV2048)
  271. #define ICG_RB_SWDT_WDPT (ICG_SWDT_RANGE_0TO100PCT)
  272. #define ICG_RB_SWDT_SLTPOFF (ICG_SWDT_LPM_CNT_STOP)
  273. /* SWDT register value */
  274. #define ICG_REG_SWDT_CONFIG (ICG_RB_SWDT_AUTS | ICG_RB_SWDT_ITS | ICG_RB_SWDT_PERI | \
  275. ICG_RB_SWDT_CKS | ICG_RB_SWDT_WDPT | ICG_RB_SWDT_SLTPOFF)
  276. /**
  277. * @}
  278. */
  279. /**
  280. * @defgroup ICG_WDT_Preload_Configuration ICG WDT Preload Configuration
  281. * @{
  282. */
  283. /* WDT register config */
  284. #define ICG_RB_WDT_AUTS (ICG_WDT_RST_STOP)
  285. #define ICG_RB_WDT_ITS (ICG_WDT_EXP_TYPE_RST)
  286. #define ICG_RB_WDT_PERI (ICG_WDT_CNT_PERIOD65536)
  287. #define ICG_RB_WDT_CKS (ICG_WDT_CLK_DIV8192)
  288. #define ICG_RB_WDT_WDPT (ICG_WDT_RANGE_0TO100PCT)
  289. #define ICG_RB_WDT_SLTPOFF (ICG_WDT_LPM_CNT_STOP)
  290. /* WDT register value */
  291. #define ICG_REG_WDT_CONFIG (ICG_RB_WDT_AUTS | ICG_RB_WDT_ITS | ICG_RB_WDT_PERI | \
  292. ICG_RB_WDT_CKS | ICG_RB_WDT_WDPT | ICG_RB_WDT_SLTPOFF)
  293. /**
  294. * @}
  295. */
  296. /**
  297. * @defgroup ICG_BOR_Preload_Configuration ICG BOR Preload Configuration
  298. * @{
  299. */
  300. /* BOR register config */
  301. #define ICG_RB_BOR_LEV (ICG_BOR_VOL_THRESHOLD_LVL3)
  302. #define ICG_RB_BOR_DIS (ICG_BOR_RST_DISABLE)
  303. /* BOR register value */
  304. #define ICG_REG_BOR_CONFIG (ICG_RB_BOR_LEV | ICG_RB_BOR_DIS)
  305. /**
  306. * @}
  307. */
  308. /**
  309. * @defgroup ICG_HRC_Preload_Configuration ICG HRC Preload Configuration
  310. * @{
  311. */
  312. /* HRC register config */
  313. #define ICG_RB_HRC_FREQSEL (ICG_HRC_16M)
  314. #define ICG_RB_HRC_STOP (ICG_HRC_RST_STOP)
  315. /* HRC register value */
  316. #define ICG_REG_HRC_CONFIG (ICG_RB_HRC_FREQSEL | ICG_RB_HRC_STOP)
  317. /**
  318. * @}
  319. */
  320. /**
  321. * @defgroup ICG_FLASH_Protect_Preload_Configuration ICG FLASH Protect Preload Configuration
  322. * @{
  323. */
  324. /* FLASH Read Protect register value */
  325. #define ICG_REG_FLASH_PROTECT_CONFIG (ICG_FLASH_PROTECT_RST_DISABLE)
  326. /**
  327. * @}
  328. */
  329. /**
  330. * @defgroup ICG_FLASH_Boot_Source_Configuration ICG FLASH Boot Source Configuration
  331. * @note The register is valid when the MD pin is at high voltage.
  332. * @{
  333. */
  334. /* Boot Source register value */
  335. #define ICG_REG_BOOT_SRC_MAIN_FLASH (0x58480448UL)
  336. #define ICG_REG_BOOT_SRC_SYS_FLASH (0xFFFFFFFFUL)
  337. /**
  338. * @}
  339. */
  340. /**
  341. * @}
  342. */
  343. /**
  344. * @defgroup ICG_Register_Value ICG Register Value
  345. * @{
  346. */
  347. /* ICG register value */
  348. #ifndef ICG_REG_CFG0_CONST
  349. #define ICG_REG_CFG0_CONST (ICG_REG_WDT_CONFIG | ICG_REG_SWDT_CONFIG | 0xE000E000UL)
  350. #endif
  351. #ifndef ICG_REG_CFG1_CONST
  352. #define ICG_REG_CFG1_CONST (ICG_REG_BOR_CONFIG | ICG_REG_HRC_CONFIG | 0xFFF8FEFEUL)
  353. #endif
  354. #ifndef ICG_REG_CFG2_CONST
  355. #define ICG_REG_CFG2_CONST (0xFFFFFFFFUL)
  356. #endif
  357. #ifndef ICG_REG_CFG3_CONST
  358. #define ICG_REG_CFG3_CONST (ICG_REG_FLASH_PROTECT_CONFIG | 0xFFFF0000UL)
  359. #endif
  360. #ifndef ICG_REG_CFG4_CONST
  361. #define ICG_REG_CFG4_CONST (ICG_REG_BOOT_SRC_SYS_FLASH)
  362. #endif
  363. /* ICG reserved value */
  364. #define ICG_REG_RESV_CONST (0xFFFFFFFFUL)
  365. /**
  366. * @}
  367. */
  368. /*******************************************************************************
  369. * Global variable definitions ('extern')
  370. ******************************************************************************/
  371. /*******************************************************************************
  372. Global function prototypes (definition in C source)
  373. ******************************************************************************/
  374. #endif /* LL_ICG_ENABLE */
  375. /**
  376. * @}
  377. */
  378. /**
  379. * @}
  380. */
  381. #ifdef __cplusplus
  382. }
  383. #endif
  384. #endif /* __HC32_LL_ICG_H__ */
  385. /*******************************************************************************
  386. * EOF (not truncated)
  387. ******************************************************************************/