hc32_ll_tmr0.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_tmr0.h
  4. * @brief This file contains all the functions prototypes of the TMR0 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_TMR0_H__
  22. #define __HC32_LL_TMR0_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_TMR0
  40. * @{
  41. */
  42. #if (LL_TMR0_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup TMR0_Global_Types TMR0 Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief TMR0 initialization structure definition
  52. * @note The 'u32ClockDiv' is invalid when the value of 'u32ClockSrc' is "TMR0_CLK_SRC_SPEC_EVT".
  53. */
  54. typedef struct {
  55. uint32_t u32ClockSrc; /*!< Specifies the clock source of TMR0 channel.
  56. This parameter can be a value of @ref TMR0_Clock_Source */
  57. uint32_t u32ClockDiv; /*!< Specifies the clock division of TMR0 channel.
  58. This parameter can be a value of @ref TMR0_Clock_Division */
  59. uint32_t u32Func; /*!< Specifies the function of TMR0 channel.
  60. This parameter can be a value of @ref TMR0_Function */
  61. uint16_t u16CompareValue; /*!< Specifies the compare value of TMR0 channel.
  62. This parameter can be a value of half-word */
  63. } stc_tmr0_init_t;
  64. /**
  65. * @}
  66. */
  67. /*******************************************************************************
  68. * Global pre-processor symbols/macros ('#define')
  69. ******************************************************************************/
  70. /**
  71. * @defgroup TMR0_Global_Macros TMR0 Global Macros
  72. * @{
  73. */
  74. /**
  75. * @defgroup TMR0_Channel TMR0 Channel
  76. * @{
  77. */
  78. #define TMR0_CH_A (0UL)
  79. #define TMR0_CH_B (1UL)
  80. /**
  81. * @}
  82. */
  83. /**
  84. * @defgroup TMR0_Clock_Source TMR0 Clock Source
  85. * @note In asynchronous clock, continuous operation of the BCONR register requires waiting for 3 asynchronous clocks.
  86. * @{
  87. */
  88. #define TMR0_CLK_SRC_INTERN_CLK (0UL) /*!< Internal clock (Synchronous clock) */
  89. #define TMR0_CLK_SRC_SPEC_EVT (TMR0_BCONR_SYNCLKA) /*!< Specified event (Synchronous clock) */
  90. #define TMR0_CLK_SRC_LRC (TMR0_BCONR_SYNSA) /*!< LRC (Asynchronous clock) */
  91. #define TMR0_CLK_SRC_XTAL32 (TMR0_BCONR_ASYNCLKA | TMR0_BCONR_SYNSA) /*!< XTAL32 (Asynchronous clock) */
  92. /**
  93. * @}
  94. */
  95. /**
  96. * @defgroup TMR0_Clock_Division TMR0 Clock Division
  97. * @{
  98. */
  99. #define TMR0_CLK_DIV1 (0UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK */
  100. #define TMR0_CLK_DIV2 (1UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/2 */
  101. #define TMR0_CLK_DIV4 (2UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/4 */
  102. #define TMR0_CLK_DIV8 (3UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/8 */
  103. #define TMR0_CLK_DIV16 (4UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/16 */
  104. #define TMR0_CLK_DIV32 (5UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/32 */
  105. #define TMR0_CLK_DIV64 (6UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/64 */
  106. #define TMR0_CLK_DIV128 (7UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/128 */
  107. #define TMR0_CLK_DIV256 (8UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/256 */
  108. #define TMR0_CLK_DIV512 (9UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/512 */
  109. #define TMR0_CLK_DIV1024 (10UL << TMR0_BCONR_CKDIVA_POS) /*!< CLK/1024 */
  110. /**
  111. * @}
  112. */
  113. /**
  114. * @defgroup TMR0_Function TMR0 Function
  115. * @{
  116. */
  117. #define TMR0_FUNC_CMP (0UL) /*!< Output comare function */
  118. #define TMR0_FUNC_CAPT (TMR0_BCONR_CAPMDA | TMR0_BCONR_HICPA) /*!< Input capture function */
  119. /**
  120. * @}
  121. */
  122. /**
  123. * @defgroup TMR0_Interrupt TMR0 Interrupt
  124. * @{
  125. */
  126. #define TMR0_INT_CMP_A (TMR0_BCONR_CMENA)
  127. #define TMR0_INT_CMP_B (TMR0_BCONR_CMENB)
  128. #define TMR0_INT_OVF_A (TMR0_BCONR_OVENA)
  129. #define TMR0_INT_OVF_B (TMR0_BCONR_OVENB)
  130. #define TMR0_INT_ALL (TMR0_INT_CMP_A | TMR0_INT_OVF_A | TMR0_INT_CMP_B | TMR0_INT_OVF_B)
  131. /**
  132. * @}
  133. */
  134. /**
  135. * @defgroup TMR0_FLAG TMR0 Flag
  136. * @{
  137. */
  138. #define TMR0_FLAG_CMP_A (TMR0_STFLR_CMFA)
  139. #define TMR0_FLAG_CMP_B (TMR0_STFLR_CMFB)
  140. #define TMR0_FLAG_REPEAT_CAPT_A (TMR0_STFLR_ICPA)
  141. #define TMR0_FLAG_REPEAT_CAPT_B (TMR0_STFLR_ICPB)
  142. #define TMR0_FLAG_OVF_A (TMR0_STFLR_OVFA)
  143. #define TMR0_FLAG_OVF_B (TMR0_STFLR_OVFB)
  144. #define TMR0_FLAG_ALL (TMR0_FLAG_CMP_A | TMR0_FLAG_CMP_B | TMR0_FLAG_REPEAT_CAPT_A | \
  145. TMR0_FLAG_REPEAT_CAPT_B | TMR0_FLAG_OVF_A | TMR0_FLAG_OVF_B)
  146. /**
  147. * @}
  148. */
  149. /**
  150. * @}
  151. */
  152. /*******************************************************************************
  153. * Global variable definitions ('extern')
  154. ******************************************************************************/
  155. /*******************************************************************************
  156. Global function prototypes (definition in C source)
  157. ******************************************************************************/
  158. /**
  159. * @addtogroup TMR0_Global_Functions
  160. * @{
  161. */
  162. /* Initialization functions */
  163. void TMR0_DeInit(CM_TMR0_TypeDef *TMR0x);
  164. int32_t TMR0_Init(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, const stc_tmr0_init_t *pstcTmr0Init);
  165. int32_t TMR0_StructInit(stc_tmr0_init_t *pstcTmr0Init);
  166. void TMR0_Start(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch);
  167. void TMR0_Stop(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch);
  168. /* Control configuration functions */
  169. void TMR0_SetCountValue(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint16_t u16Value);
  170. uint16_t TMR0_GetCountValue(const CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch);
  171. void TMR0_SetCompareValue(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint16_t u16Value);
  172. uint16_t TMR0_GetCompareValue(const CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch);
  173. void TMR0_SetClockSrc(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint32_t u32Src);
  174. void TMR0_SetClockDiv(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint32_t u32Div);
  175. void TMR0_SetFunc(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint32_t u32Func);
  176. /* Hardware trigger Functions */
  177. void TMR0_HWCaptureCondCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, en_functional_state_t enNewState);
  178. void TMR0_HWStartCondCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, en_functional_state_t enNewState);
  179. void TMR0_HWStopCondCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, en_functional_state_t enNewState);
  180. void TMR0_HWClearCondCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, en_functional_state_t enNewState);
  181. /* Interrupt and flag management functions */
  182. void TMR0_IntCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32IntType, en_functional_state_t enNewState);
  183. en_flag_status_t TMR0_GetStatus(const CM_TMR0_TypeDef *TMR0x, uint32_t u32Flag);
  184. void TMR0_ClearStatus(CM_TMR0_TypeDef *TMR0x, uint32_t u32Flag);
  185. /**
  186. * @}
  187. */
  188. #endif /* LL_TMR0_ENABLE */
  189. /**
  190. * @}
  191. */
  192. /**
  193. * @}
  194. */
  195. #ifdef __cplusplus
  196. }
  197. #endif
  198. #endif /* __HC32_LL_TMR0_H__ */
  199. /*******************************************************************************
  200. * EOF (not truncated)
  201. ******************************************************************************/