hc32_ll_fcm.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_fcm.h
  4. * @brief This file contains all the functions prototypes of the FCM 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_FCM_H__
  22. #define __HC32_LL_FCM_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_FCM
  40. * @{
  41. */
  42. #if (LL_FCM_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup FCM_Global_Types FCM Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief FCM Init structure definition
  52. */
  53. typedef struct {
  54. uint16_t u16LowerLimit; /*!< FCM lower limit value */
  55. uint16_t u16UpperLimit; /*!< FCM upper limit value */
  56. uint32_t u32TargetClock; /*!< FCM target clock source selection, @ref FCM_Target_Clock_Src */
  57. uint32_t u32TargetClockDiv; /*!< FCM target clock source division selection, @ref FCM_Target_Clock_Div */
  58. uint32_t u32ExtRefClockEnable; /*!< FCM external reference clock function config, @ref FCM_Ext_Ref_Clock_Config */
  59. uint32_t u32RefClockEdge; /*!< FCM reference clock trigger edge selection, @ref FCM_Ref_Clock_Edge */
  60. uint32_t u32DigitalFilter; /*!< FCM digital filter function config, @ref FCM_Digital_Filter_Config */
  61. uint32_t u32RefClock; /*!< FCM reference clock source selection, @ref FCM_Ref_Clock_Src */
  62. uint32_t u32RefClockDiv; /*!< FCM reference clock source division selection, @ref FCM_Ref_Clock_Div */
  63. uint32_t u32ExceptionType; /*!< FCM exception type select, @ref FCM_Exception_Type */
  64. } stc_fcm_init_t;
  65. /**
  66. * @}
  67. */
  68. /*******************************************************************************
  69. * Global pre-processor symbols/macros ('#define')
  70. ******************************************************************************/
  71. /**
  72. * @defgroup FCM_Global_Macros FCM Global Macros
  73. * @{
  74. */
  75. /**
  76. * @defgroup FCM_Target_Clock_Src FCM Target Clock Source
  77. * @{
  78. */
  79. #define FCM_TARGET_CLK_XTAL (0x00UL << FCM_MCCR_MCKS_POS)
  80. #define FCM_TARGET_CLK_XTAL32 (0x01UL << FCM_MCCR_MCKS_POS)
  81. #define FCM_TARGET_CLK_HRC (0x02UL << FCM_MCCR_MCKS_POS)
  82. #define FCM_TARGET_CLK_LRC (0x03UL << FCM_MCCR_MCKS_POS)
  83. #define FCM_TARGET_CLK_SWDTLRC (0x04UL << FCM_MCCR_MCKS_POS)
  84. #define FCM_TARGET_CLK_PCLK1 (0x05UL << FCM_MCCR_MCKS_POS)
  85. #define FCM_TARGET_CLK_MRC (0x07UL << FCM_MCCR_MCKS_POS)
  86. #define FCM_TARGET_CLK_PLLHP (0x08UL << FCM_MCCR_MCKS_POS)
  87. /**
  88. * @}
  89. */
  90. /**
  91. * @defgroup FCM_Target_Clock_Div FCM Target Clock Division
  92. * @{
  93. */
  94. #define FCM_TARGET_CLK_DIV1 (0x00UL << FCM_MCCR_MDIVS_POS)
  95. #define FCM_TARGET_CLK_DIV4 (0x01UL << FCM_MCCR_MDIVS_POS)
  96. #define FCM_TARGET_CLK_DIV8 (0x02UL << FCM_MCCR_MDIVS_POS)
  97. #define FCM_TARGET_CLK_DIV32 (0x03UL << FCM_MCCR_MDIVS_POS)
  98. /**
  99. * @}
  100. */
  101. /**
  102. * @defgroup FCM_Ext_Ref_Clock_Config FCM External Reference Clock Config
  103. * @{
  104. */
  105. #define FCM_EXT_REF_OFF (0x00UL)
  106. #define FCM_EXT_REF_ON (FCM_RCCR_EXREFE)
  107. /**
  108. * @}
  109. */
  110. /**
  111. * @defgroup FCM_Ref_Clock_Edge FCM Reference Clock Edge
  112. * @{
  113. */
  114. #define FCM_REF_CLK_RISING (0x00UL)
  115. #define FCM_REF_CLK_FALLING (FCM_RCCR_EDGES_0)
  116. #define FCM_REF_CLK_BOTH (FCM_RCCR_EDGES_1)
  117. /**
  118. * @}
  119. */
  120. /**
  121. * @defgroup FCM_Digital_Filter_Config FCM Digital Filter Config
  122. * @{
  123. */
  124. #define FCM_DIG_FILTER_OFF (0x00UL)
  125. #define FCM_DIG_FILTER_DIV1 (FCM_RCCR_DNFS_0)
  126. #define FCM_DIG_FILTER_DIV4 (FCM_RCCR_DNFS_1)
  127. #define FCM_DIG_FILTER_DIV16 (FCM_RCCR_DNFS)
  128. /**
  129. * @}
  130. */
  131. /**
  132. * @defgroup FCM_Ref_Clock_Src FCM Reference Clock Source
  133. * @{
  134. */
  135. #define FCM_REF_CLK_EXTCLK (0x00UL << FCM_RCCR_RCKS_POS)
  136. #define FCM_REF_CLK_XTAL (0x10UL << FCM_RCCR_RCKS_POS)
  137. #define FCM_REF_CLK_XTAL32 (0x11UL << FCM_RCCR_RCKS_POS)
  138. #define FCM_REF_CLK_HRC (0x12UL << FCM_RCCR_RCKS_POS)
  139. #define FCM_REF_CLK_LRC (0x13UL << FCM_RCCR_RCKS_POS)
  140. #define FCM_REF_CLK_SWDTLRC (0x14UL << FCM_RCCR_RCKS_POS)
  141. #define FCM_REF_CLK_PCLK1 (0x15UL << FCM_RCCR_RCKS_POS)
  142. #define FCM_REF_CLK_MRC (0x17UL << FCM_RCCR_RCKS_POS)
  143. #define FCM_REF_CLK_PLLHP (0x18UL << FCM_RCCR_RCKS_POS)
  144. /**
  145. * @}
  146. */
  147. /**
  148. * @defgroup FCM_Ref_Clock_Div FCM Reference Clock Division
  149. * @{
  150. */
  151. #define FCM_REF_CLK_DIV32 (0x00UL << FCM_RCCR_RDIVS_POS)
  152. #define FCM_REF_CLK_DIV128 (0x01UL << FCM_RCCR_RDIVS_POS)
  153. #define FCM_REF_CLK_DIV1024 (0x02UL << FCM_RCCR_RDIVS_POS)
  154. #define FCM_REF_CLK_DIV8192 (0x03UL << FCM_RCCR_RDIVS_POS)
  155. /**
  156. * @}
  157. */
  158. /**
  159. * @defgroup FCM_Abnormal_Reset_Func FCM Abnormal Reset Function Config
  160. * @{
  161. */
  162. #define FCM_ERR_RST_OFF (0x00UL)
  163. #define FCM_ERR_RST_ON (FCM_RIER_ERRE)
  164. /**
  165. * @}
  166. */
  167. /**
  168. * @defgroup FCM_Exception_Type FCM Exception Type
  169. * @{
  170. */
  171. #define FCM_EXP_TYPE_INT (0x00UL)
  172. #define FCM_EXP_TYPE_RST (FCM_RIER_ERRINTRS)
  173. /**
  174. * @}
  175. */
  176. /**
  177. * @defgroup FCM_Int_Type FCM Interrupt Type
  178. * @{
  179. */
  180. #define FCM_INT_OVF (FCM_RIER_OVFIE)
  181. #define FCM_INT_END (FCM_RIER_MENDIE)
  182. #define FCM_INT_ERR (FCM_RIER_ERRIE)
  183. /**
  184. * @}
  185. */
  186. /**
  187. * @defgroup FCM_Flag_Sel FCM Status Flag Selection
  188. * @{
  189. */
  190. #define FCM_FLAG_ERR (FCM_SR_ERRF)
  191. #define FCM_FLAG_END (FCM_SR_MENDF)
  192. #define FCM_FLAG_OVF (FCM_SR_OVF)
  193. /**
  194. * @}
  195. */
  196. /**
  197. * @}
  198. */
  199. /*******************************************************************************
  200. * Global variable definitions ('extern')
  201. ******************************************************************************/
  202. /*******************************************************************************
  203. Global function prototypes (definition in C source)
  204. ******************************************************************************/
  205. /**
  206. * @addtogroup FCM_Global_Functions
  207. * @{
  208. */
  209. /**
  210. * @brief Set FCM upper limit value.
  211. * @param u16Limit
  212. * @retval None.
  213. */
  214. __STATIC_INLINE void FCM_SetUpperLimit(uint16_t u16Limit)
  215. {
  216. WRITE_REG32(CM_FCM->UVR, u16Limit);
  217. }
  218. /**
  219. * @brief Set FCM lower limit value.
  220. * @param u16Limit
  221. * @retval None
  222. */
  223. __STATIC_INLINE void FCM_SetLowerLimit(uint16_t u16Limit)
  224. {
  225. WRITE_REG32(CM_FCM->LVR, u16Limit);
  226. }
  227. int32_t FCM_Init(const stc_fcm_init_t *pstcFcmInit);
  228. int32_t FCM_StructInit(stc_fcm_init_t *pstcFcmInit);
  229. void FCM_DeInit(void);
  230. uint16_t FCM_GetCountValue(void);
  231. void FCM_SetUpperLimit(uint16_t u16Limit);
  232. void FCM_SetLowerLimit(uint16_t u16Limit);
  233. void FCM_SetTargetClock(uint32_t u32ClockSrc, uint32_t u32Div);
  234. void FCM_SetRefClock(uint32_t u32ClockSrc, uint32_t u32Div);
  235. en_flag_status_t FCM_GetStatus(uint32_t u32Flag);
  236. void FCM_ClearStatus(uint32_t u32Flag);
  237. void FCM_ResetCmd(en_functional_state_t enNewState);
  238. void FCM_IntCmd(uint32_t u32IntType, en_functional_state_t enNewState);
  239. void FCM_Cmd(en_functional_state_t enNewState);
  240. /**
  241. * @}
  242. */
  243. #endif /* LL_FCM_ENABLE */
  244. /**
  245. * @}
  246. */
  247. /**
  248. * @}
  249. */
  250. #ifdef __cplusplus
  251. }
  252. #endif
  253. #endif /* __HC32_LL_FCM_H__ */
  254. /*******************************************************************************
  255. * EOF (not truncated)
  256. ******************************************************************************/