hc32_ll_pwc.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_pwc.h
  4. * @brief This file contains all the functions prototypes of the PWC 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_PWC_H__
  22. #define __HC32_LL_PWC_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_PWC
  40. * @{
  41. */
  42. #if (LL_PWC_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup PWC_Global_Types PWC Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief PWC LVD Init
  52. */
  53. typedef struct {
  54. uint32_t u32State; /*!< LVD function setting, @ref PWC_LVD_Config for details */
  55. uint32_t u32CompareOutputState; /*!< LVD compare output function setting, @ref PWC_LVD_CMP_Config for details */
  56. uint32_t u32ExceptionType; /*!< LVD interrupt or reset selection, @ref PWC_LVD_Exception_Type_Sel for details */
  57. uint32_t u32Filter; /*!< LVD digital filter function setting, @ref PWC_LVD_DF_Config for details */
  58. uint32_t u32FilterClock; /*!< LVD digital filter clock setting, @ref PWC_LVD_DFS_Clk_Sel for details */
  59. uint32_t u32ThresholdVoltage; /*!< LVD detect voltage setting, @ref PWC_LVD_Detection_Voltage_Sel for details */
  60. uint32_t u32TriggerEdge; /*!< LVD trigger setting, @ref PWC_LVD_TRIG_Sel for details */
  61. } stc_pwc_lvd_init_t;
  62. /**
  63. * @brief PWC power down mode innit
  64. */
  65. typedef struct {
  66. uint8_t u8Mode; /*!< Power down mode, @ref PWC_PDMode_Sel for details. */
  67. uint8_t u8IOState; /*!< IO state in power down mode, @ref PWC_PDMode_IO_Sel for details. */
  68. uint8_t u8VcapCtrl; /*!< Power down Wakeup time control, @ref PWC_PD_VCAP_Sel for details. */
  69. } stc_pwc_pd_mode_config_t;
  70. /**
  71. * @brief PWC Stop mode Init
  72. */
  73. typedef struct {
  74. uint16_t u16Clock; /*!< System clock setting after wake-up from stop mode,
  75. @ref PWC_STOP_CLK_Sel for details. */
  76. uint8_t u8StopDrv; /*!< Stop mode drive capacity,
  77. @ref PWC_STOP_DRV_Sel for details. */
  78. uint16_t u16ExBusHold; /*!< Expos status in stop mode,
  79. @ref PWC_STOP_EXBUS_Sel for details. */
  80. uint16_t u16FlashWait; /*!< Waiting flash stable after wake-up from stop mode,
  81. @ref PWC_STOP_Flash_Wait_Sel for details. */
  82. } stc_pwc_stop_mode_config_t;
  83. /**
  84. * @}
  85. */
  86. /*******************************************************************************
  87. * Global pre-processor symbols/macros ('#define')
  88. ******************************************************************************/
  89. /**
  90. * @defgroup PWC_Global_Macros PWC Global Macros
  91. * @{
  92. */
  93. /**
  94. * @defgroup PWC_PDMode_Sel Power down mode selection
  95. * @{
  96. */
  97. #define PWC_PD_MD1 (0x00U) /*!< Power down mode 1 */
  98. #define PWC_PD_MD2 (0x01U) /*!< Power down mode 2 */
  99. #define PWC_PD_MD3 (0x02U) /*!< Power down mode 3 */
  100. #define PWC_PD_MD4 (0x03U) /*!< Power down mode 4 */
  101. /**
  102. * @}
  103. */
  104. /**
  105. * @defgroup PWC_PDMode_IO_Sel IO state config in Power down mode
  106. * @{
  107. */
  108. #define PWC_PD_IO_KEEP1 (0x00U) /*!< IO state retain in PD mode and configurable after wakeup */
  109. #define PWC_PD_IO_KEEP2 (PWC_PWRC0_IORTN_0) /*!< IO state retain in PD mode and configurable after wakeup & set IORTN[1:0]=00b */
  110. #define PWC_PD_IO_HIZ (PWC_PWRC0_IORTN_1) /*!< IO state switch to HiZ */
  111. /**
  112. * @}
  113. */
  114. /**
  115. * @defgroup PWC_PD_VCAP_Sel Wakeup speed config in Power down mode
  116. * @{
  117. */
  118. #define PWC_PD_VCAP_0P1UF (0x00U) /*!< VCAP1/VCAP2 = 0.1uF x2 or 0.22uF x1 */
  119. #define PWC_PD_VCAP_0P047UF (0x01U) /*!< VCAP1/VCAP2 = 0.047uF x2 or 0.1uF x1 */
  120. /**
  121. * @}
  122. */
  123. /**
  124. * @defgroup PWC_STOP_DRV_Sel Drive capacity while enter stop mode
  125. * @{
  126. */
  127. #define PWC_STOP_DRV_HIGH (0x00U) /*!< Enter stop mode from high speed mode */
  128. #define PWC_STOP_DRV_LOW (PWC_PWRC1_STPDAS) /*!< Enter stop mode from ultra low speed mode */
  129. /**
  130. * @}
  131. */
  132. /**
  133. * @defgroup PWC_STOP_EXBUS_Sel ExBus status while enter stop mode
  134. * @{
  135. */
  136. #define PWC_STOP_EXBUS_HIZ (0x00U) /*!< Ex-Bus Hiz in stop mode */
  137. #define PWC_STOP_EXBUS_HOLD (PWC_STPMCR_EXBUSOE) /*!< Ex-Bus keep in stop mode */
  138. /**
  139. * @}
  140. */
  141. /**
  142. * @defgroup PWC_STOP_CLK_Sel System clock setting after wake-up from stop mode
  143. * @{
  144. */
  145. #define PWC_STOP_CLK_KEEP (0x00U) /*!< Keep System clock setting after wake-up from stop mode */
  146. #define PWC_STOP_CLK_MRC (PWC_STPMCR_CKSMRC) /*!< System clock switch to MRC after wake-up from stop mode */
  147. /**
  148. * @}
  149. */
  150. /**
  151. * @defgroup PWC_STOP_Flash_Wait_Sel Whether wait flash stable or not after wake-up from stop mode
  152. * @{
  153. */
  154. #define PWC_STOP_FLASH_WAIT_ON (0x00U) /*!< Wait flash stable after wake-up from stop mode */
  155. #define PWC_STOP_FLASH_WAIT_OFF (PWC_STPMCR_FLNWT) /*!< Don't wait flash stable after wake-up from stop mode */
  156. /**
  157. * @}
  158. */
  159. /**
  160. * @defgroup PWC_Stop_Type PWC stop mode type.
  161. * @{
  162. */
  163. #define PWC_STOP_WFI (0x00U)
  164. #define PWC_STOP_WFE (0x01U)
  165. /**
  166. * @}
  167. */
  168. /**
  169. * @defgroup PWC_RAM_Config Operating mode for RAM Config
  170. * @{
  171. */
  172. #define PWC_RAM_HIGH_SPEED (0x8043U) /*!< MCU operating under high frequency (lower than 240MHz) */
  173. #define PWC_RAM_ULOW_SPEED (0x9062U) /*!< MCU operating under ultra low frequency (lower than 8MHz) */
  174. /**
  175. * @}
  176. */
  177. /**
  178. * @defgroup PWC_PD_Periph_Ram Peripheral ram to power down
  179. * @{
  180. */
  181. #define PWC_RAM_PD_CAN1 (PWC_PRAMLPC_PRAMPDC0)
  182. #define PWC_RAM_PD_CACHE (PWC_PRAMLPC_PRAMPDC3)
  183. #define PWC_RAM_PD_ALL (0x09U)
  184. /**
  185. * @}
  186. */
  187. /**
  188. * @defgroup PWC_PD_Ram Peripheral ram to power down
  189. * @{
  190. */
  191. #define PWC_RAM_PD_SRAM0 (PWC_RAMPC0_RAMPDC0) /*!< 0x20000000 ~ 0x20007FFF */
  192. #define PWC_RAM_PD_SRAMH (PWC_RAMPC0_RAMPDC10) /*!< 0x1FFF8000 ~ 0x1FFFFFFF */
  193. /**
  194. * @}
  195. */
  196. /**
  197. * @defgroup PWC_LVD_Channel PWC LVD channel
  198. * @{
  199. */
  200. #define PWC_LVD_CH1 (0x00U)
  201. #define PWC_LVD_CH2 (0x01U)
  202. /**
  203. * @}
  204. */
  205. /**
  206. * @defgroup PWC_LVD_Config PWC LVD Config
  207. * @{
  208. */
  209. #define PWC_LVD_ON (PWC_PVDCR0_PVD1EN)
  210. #define PWC_LVD_OFF (0x00U)
  211. /**
  212. * @}
  213. */
  214. /**
  215. * @defgroup PWC_LVD_Exception_Type_Sel PWC LVD Exception Type Select
  216. * @{
  217. */
  218. #define PWC_LVD_EXP_TYPE_NONE (0x00U)
  219. #define PWC_LVD_EXP_TYPE_INT (0x0101U)
  220. #define PWC_LVD_EXP_TYPE_NMI (0x0001U)
  221. #define PWC_LVD_EXP_TYPE_RST (PWC_PVDCR1_PVD1IRE | PWC_PVDCR1_PVD1IRS)
  222. /**
  223. * @}
  224. */
  225. /**
  226. * @defgroup PWC_LVD_CMP_Config PWC LVD Compare Config
  227. * @{
  228. */
  229. #define PWC_LVD_CMP_OFF (0x00U)
  230. #define PWC_LVD_CMP_ON (PWC_PVDCR1_PVD1CMPOE)
  231. /**
  232. * @}
  233. */
  234. /**
  235. * @defgroup PWC_LVD_DF_Config LVD digital filter ON or OFF
  236. * @{
  237. */
  238. #define PWC_LVD_FILTER_ON (0x00U)
  239. #define PWC_LVD_FILTER_OFF (0x01U)
  240. /**
  241. * @}
  242. */
  243. /**
  244. * @defgroup PWC_LVD_DFS_Clk_Sel LVD digital filter sample ability
  245. * @note modified this value must when PWC_LVD_FILTER_OFF
  246. * @{
  247. */
  248. #define PWC_LVD_FILTER_LRC_DIV4 (0x00UL << PWC_PVDFCR_PVD1NFCKS_POS) /*!< 0.25 LRC cycle */
  249. #define PWC_LVD_FILTER_LRC_DIV2 (0x01UL << PWC_PVDFCR_PVD1NFCKS_POS) /*!< 0.5 LRC cycle */
  250. #define PWC_LVD_FILTER_LRC_DIV1 (0x02UL << PWC_PVDFCR_PVD1NFCKS_POS) /*!< 1 LRC cycle */
  251. #define PWC_LVD_FILTER_LRC_MUL2 (0x03UL << PWC_PVDFCR_PVD1NFCKS_POS) /*!< 2 LRC cycles */
  252. /**
  253. * @}
  254. */
  255. /**
  256. * @defgroup PWC_LVD_Detection_Voltage_Sel PWC LVD Detection voltage
  257. * @{
  258. * @note
  259. @verbatim
  260. * | |
  261. * | LVD1 | LVD2 |
  262. * LVL0 | 2.1V | 2.0V |
  263. * LVL1 | 2.3V | 2.1V |
  264. * LVL2 | 2.5V | 2.3V |
  265. * LVL3 | 2.6V | 2.5V |
  266. * LVL4 | 2.7V | 2.6V |
  267. * LVL5 | 2.8V | 2.7V |
  268. * LVL6 | 2.9V | 2.8V |
  269. * LVL7 | --- | 2.9V |
  270. * EXVCC | EXVCC | --- |
  271. @endverbatim
  272. */
  273. #define PWC_LVD_THRESHOLD_LVL0 (0x00U)
  274. #define PWC_LVD_THRESHOLD_LVL1 (0x01U)
  275. #define PWC_LVD_THRESHOLD_LVL2 (0x02U)
  276. #define PWC_LVD_THRESHOLD_LVL3 (0x03U)
  277. #define PWC_LVD_THRESHOLD_LVL4 (0x04U)
  278. #define PWC_LVD_THRESHOLD_LVL5 (0x05U)
  279. #define PWC_LVD_THRESHOLD_LVL6 (0x06U)
  280. #define PWC_LVD_THRESHOLD_LVL7 (0x07U)
  281. #define PWC_LVD_EXTVCC (0x07U)
  282. /**
  283. * @}
  284. */
  285. /**
  286. * @defgroup PWC_LVD_TRIG_Sel LVD trigger setting
  287. * @{
  288. */
  289. #define PWC_LVD_TRIG_FALLING (0x00UL << PWC_PVDICR_PVD1EDGS_POS)
  290. #define PWC_LVD_TRIG_RISING (0x01UL << PWC_PVDICR_PVD1EDGS_POS)
  291. #define PWC_LVD_TRIG_BOTH (0x02UL << PWC_PVDICR_PVD1EDGS_POS)
  292. /**
  293. * @}
  294. */
  295. /**
  296. * @defgroup PWC_LVD_Flag LVD flag
  297. * @{
  298. */
  299. #define PWC_LVD1_FLAG_DETECT (PWC_PVDDSR_PVD1DETFLG) /*!< VCC across VLVD1 */
  300. #define PWC_LVD2_FLAG_DETECT (PWC_PVDDSR_PVD2DETFLG) /*!< VCC across VLVD2 */
  301. #define PWC_LVD1_FLAG_MON (PWC_PVDDSR_PVD1MON) /*!< VCC > VLVD1 */
  302. #define PWC_LVD2_FLAG_MON (PWC_PVDDSR_PVD2MON) /*!< VCC > VLVD2 */
  303. /**
  304. * @}
  305. */
  306. /**
  307. * @defgroup PWC_WKUP_Event_Sel Power down mode wakeup event selection
  308. * @{
  309. */
  310. #define PWC_PD_WKUP0_POS (0U)
  311. #define PWC_PD_WKUP1_POS (8U)
  312. #define PWC_PD_WKUP2_POS (16U)
  313. #define PWC_PD_WKUP_WKUP00 (PWC_PDWKE0_WKE00 << PWC_PD_WKUP0_POS)
  314. #define PWC_PD_WKUP_WKUP01 (PWC_PDWKE0_WKE01 << PWC_PD_WKUP0_POS)
  315. #define PWC_PD_WKUP_WKUP02 (PWC_PDWKE0_WKE02 << PWC_PD_WKUP0_POS)
  316. #define PWC_PD_WKUP_WKUP03 (PWC_PDWKE0_WKE03 << PWC_PD_WKUP0_POS)
  317. #define PWC_PD_WKUP_WKUP10 (PWC_PDWKE0_WKE10 << PWC_PD_WKUP0_POS)
  318. #define PWC_PD_WKUP_WKUP11 (PWC_PDWKE0_WKE11 << PWC_PD_WKUP0_POS)
  319. #define PWC_PD_WKUP_WKUP12 (PWC_PDWKE0_WKE12 << PWC_PD_WKUP0_POS)
  320. #define PWC_PD_WKUP_WKUP13 (PWC_PDWKE0_WKE13 << PWC_PD_WKUP0_POS)
  321. #define PWC_PD_WKUP_WKUP20 (PWC_PDWKE1_WKE20 << PWC_PD_WKUP1_POS)
  322. #define PWC_PD_WKUP_WKUP21 (PWC_PDWKE1_WKE21 << PWC_PD_WKUP1_POS)
  323. #define PWC_PD_WKUP_WKUP22 (PWC_PDWKE1_WKE22 << PWC_PD_WKUP1_POS)
  324. #define PWC_PD_WKUP_WKUP23 (PWC_PDWKE1_WKE23 << PWC_PD_WKUP1_POS)
  325. #define PWC_PD_WKUP_WKUP30 (PWC_PDWKE1_WKE30 << PWC_PD_WKUP1_POS)
  326. #define PWC_PD_WKUP_WKUP31 (PWC_PDWKE1_WKE31 << PWC_PD_WKUP1_POS)
  327. #define PWC_PD_WKUP_WKUP32 (PWC_PDWKE1_WKE32 << PWC_PD_WKUP1_POS)
  328. #define PWC_PD_WKUP_WKUP33 (PWC_PDWKE1_WKE33 << PWC_PD_WKUP1_POS)
  329. #define PWC_PD_WKUP_LVD1 (PWC_PDWKE2_VD1WKE << PWC_PD_WKUP2_POS)
  330. #define PWC_PD_WKUP_LVD2 (PWC_PDWKE2_VD2WKE << PWC_PD_WKUP2_POS)
  331. #define PWC_PD_WKUP_RTCPRD (PWC_PDWKE2_RTCPRDWKE << PWC_PD_WKUP2_POS)
  332. #define PWC_PD_WKUP_RTCALM (PWC_PDWKE2_RTCALMWKE << PWC_PD_WKUP2_POS)
  333. #define PWC_PD_WKUP_WKTM (PWC_PDWKE2_WKTMWKE << PWC_PD_WKUP2_POS)
  334. /**
  335. * @}
  336. */
  337. /**
  338. * @defgroup PWC_WKUP_Trigger_Event_Sel Power down mode wakeup event selection to set trigger edge.
  339. * @{
  340. */
  341. #define PWC_PD_WKUP_TRIG_LVD1 (PWC_PDWKES_VD1EGS)
  342. #define PWC_PD_WKUP_TRIG_LVD2 (PWC_PDWKES_VD2EGS)
  343. #define PWC_PD_WKUP_TRIG_WKUP0 (PWC_PDWKES_WK0EGS)
  344. #define PWC_PD_WKUP_TRIG_WKUP1 (PWC_PDWKES_WK1EGS)
  345. #define PWC_PD_WKUP_TRIG_WKUP2 (PWC_PDWKES_WK2EGS)
  346. #define PWC_PD_WKUP_TRIG_WKUP3 (PWC_PDWKES_WK3EGS)
  347. #define PWC_PD_WKUP_TRIG_ALL (PWC_PD_WKUP_TRIG_LVD1 | PWC_PD_WKUP_TRIG_LVD2 | PWC_PD_WKUP_TRIG_WKUP0 | \
  348. PWC_PD_WKUP_TRIG_WKUP1 | PWC_PD_WKUP_TRIG_WKUP2 | PWC_PD_WKUP_TRIG_WKUP3)
  349. /**
  350. * @}
  351. */
  352. /**
  353. * @defgroup PWC_WKUP_Trigger_Edge_Sel Power down mode wakeup trigger edge selection
  354. * @{
  355. */
  356. #define PWC_PD_WKUP_TRIG_FALLING (0x00U)
  357. #define PWC_PD_WKUP_TRIG_RISING (0x01U)
  358. /**
  359. * @}
  360. */
  361. /**
  362. * @defgroup PWC_WKUP_Event_Flag_Sel Power down mode wakeup Event status selection
  363. * @{
  364. */
  365. #define PWC_PD_WKUP_FLAG0_POS (0U)
  366. #define PWC_PD_WKUP_FLAG1_POS (8U)
  367. #define PWC_PD_WKUP_FLAG_WKUP0 (PWC_PDWKF0_PTWK0F << PWC_PD_WKUP_FLAG0_POS)
  368. #define PWC_PD_WKUP_FLAG_WKUP1 (PWC_PDWKF0_PTWK1F << PWC_PD_WKUP_FLAG0_POS)
  369. #define PWC_PD_WKUP_FLAG_WKUP2 (PWC_PDWKF0_PTWK2F << PWC_PD_WKUP_FLAG0_POS)
  370. #define PWC_PD_WKUP_FLAG_WKUP3 (PWC_PDWKF0_PTWK3F << PWC_PD_WKUP_FLAG0_POS)
  371. #define PWC_PD_WKUP_FLAG_LVD1 (PWC_PDWKF0_VD1WKF << PWC_PD_WKUP_FLAG0_POS)
  372. #define PWC_PD_WKUP_FLAG_LVD2 (PWC_PDWKF0_VD2WKF << PWC_PD_WKUP_FLAG0_POS)
  373. #define PWC_PD_WKUP_FLAG_RTCPRD (PWC_PDWKF1_RTCPRDWKF << PWC_PD_WKUP_FLAG1_POS)
  374. #define PWC_PD_WKUP_FLAG_RTCALM (PWC_PDWKF1_RTCALMWKF << PWC_PD_WKUP_FLAG1_POS)
  375. #define PWC_PD_WKUP_FLAG_WKTM (PWC_PDWKF1_WKTMWKF << PWC_PD_WKUP_FLAG1_POS)
  376. #define PWC_PD_WKUP_FLAG_ALL (PWC_PD_WKUP_FLAG_WKUP0 | PWC_PD_WKUP_FLAG_WKUP1 | PWC_PD_WKUP_FLAG_WKUP2 | \
  377. PWC_PD_WKUP_FLAG_WKUP3 | PWC_PD_WKUP_FLAG_LVD1 | PWC_PD_WKUP_FLAG_LVD2 | \
  378. PWC_PD_WKUP_FLAG_RTCPRD | PWC_PD_WKUP_FLAG_RTCALM | PWC_PD_WKUP_FLAG_WKTM)
  379. /**
  380. * @}
  381. */
  382. /**
  383. * @defgroup PWC_Monitor_Power PWC Power Monitor voltage definition
  384. * @{
  385. */
  386. #define PWC_PWR_MON_IREF (0x00U) /*!< Internal reference voltage */
  387. /**
  388. * @}
  389. */
  390. /**
  391. * @defgroup PWC_WKT_State PWC WKT State
  392. * @{
  393. */
  394. #define PWC_WKT_OFF (0x00U)
  395. #define PWC_WKT_ON (PWC_WKTCR_WKTCE)
  396. /**
  397. * @}
  398. */
  399. /**
  400. * @defgroup PWC_WKT_Clock_Source PWC WKT Clock Source
  401. * @{
  402. */
  403. #define PWC_WKT_CLK_SRC_64HZ ((0x00U << PWC_WKTCR_WKCKS_POS)) /*!< 64Hz Clock */
  404. #define PWC_WKT_CLK_SRC_XTAL32 ((0x01U << PWC_WKTCR_WKCKS_POS)) /*!< XTAL32 Clock */
  405. #define PWC_WKT_CLK_SRC_LRC ((0x02U << PWC_WKTCR_WKCKS_POS)) /*!< LRC Clock */
  406. /**
  407. * @}
  408. */
  409. /**
  410. * @defgroup PWC_Ldo_Sel PWC LDO Selection
  411. * @{
  412. */
  413. #define PWC_LDO_HRC (PWC_PWRC1_VHRCSD)
  414. #define PWC_LDO_PLL (PWC_PWRC1_VPLLSD)
  415. #define PWC_LDO_MASK (PWC_LDO_HRC | PWC_LDO_PLL)
  416. /**
  417. * @}
  418. */
  419. /**
  420. * @defgroup PWC_Rtc_Clock_Sel PWC RTC clock selection
  421. * @{
  422. */
  423. #define PWC_RTC_CLK_LRC (0x00U) /*!< Rtc clock selects LRC */
  424. #define PWC_RTC_CLK_XTAL_DIV (0x01U) /*!< Rtc clock selects XTAL div as 32.768KHz */
  425. /**
  426. * @}
  427. */
  428. /**
  429. * @defgroup PWC_Port_Reset_Sel PWC Port reset selection
  430. * @{
  431. */
  432. #define PWC_PORT_RST_WDT (PWC_PWRC6_WDRTNE)
  433. #define PWC_PORT_RST_SW (PWC_PWRC6_SWRTNE)
  434. #define PWC_PORT_RST_ALL (PWC_PORT_RST_WDT | PWC_PORT_RST_SW)
  435. /**
  436. * @}
  437. */
  438. /**
  439. * @defgroup PWC_Port_Reset_flag PWC Port reset event flag
  440. * @{
  441. */
  442. #define PWC_FLAG_PORT_RST_WDT (PWC_PWRC6_WDRIOCLR)
  443. #define PWC_FLAG_PORT_RST_SW (PWC_PWRC6_SWRIOCLR)
  444. #define PWC_FLAG_PORT_RST_ALL (PWC_FLAG_PORT_RST_WDT | PWC_FLAG_PORT_RST_SW)
  445. /**
  446. * @}
  447. */
  448. /**
  449. * @defgroup PWC_Dac_Reset_Sel PWC Port reset selection
  450. * @{
  451. */
  452. #define PWC_DAC_RST_WDT (PWC_PWRC6_WDRDAC)
  453. #define PWC_DAC_RST_SW (PWC_PWRC6_SWRDAC)
  454. #define PWC_DAC_RST_ALL (PWC_DAC_RST_WDT | PWC_DAC_RST_SW)
  455. /**
  456. * @}
  457. */
  458. /**
  459. * @defgroup PWC_REG_Write_Unlock_Code PWC register unlock code.
  460. * @brief Lock/unlock Code for each module
  461. * PWC_UNLOCK_CODE0:
  462. * Below registers are locked in CLK module.
  463. * XTALCFGR, XTALSTBCR, XTALCR, XTALSTDCR, XTALSTDSR, HRCTRM, HRCCR,
  464. * MRCTRM, MRCCR, PLLCFGR, PLLCR, UPLLCFGR, UPLLCR, OSCSTBSR, CKSWR,
  465. * SCFGR, USBCKCFGR, TPIUCKCFGR, MCO1CFGR, MCO2CFGR, XTAL32CR,
  466. * XTALC32CFGR, XTAL32NFR, LRCCR, LRCTRM.
  467. * PWC_UNLOCK_CODE1:
  468. * Below registers are locked in PWC module.
  469. * PWRC0, PWRC1, PWRC2, PWRC3, PDWKE0, PDWKE1, PDWKE2, PDWKES, PDWKF0,
  470. * PDWKF1, PWCMR, PWR_STPMCR, RAMPC0, RAMOPM.
  471. * Below registers are locked in CLK module.
  472. * PERICKSEL, I2SCKSEL,
  473. * Below register is locked in RMU module.
  474. * RSTF0
  475. * PWC_UNLOCK_CODE2:
  476. * Below registers are locked in PWC module.
  477. * PVDCR0, PVDCR1, PVDFCR, PVDLCR, PVDICR, PVDDSR
  478. * @{
  479. */
  480. #define PWC_WRITE_ENABLE (0xA500U)
  481. #define PWC_UNLOCK_CODE0 (0xA501U)
  482. #define PWC_UNLOCK_CODE1 (0xA502U)
  483. #define PWC_UNLOCK_CODE2 (0xA508U)
  484. /**
  485. * @brief PWC FCG0 Unlock/Lock code
  486. */
  487. #define PWC_FCG0_REG_UNLOCK_KEY (0xA5A50001UL)
  488. #define PWC_FCG0_REG_LOCK_KEY (0xA5A50000UL)
  489. /**
  490. * @}
  491. */
  492. /**
  493. * @}
  494. */
  495. /*******************************************************************************
  496. * Global variable definitions ('extern')
  497. ******************************************************************************/
  498. /*******************************************************************************
  499. Global function prototypes (definition in C source)
  500. ******************************************************************************/
  501. /**
  502. * @addtogroup PWC_Global_Functions
  503. * @{
  504. */
  505. /**
  506. * @brief Lock PWC, CLK, RMU register.
  507. * @param [in] u16Module Lock code for each module.
  508. * @arg PWC_UNLOCK_CODE0
  509. * @arg PWC_UNLOCK_CODE1
  510. * @arg PWC_UNLOCK_CODE2
  511. * @retval None
  512. */
  513. __STATIC_INLINE void PWC_REG_Lock(uint16_t u16Module)
  514. {
  515. CM_PWC->FPRC = (PWC_WRITE_ENABLE | (uint16_t)((uint16_t)(~u16Module) & (CM_PWC->FPRC)));
  516. }
  517. /**
  518. * @brief Unlock PWC, CLK, RMU register.
  519. * @param [in] u16Module Unlock code for each module.
  520. * @arg PWC_UNLOCK_CODE0
  521. * @arg PWC_UNLOCK_CODE1
  522. * @arg PWC_UNLOCK_CODE2
  523. * @retval None
  524. */
  525. __STATIC_INLINE void PWC_REG_Unlock(uint16_t u16Module)
  526. {
  527. SET_REG16_BIT(CM_PWC->FPRC, u16Module);
  528. }
  529. /**
  530. * @brief Lock PWC_FCG0 register .
  531. * @param None
  532. * @retval None
  533. */
  534. __STATIC_INLINE void PWC_FCG0_REG_Lock(void)
  535. {
  536. WRITE_REG32(CM_PWC->FCG0PC, PWC_FCG0_REG_LOCK_KEY);
  537. }
  538. /**
  539. * @brief Unlock PWR_FCG0 register.
  540. * @param None
  541. * @retval None
  542. * @note Call this function before FCG_Fcg0PeriphClockCmd()
  543. */
  544. __STATIC_INLINE void PWC_FCG0_REG_Unlock(void)
  545. {
  546. WRITE_REG32(CM_PWC->FCG0PC, PWC_FCG0_REG_UNLOCK_KEY);
  547. }
  548. /* PWC PD Function */
  549. void PWC_PD_Enter(void);
  550. int32_t PWC_PD_StructInit(stc_pwc_pd_mode_config_t *pstcPDModeConfig);
  551. int32_t PWC_PD_Config(const stc_pwc_pd_mode_config_t *pstcPDModeConfig);
  552. void PWC_PD_WakeupCmd(uint32_t u32Event, en_functional_state_t enNewState);
  553. void PWC_PD_SetWakeupTriggerEdge(uint8_t u8Event, uint8_t u8TrigEdge);
  554. en_flag_status_t PWC_PD_GetWakeupStatus(uint16_t u16Flag);
  555. void PWC_PD_ClearWakeupStatus(uint16_t u16Flag);
  556. void PWC_PD_PeriphRamCmd(uint32_t u32PeriphRam, en_functional_state_t enNewState);
  557. void PWC_PD_RamCmd(uint32_t u32Ram, en_functional_state_t enNewState);
  558. void PWC_PD_VdrCmd(en_functional_state_t enNewState);
  559. /* PWC WKTM Function */
  560. void PWC_WKT_Config(uint16_t u16ClkSrc, uint16_t u16CmpVal);
  561. void PWC_WKT_SetCompareValue(uint16_t u16CmpVal);
  562. uint16_t PWC_WKT_GetCompareValue(void);
  563. void PWC_WKT_Cmd(en_functional_state_t enNewState);
  564. en_flag_status_t PWC_WKT_GetStatus(void);
  565. void PWC_WKT_ClearStatus(void);
  566. void PWC_RamModeConfig(uint16_t u16Mode);
  567. /* PWC Sleep Function */
  568. void PWC_SLEEP_Enter(void);
  569. /* PWC Stop Function */
  570. void PWC_STOP_Enter(uint8_t u8StopType);
  571. int32_t PWC_STOP_StructInit(stc_pwc_stop_mode_config_t *pstcStopConfig);
  572. int32_t PWC_STOP_Config(const stc_pwc_stop_mode_config_t *pstcStopConfig);
  573. void PWC_STOP_ClockSelect(uint8_t u8Clock);
  574. void PWC_STOP_SetDrv(uint8_t u8StopDrv);
  575. void PWC_STOP_FlashWaitCmd(en_functional_state_t enNewState);
  576. void PWC_STOP_ExBusHoldConfig(uint16_t u16ExBusHold);
  577. /* PWC Speed Switch Function */
  578. int32_t PWC_HighSpeedToLowSpeed(void);
  579. int32_t PWC_LowSpeedToHighSpeed(void);
  580. /* PWC LDO Function */
  581. void PWC_LDO_Cmd(uint16_t u16Ldo, en_functional_state_t enNewState);
  582. /* PWC LVD Function, LVD for PVD while HC32F460, HC32F451, HC32F452 and HC32F4A0 */
  583. int32_t PWC_LVD_Init(uint8_t u8Ch, const stc_pwc_lvd_init_t *pstcLvdInit);
  584. int32_t PWC_LVD_StructInit(stc_pwc_lvd_init_t *pstcLvdInit);
  585. void PWC_LVD_Cmd(uint8_t u8Ch, en_functional_state_t enNewState);
  586. void PWC_LVD_ExtInputCmd(en_functional_state_t enNewState);
  587. void PWC_LVD_CompareOutputCmd(uint8_t u8Ch, en_functional_state_t enNewState);
  588. void PWC_LVD_DigitalFilterCmd(uint8_t u8Ch, en_functional_state_t enNewState);
  589. void PWC_LVD_SetFilterClock(uint8_t u8Ch, uint32_t u32Clock);
  590. void PWC_LVD_SetThresholdVoltage(uint8_t u8Ch, uint32_t u32Voltage);
  591. void PWC_LVD_ClearStatus(uint8_t u8Flag);
  592. en_flag_status_t PWC_LVD_GetStatus(uint8_t u8Flag);
  593. /* PWC Power Monitor Function */
  594. void PWC_PowerMonitorCmd(en_functional_state_t enNewState);
  595. /* PWC RAM Function */
  596. void PWC_XTAL32_PowerCmd(en_functional_state_t enNewState);
  597. void PWC_RetSram_PowerCmd(en_functional_state_t enNewState);
  598. /**
  599. * @}
  600. */
  601. #endif /* LL_PWC_ENABLE */
  602. /**
  603. * @}
  604. */
  605. /**
  606. * @}
  607. */
  608. #ifdef __cplusplus
  609. }
  610. #endif
  611. #endif /* __HC32_LL_PWC_H__ */
  612. /*******************************************************************************
  613. * EOF (not truncated)
  614. ******************************************************************************/