hc32f460_timer0.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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_timer0.h
  11. **
  12. ** A detailed description is available at
  13. ** @link Timer0Group description @endlink
  14. **
  15. ** - 2018-10-11 CDT First version for Device Driver Library of TIMER0.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_TIMER0_H__
  19. #define __HC32F460_TIMER0_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_TIMER0_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 Timer0Group Timer0
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief Timer0 channel enumeration
  43. **
  44. ******************************************************************************/
  45. typedef enum en_tim0_channel
  46. {
  47. Tim0_ChannelA = 0x00u,
  48. Tim0_ChannelB = 0x01u
  49. }en_tim0_channel_t;
  50. /**
  51. *******************************************************************************
  52. ** \brief Timer0 Async Mode clock enumeration
  53. **
  54. ******************************************************************************/
  55. typedef enum en_tim0_async_clock_src
  56. {
  57. Tim0_LRC = 0x00u,
  58. Tim0_XTAL32 = 0x01u
  59. }en_tim0_async_clock_src_t;
  60. /**
  61. *******************************************************************************
  62. ** \brief Timer0 Sync Mode clock enumeration
  63. **
  64. ******************************************************************************/
  65. typedef enum en_tim0_sync_clock_src
  66. {
  67. Tim0_Pclk1 = 0x00u,
  68. Tim0_InsideHardTrig = 0x01u
  69. }en_tim0_sync_clock_src_t;
  70. /**
  71. *******************************************************************************
  72. ** \brief Timer0 counter mode enumeration
  73. **
  74. ******************************************************************************/
  75. typedef enum en_tim0_counter_mode
  76. {
  77. Tim0_Sync = 0x00u,
  78. Tim0_Async = 0x01u
  79. }en_tim0_counter_mode_t;
  80. /**
  81. *******************************************************************************
  82. ** \brief Timer0 trigger event mode enumeration
  83. **
  84. ******************************************************************************/
  85. typedef enum en_tim0_function
  86. {
  87. Tim0_OutputCapare = 0x00u,
  88. Tim0_InputCaptrue = 0x01u
  89. }en_tim0_function_t;
  90. /**
  91. *******************************************************************************
  92. ** \brief Timer0 clock division enumeration
  93. **
  94. ******************************************************************************/
  95. typedef enum en_tim0_clock_div
  96. {
  97. Tim0_ClkDiv0 = 0u,
  98. Tim0_ClkDiv2,
  99. Tim0_ClkDiv4,
  100. Tim0_ClkDiv8,
  101. Tim0_ClkDiv16,
  102. Tim0_ClkDiv32,
  103. Tim0_ClkDiv64,
  104. Tim0_ClkDiv128,
  105. Tim0_ClkDiv256,
  106. Tim0_ClkDiv512,
  107. Tim0_ClkDiv1024
  108. }en_tim0_clock_div_t;
  109. /**
  110. *******************************************************************************
  111. ** \brief Timer0 common trigger source select enumeration
  112. **
  113. ******************************************************************************/
  114. typedef enum en_tim0_com_trigger
  115. {
  116. Tim0ComTrigger_1 = 1u, ///< Select common trigger 1.
  117. Tim0ComTrigger_2 = 2u, ///< Select common trigger 2.
  118. Tim0ComTrigger_1_2 = 3u, ///< Select common trigger 1 and 2.
  119. } en_tim0_com_trigger_t;
  120. /**
  121. *******************************************************************************
  122. ** \brief Timer0 trigger function init structrue definition
  123. **
  124. ******************************************************************************/
  125. typedef struct stc_tim0_trigger_init
  126. {
  127. en_tim0_function_t Tim0_OCMode; ///<specifies the TIM mode value of @ref en_tim0_function_t
  128. en_event_src_t Tim0_SelTrigSrc; ///<specifies the TIM Clk Src, and this parameter can be a value of @ref en_event_src_t
  129. bool Tim0_InTrigEnable;///<specifies the TIM enable trigger
  130. bool Tim0_InTrigClear; ///<specifies the TIM enable trigger clear
  131. bool Tim0_InTrigStop; ///<specifies the TIM enable trigger stop
  132. bool Tim0_InTrigStart; ///<specifies the TIM enable trigger start
  133. }stc_tim0_trigger_init_t;
  134. /**
  135. *******************************************************************************
  136. ** \brief Timer0 base counter function init structrue definition
  137. **
  138. ******************************************************************************/
  139. typedef struct stc_tim0_base_init
  140. {
  141. en_tim0_clock_div_t Tim0_ClockDivision; ///<specifies the TIM clock division, and this parameter can be a value of @ref en_tim0_clock_div_t*/
  142. en_tim0_sync_clock_src_t Tim0_SyncClockSource; ///<specifies the TIM sync clock source, and this parameter can be a value of @ref en_tim0_sync_clock_src_t*/
  143. en_tim0_async_clock_src_t Tim0_AsyncClockSource;///<specifies the TIM async clock source, and this parameter can be a value of @ref en_tim0_async_clock_src_t*/
  144. en_tim0_counter_mode_t Tim0_CounterMode; ///<specifies the TIM counter mode, and this parameter can be a value of @ref en_tim0_counter_mode_t*/
  145. uint16_t Tim0_CmpValue; ///<specifies the TIM counter value This value can be set 0-0xFFFF
  146. }stc_tim0_base_init_t;
  147. /*******************************************************************************
  148. * Global pre-processor symbols/macros ('#define')
  149. ******************************************************************************/
  150. /*******************************************************************************
  151. * Global variable definitions ('extern')
  152. ******************************************************************************/
  153. /*******************************************************************************
  154. Global function prototypes (definition in C source)
  155. ******************************************************************************/
  156. en_flag_status_t TIMER0_GetFlag(M4_TMR0_TypeDef* pstcTim0Reg, en_tim0_channel_t enCh);
  157. en_result_t TIMER0_ClearFlag(M4_TMR0_TypeDef* pstcTim0Reg, en_tim0_channel_t enCh);
  158. en_result_t TIMER0_Cmd(M4_TMR0_TypeDef* pstcTim0Reg, en_tim0_channel_t enCh,
  159. en_functional_state_t enCmd);
  160. en_result_t TIMER0_SetFunc(M4_TMR0_TypeDef* pstcTim0Reg, en_tim0_channel_t enCh,
  161. en_tim0_function_t enFunc);
  162. en_result_t TIMER0_IntCmd(M4_TMR0_TypeDef* pstcTim0Reg, en_tim0_channel_t enCh,
  163. en_functional_state_t enCmd);
  164. uint16_t TIMER0_GetCntReg(M4_TMR0_TypeDef* pstcTim0Reg,en_tim0_channel_t enCh);
  165. en_result_t TIMER0_WriteCntReg(M4_TMR0_TypeDef* pstcTim0Reg,en_tim0_channel_t enCh,uint16_t u16Cnt);
  166. uint16_t TIMER0_GetCmpReg(M4_TMR0_TypeDef* pstcTim0Reg,en_tim0_channel_t enCh);
  167. en_result_t TIMER0_WriteCmpReg(M4_TMR0_TypeDef* pstcTim0Reg, en_tim0_channel_t enCh,uint16_t u16Cnt);
  168. en_result_t TIMER0_BaseInit(M4_TMR0_TypeDef* pstcTim0Reg,en_tim0_channel_t enCh,
  169. const stc_tim0_base_init_t* pstcBaseInit);
  170. en_result_t TIMER0_DeInit(M4_TMR0_TypeDef* pstcTim0Reg,en_tim0_channel_t enCh);
  171. en_result_t TIMER0_HardTriggerInit(M4_TMR0_TypeDef* pstcTim0Reg,en_tim0_channel_t enCh,
  172. const stc_tim0_trigger_init_t* pStcInit);
  173. void TIMER0_SetTriggerSrc(en_event_src_t enEvent);
  174. void TIMER0_ComTriggerCmd(en_tim0_com_trigger_t enComTrigger, en_functional_state_t enState);
  175. //@} // Timer0Group
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #endif /* DDL_TIMER0_ENABLE */
  180. #endif /* __HC32F460_TIMER0_H__ */
  181. /*******************************************************************************
  182. * EOF (not truncated)
  183. ******************************************************************************/