hc32f460_icg.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /*******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_icg.h
  11. **
  12. ** A detailed description is available at
  13. ** @link IcgGroup Initialize configure description @endlink
  14. **
  15. ** - 2018-10-15 CDT First version for Device Driver Library of ICG.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_ICG_H__
  19. #define __HC32F460_ICG_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_ICG_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup IcgGroup Initialize Configure(ICG)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /*******************************************************************************
  41. * Global pre-processor symbols/macros ('#define')
  42. ******************************************************************************/
  43. /**
  44. *******************************************************************************
  45. ** \brief SWDT running state after reset
  46. ******************************************************************************/
  47. #define SWDT_AUTO_START_AFTER_RESET ((uint16_t)0x0000) ///< SWDT Auto Start after reset
  48. #define SWDT_STOP_AFTER_RESET ((uint16_t)0x0001) ///< SWDT stop after reset
  49. /**
  50. *******************************************************************************
  51. ** \brief SWDT count underflow or refresh error trigger event type
  52. ******************************************************************************/
  53. #define SWDT_INTERRUPT_REQUEST ((uint16_t)0x0000) ///< WDT trigger interrupt request
  54. #define SWDT_RESET_REQUEST ((uint16_t)0x0002) ///< WDT trigger reset request
  55. /**
  56. *******************************************************************************
  57. ** \brief SWDT count underflow cycle
  58. ******************************************************************************/
  59. #define SWDT_COUNT_UNDERFLOW_CYCLE_256 ((uint16_t)0x0000) ///< 256 clock cycle
  60. #define SWDT_COUNT_UNDERFLOW_CYCLE_4096 ((uint16_t)0x0004) ///< 4096 clock cycle
  61. #define SWDT_COUNT_UNDERFLOW_CYCLE_16384 ((uint16_t)0x0008) ///< 16384 clock cycle
  62. #define SWDT_COUNT_UNDERFLOW_CYCLE_65536 ((uint16_t)0x000C) ///< 65536 clock cycle
  63. /**
  64. *******************************************************************************
  65. ** \brief SWDT count clock division
  66. ******************************************************************************/
  67. #define SWDT_COUNT_SWDTCLK_DIV1 ((uint16_t)0x0000) ///< SWDTCLK
  68. #define SWDT_COUNT_SWDTCLK_DIV16 ((uint16_t)0x0040) ///< SWDTCLK/16
  69. #define SWDT_COUNT_SWDTCLK_DIV32 ((uint16_t)0x0050) ///< SWDTCLK/32
  70. #define SWDT_COUNT_SWDTCLK_DIV64 ((uint16_t)0x0060) ///< SWDTCLK/64
  71. #define SWDT_COUNT_SWDTCLK_DIV128 ((uint16_t)0x0070) ///< SWDTCLK/128
  72. #define SWDT_COUNT_SWDTCLK_DIV256 ((uint16_t)0x0080) ///< SWDTCLK/256
  73. #define SWDT_COUNT_SWDTCLK_DIV2048 ((uint16_t)0x00B0) ///< SWDTCLK/2048
  74. /**
  75. *******************************************************************************
  76. ** \brief SWDT allow refresh percent range
  77. ******************************************************************************/
  78. #define SWDT_100PCT ((uint16_t)0x0000) ///< 100%
  79. #define SWDT_0To25PCT ((uint16_t)0x0100) ///< 0%~25%
  80. #define SWDT_25To50PCT ((uint16_t)0x0200) ///< 25%~50%
  81. #define SWDT_0To50PCT ((uint16_t)0x0300) ///< 0%~50%
  82. #define SWDT_50To75PCT ((uint16_t)0x0400) ///< 50%~75%
  83. #define SWDT_0To25PCT_50To75PCT ((uint16_t)0x0500) ///< 0%~25% & 50%~75%
  84. #define SWDT_25To75PCT ((uint16_t)0x0600) ///< 25%~75%
  85. #define SWDT_0To75PCT ((uint16_t)0x0700) ///< 0%~75%
  86. #define SWDT_75To100PCT ((uint16_t)0x0800) ///< 75%~100%
  87. #define SWDT_0To25PCT_75To100PCT ((uint16_t)0x0900) ///< 0%~25% & 75%~100%
  88. #define SWDT_25To50PCT_75To100PCT ((uint16_t)0x0A00) ///< 25%~50% & 75%~100%
  89. #define SWDT_0To50PCT_75To100PCT ((uint16_t)0x0B00) ///< 0%~50% & 75%~100%
  90. #define SWDT_50To100PCT ((uint16_t)0x0C00) ///< 50%~100%
  91. #define SWDT_0To25PCT_50To100PCT ((uint16_t)0x0D00) ///< 0%~25% & 50%~100%
  92. #define SWDT_25To100PCT ((uint16_t)0x0E00) ///< 25%~100%
  93. #define SWDT_0To100PCT ((uint16_t)0x0F00) ///< 0%~100%
  94. /**
  95. *******************************************************************************
  96. ** \brief SWDT count control in the sleep/stop mode
  97. ******************************************************************************/
  98. #define SWDT_SPECIAL_MODE_COUNT_CONTINUE ((uint16_t)0x0000) ///< SWDT count continue in the sleep/stop mode
  99. #define SWDT_SPECIAL_MODE_COUNT_STOP ((uint16_t)0x1000) ///< SWDT count stop in the sleep/stop mode
  100. /**
  101. *******************************************************************************
  102. ** \brief WDT running state after reset
  103. ******************************************************************************/
  104. #define WDT_AUTO_START_AFTER_RESET ((uint16_t)0x0000) ///< WDT Auto Start after reset
  105. #define WDT_STOP_AFTER_RESET ((uint16_t)0x0001) ///< WDT stop after reset
  106. /**
  107. *******************************************************************************
  108. ** \brief WDT count underflow or refresh error trigger event type
  109. ******************************************************************************/
  110. #define WDT_INTERRUPT_REQUEST ((uint16_t)0x0000) ///< WDT trigger interrupt request
  111. #define WDT_RESET_REQUEST ((uint16_t)0x0002) ///< WDT trigger reset request
  112. /**
  113. *******************************************************************************
  114. ** \brief WDT count underflow cycle
  115. ******************************************************************************/
  116. #define WDT_COUNT_UNDERFLOW_CYCLE_256 ((uint16_t)0x0000) ///< 256 clock cycle
  117. #define WDT_COUNT_UNDERFLOW_CYCLE_4096 ((uint16_t)0x0004) ///< 4096 clock cycle
  118. #define WDT_COUNT_UNDERFLOW_CYCLE_16384 ((uint16_t)0x0008) ///< 16384 clock cycle
  119. #define WDT_COUNT_UNDERFLOW_CYCLE_65536 ((uint16_t)0x000C) ///< 65536 clock cycle
  120. /**
  121. *******************************************************************************
  122. ** \brief WDT count clock division
  123. ******************************************************************************/
  124. #define WDT_COUNT_PCLK3_DIV4 ((uint16_t)0x0020) ///< PCLK3/4
  125. #define WDT_COUNT_PCLK3_DIV64 ((uint16_t)0x0060) ///< PCLK3/64
  126. #define WDT_COUNT_PCLK3_DIV128 ((uint16_t)0x0070) ///< PCLK3/128
  127. #define WDT_COUNT_PCLK3_DIV256 ((uint16_t)0x0080) ///< PCLK3/256
  128. #define WDT_COUNT_PCLK3_DIV512 ((uint16_t)0x0090) ///< PCLK3/512
  129. #define WDT_COUNT_PCLK3_DIV1024 ((uint16_t)0x00A0) ///< PCLK3/1024
  130. #define WDT_COUNT_PCLK3_DIV2048 ((uint16_t)0x00B0) ///< PCLK3/2048
  131. #define WDT_COUNT_PCLK3_DIV8192 ((uint16_t)0x00D0) ///< PCLK3/8192
  132. /**
  133. *******************************************************************************
  134. ** \brief WDT allow refresh percent range
  135. ******************************************************************************/
  136. #define WDT_100PCT ((uint16_t)0x0000) ///< 100%
  137. #define WDT_0To25PCT ((uint16_t)0x0100) ///< 0%~25%
  138. #define WDT_25To50PCT ((uint16_t)0x0200) ///< 25%~50%
  139. #define WDT_0To50PCT ((uint16_t)0x0300) ///< 0%~50%
  140. #define WDT_50To75PCT ((uint16_t)0x0400) ///< 50%~75%
  141. #define WDT_0To25PCT_50To75PCT ((uint16_t)0x0500) ///< 0%~25% & 50%~75%
  142. #define WDT_25To75PCT ((uint16_t)0x0600) ///< 25%~75%
  143. #define WDT_0To75PCT ((uint16_t)0x0700) ///< 0%~75%
  144. #define WDT_75To100PCT ((uint16_t)0x0800) ///< 75%~100%
  145. #define WDT_0To25PCT_75To100PCT ((uint16_t)0x0900) ///< 0%~25% & 75%~100%
  146. #define WDT_25To50PCT_75To100PCT ((uint16_t)0x0A00) ///< 25%~50% & 75%~100%
  147. #define WDT_0To50PCT_75To100PCT ((uint16_t)0x0B00) ///< 0%~50% & 75%~100%
  148. #define WDT_50To100PCT ((uint16_t)0x0C00) ///< 50%~100%
  149. #define WDT_0To25PCT_50To100PCT ((uint16_t)0x0D00) ///< 0%~25% & 50%~100%
  150. #define WDT_25To100PCT ((uint16_t)0x0E00) ///< 25%~100%
  151. #define WDT_0To100PCT ((uint16_t)0x0F00) ///< 0%~100%
  152. /**
  153. *******************************************************************************
  154. ** \brief WDT count control in the sleep mode
  155. ******************************************************************************/
  156. #define WDT_SPECIAL_MODE_COUNT_CONTINUE ((uint16_t)0x0000) ///< WDT count continue in the sleep mode
  157. #define WDT_SPECIAL_MODE_COUNT_STOP ((uint16_t)0x1000) ///< WDT count stop in the sleep mode
  158. /**
  159. *******************************************************************************
  160. ** \brief HRC frequency select
  161. ******************************************************************************/
  162. #define HRC_FREQUENCY_20MHZ ((uint16_t)0x0000) ///< HRC frequency 20MHZ
  163. #define HRC_FREQUENCY_16MHZ ((uint16_t)0x0001) ///< HRC frequency 16MHZ
  164. /**
  165. *******************************************************************************
  166. ** \brief HRC oscillation state control
  167. ******************************************************************************/
  168. #define HRC_OSCILLATION_START ((uint16_t)0x0000) ///< HRC oscillation start
  169. #define HRC_OSCILLATION_STOP ((uint16_t)0x0100) ///< HRC oscillation stop
  170. /**
  171. *******************************************************************************
  172. ** \brief VDU0 threshold voltage select
  173. ******************************************************************************/
  174. #define VDU0_VOLTAGE_THRESHOLD_1P5 ((uint8_t)0x00) ///< VDU0 voltage threshold 1.9V
  175. #define VDU0_VOLTAGE_THRESHOLD_2P0 ((uint8_t)0x01) ///< VDU0 voltage threshold 2.0V
  176. #define VDU0_VOLTAGE_THRESHOLD_2P1 ((uint8_t)0x02) ///< VDU0 voltage threshold 2.1V
  177. #define VDU0_VOLTAGE_THRESHOLD_2P3 ((uint8_t)0x03) ///< VDU0 voltage threshold 2.3V
  178. /**
  179. *******************************************************************************
  180. ** \brief VDU0 running state after reset
  181. ******************************************************************************/
  182. #define VDU0_START_AFTER_RESET ((uint8_t)0x00) ///< VDU0 start after reset
  183. #define VDU0_STOP_AFTER_RESET ((uint8_t)0x04) ///< VDU0 stop after reset
  184. /**
  185. *******************************************************************************
  186. ** \brief NMI pin filter sample clock division
  187. ******************************************************************************/
  188. #define NMI_PIN_FILTER_PCLK3_DIV1 ((uint8_t)0x00) ///< PCLK3
  189. #define NMI_PIN_FILTER_PCLK3_DIV8 ((uint8_t)0x04) ///< PCLK3/8
  190. #define NMI_PIN_FILTER_PCLK3_DIV32 ((uint8_t)0x08) ///< PCLK3/32
  191. #define NMI_PIN_FILTER_PCLK3_DIV64 ((uint8_t)0x0C) ///< PCLK3/64
  192. /**
  193. *******************************************************************************
  194. ** \brief NMI pin trigger edge type
  195. ******************************************************************************/
  196. #define NMI_PIN_TRIGGER_EDGE_FALLING ((uint8_t)0x00) ///< Falling edge trigger
  197. #define NMI_PIN_TRIGGER_EDGE_RISING ((uint8_t)0x10) ///< Rising edge trigger
  198. /**
  199. *******************************************************************************
  200. ** \brief Enable or disable NMI pin interrupt request
  201. ******************************************************************************/
  202. #define NMI_PIN_IRQ_DISABLE ((uint8_t)0x00) ///< Disable NMI pin interrupt request
  203. #define NMI_PIN_IRQ_ENABLE ((uint8_t)0x20) ///< Enable NMI pin interrupt request
  204. /**
  205. *******************************************************************************
  206. ** \brief Enable or disable NMI digital filter function
  207. ******************************************************************************/
  208. #define NMI_DIGITAL_FILTER_DISABLE ((uint8_t)0x00) ///< Disable NMI digital filter
  209. #define NMI_DIGITAL_FILTER_ENABLE ((uint8_t)0x40) ///< Enable NMI digital filter
  210. /**
  211. *******************************************************************************
  212. ** \brief Enable or disable NMI pin ICG function
  213. ******************************************************************************/
  214. #define NMI_PIN_ICG_FUNCTION_DISABLE ((uint8_t)0x80) ///< Disable NMI pin ICG function
  215. #define NMI_PIN_ICG_FUNCTION_ENABLE ((uint8_t)0x00) ///< Enable NMI pin ICG function
  216. /**
  217. *******************************************************************************
  218. ** \brief ICG start configure function on/off
  219. ******************************************************************************/
  220. #ifndef ICG_FUNCTION_ON
  221. #define ICG_FUNCTION_ON (1u)
  222. #endif
  223. #ifndef ICG_FUNCTION_OFF
  224. #define ICG_FUNCTION_OFF (0u)
  225. #endif
  226. /**
  227. *******************************************************************************
  228. ** \brief SWDT hardware start configuration
  229. ******************************************************************************/
  230. /*!< Enable or disable SWDT hardware start */
  231. #define ICG0_SWDT_HARDWARE_START (ICG_FUNCTION_OFF)
  232. /*!< SWDT register config */
  233. #define ICG0_SWDT_AUTS (SWDT_STOP_AFTER_RESET)
  234. #define ICG0_SWDT_ITS (SWDT_RESET_REQUEST)
  235. #define ICG0_SWDT_PERI (SWDT_COUNT_UNDERFLOW_CYCLE_16384)
  236. #define ICG0_SWDT_CKS (SWDT_COUNT_SWDTCLK_DIV2048)
  237. #define ICG0_SWDT_WDPT (SWDT_0To100PCT)
  238. #define ICG0_SWDT_SLTPOFF (SWDT_SPECIAL_MODE_COUNT_STOP)
  239. /*!< SWDT register config value */
  240. #if ICG0_SWDT_HARDWARE_START == ICG_FUNCTION_ON
  241. #define ICG0_SWDT_REG_CONFIG (ICG0_SWDT_AUTS | ICG0_SWDT_ITS | ICG0_SWDT_PERI | \
  242. ICG0_SWDT_CKS | ICG0_SWDT_WDPT | ICG0_SWDT_SLTPOFF)
  243. #else
  244. #define ICG0_SWDT_REG_CONFIG ((uint16_t)0xFFFF)
  245. #endif
  246. /**
  247. *******************************************************************************
  248. ** \brief WDT hardware start configuration
  249. ******************************************************************************/
  250. /*!< Enable or disable WDT hardware start */
  251. #define ICG0_WDT_HARDWARE_START (ICG_FUNCTION_OFF)
  252. /*!< WDT register config */
  253. #define ICG0_WDT_AUTS (WDT_STOP_AFTER_RESET)
  254. #define ICG0_WDT_ITS (WDT_RESET_REQUEST)
  255. #define ICG0_WDT_PERI (WDT_COUNT_UNDERFLOW_CYCLE_16384)
  256. #define ICG0_WDT_CKS (WDT_COUNT_PCLK3_DIV8192)
  257. #define ICG0_WDT_WDPT (WDT_0To100PCT)
  258. #define ICG0_WDT_SLPOFF (WDT_SPECIAL_MODE_COUNT_STOP)
  259. /*!< WDT register config value */
  260. #if ICG0_WDT_HARDWARE_START == ICG_FUNCTION_ON
  261. #define ICG0_WDT_REG_CONFIG (ICG0_WDT_AUTS | ICG0_WDT_ITS | ICG0_WDT_PERI | \
  262. ICG0_WDT_CKS | ICG0_WDT_WDPT | ICG0_WDT_SLPOFF)
  263. #else
  264. #define ICG0_WDT_REG_CONFIG ((uint16_t)0xFFFF)
  265. #endif
  266. /**
  267. *******************************************************************************
  268. ** \brief HRC hardware start configuration
  269. ******************************************************************************/
  270. /*!< Enable or disable HRC hardware start */
  271. #define ICG1_HRC_HARDWARE_START (ICG_FUNCTION_ON)
  272. /*!< HRC register config */
  273. #define ICG1_HRC_FREQSEL (HRC_FREQUENCY_16MHZ)
  274. #define ICG1_HRC_STOP (HRC_OSCILLATION_START)
  275. /*!< HRC register config value */
  276. #if ICG1_HRC_HARDWARE_START == ICG_FUNCTION_ON
  277. #define ICG1_HRC_REG_CONFIG (ICG1_HRC_FREQSEL | ICG1_HRC_STOP)
  278. #else
  279. #define ICG1_HRC_REG_CONFIG ((uint16_t)0xFFFF)
  280. #endif
  281. /**
  282. *******************************************************************************
  283. ** \brief VDU0 hardware start configuration
  284. ******************************************************************************/
  285. /*!< Enable or disable VDU0 hardware start */
  286. #define ICG1_VDU0_HARDWARE_START (ICG_FUNCTION_OFF)
  287. /*!< VDU0 register config */
  288. #define ICG1_VDU0_BOR_LEV (VDU0_VOLTAGE_THRESHOLD_2P3)
  289. #define ICG1_VDU0_BORDIS (VDU0_STOP_AFTER_RESET)
  290. /*!< VDU0 register config value */
  291. #if ICG1_VDU0_HARDWARE_START == ICG_FUNCTION_ON
  292. #define ICG1_VDU0_REG_CONFIG (ICG1_VDU0_BOR_LEV | ICG1_VDU0_BORDIS)
  293. #else
  294. #define ICG1_VDU0_REG_CONFIG ((uint8_t)0xFF)
  295. #endif
  296. /**
  297. *******************************************************************************
  298. ** \brief NMI hardware start configuration
  299. ******************************************************************************/
  300. /*!< Enable or disable NMI hardware start */
  301. #define ICG1_NMI_HARDWARE_START (ICG_FUNCTION_OFF)
  302. /*!< NMI register config */
  303. #define ICG1_NMI_SMPCLK (NMI_PIN_FILTER_PCLK3_DIV1)
  304. #define ICG1_NMI_TRG (NMI_PIN_TRIGGER_EDGE_RISING)
  305. #define ICG1_NMI_IMR (NMI_PIN_IRQ_DISABLE)
  306. #define ICG1_NMI_NFEN (NMI_DIGITAL_FILTER_DISABLE)
  307. #define ICG1_NMI_ICGENA (NMI_PIN_ICG_FUNCTION_DISABLE)
  308. /*!< NMI register config value */
  309. #if ICG1_NMI_HARDWARE_START == ICG_FUNCTION_ON
  310. #define ICG1_NMI_REG_CONFIG (ICG1_NMI_SMPCLK | ICG1_NMI_TRG | \
  311. ICG1_NMI_IMR | ICG1_NMI_NFEN | ICG1_NMI_ICGENA)
  312. #else
  313. #define ICG1_NMI_REG_CONFIG ((uint8_t)0xFF)
  314. #endif
  315. /**
  316. *******************************************************************************
  317. ** \brief ICG registers configuration
  318. ******************************************************************************/
  319. /*!< ICG0 register value */
  320. #define ICG0_REGISTER_CONSTANT (((uint32_t)ICG0_WDT_REG_CONFIG << 16) | \
  321. ((uint32_t)ICG0_SWDT_REG_CONFIG) | \
  322. ((uint32_t)0xE000E000ul))
  323. /*!< ICG1 register value */
  324. #define ICG1_REGISTER_CONSTANT (((uint32_t)ICG1_NMI_REG_CONFIG << 24) | \
  325. ((uint32_t)ICG1_VDU0_REG_CONFIG << 16) | \
  326. ((uint32_t)ICG1_HRC_REG_CONFIG) | \
  327. ((uint32_t)0x03F8FEFEul))
  328. /*!< ICG2~7 register reserved value */
  329. #define ICG2_REGISTER_CONSTANT ((uint32_t)0xFFFFFFFFul)
  330. #define ICG3_REGISTER_CONSTANT ((uint32_t)0xFFFFFFFFul)
  331. #define ICG4_REGISTER_CONSTANT ((uint32_t)0xFFFFFFFFul)
  332. #define ICG5_REGISTER_CONSTANT ((uint32_t)0xFFFFFFFFul)
  333. #define ICG6_REGISTER_CONSTANT ((uint32_t)0xFFFFFFFFul)
  334. #define ICG7_REGISTER_CONSTANT ((uint32_t)0xFFFFFFFFul)
  335. /*******************************************************************************
  336. * Global variable definitions ('extern')
  337. ******************************************************************************/
  338. /*******************************************************************************
  339. Global function prototypes (definition in C source)
  340. ******************************************************************************/
  341. //@} // IcgGroup
  342. #ifdef __cplusplus
  343. }
  344. #endif
  345. #endif /* DDL_ICG_ENABLE */
  346. #endif /* __HC32F460_ICG_H__ */
  347. /*******************************************************************************
  348. * EOF (not truncated)
  349. ******************************************************************************/