hc32f460_timer4_oco.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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_timer4_oco.h
  11. **
  12. ** A detailed description is available at
  13. ** @link Timer4OcoGroup Timer4OCO description @endlink
  14. **
  15. ** - 2018-11-02 CDT First version for Device Driver Library of Timer4OCO.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_TIMER4_OCO_H__
  19. #define __HC32F460_TIMER4_OCO_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_TIMER4_OCO_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 Timer4OcoGroup Timer4 Output Compare(Timer4OCO)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief Timer4 OCO channel enumeration
  43. **
  44. ******************************************************************************/
  45. typedef enum en_timer4_oco_ch
  46. {
  47. Timer4OcoOuh = 0u, ///< Timer4 OCO channel:OUH
  48. Timer4OcoOul = 1u, ///< Timer4 OCO channel:OUL
  49. Timer4OcoOvh = 2u, ///< Timer4 OCO channel:OVH
  50. Timer4OcoOvl = 3u, ///< Timer4 OCO channel:OVL
  51. Timer4OcoOwh = 4u, ///< Timer4 OCO channel:OWH
  52. Timer4OcoOwl = 5u, ///< Timer4 OCO channel:OWL
  53. } en_timer4_oco_ch_t;
  54. /**
  55. *******************************************************************************
  56. ** \brief output level of the OC port enumeration
  57. **
  58. ******************************************************************************/
  59. typedef enum en_timer4_oco_port_level
  60. {
  61. OcPortLevelLow = 0u, ///< Output low level to OC port
  62. OcPortLevelHigh = 1u, ///< Output high level to OC port
  63. } en_timer4_oco_port_level_t;
  64. /**
  65. *******************************************************************************
  66. ** \brief buffer register function of OCCR
  67. **
  68. ******************************************************************************/
  69. typedef enum en_timer4_oco_occr_buf
  70. {
  71. OccrBufDisable = 0u, ///< Disable the register buffer function
  72. OccrBufTrsfByCntZero = 1u, ///< Register buffer transfer when counter value is 0x0000
  73. OccrBufTrsfByCntPeak = 2u, ///< Register buffer transfer when counter value is CPSR
  74. OccrBufTrsfByCntZeroOrCntPeak = 3u, ///< Register buffer transfer when the value is both 0 and CPSR
  75. OccrBufTrsfByCntZeroZicZero = 4u, ///< Register buffer transfer when counter value is 0x0000 and zero value detection mask counter value is 0
  76. OccrBufTrsfByCntPeakPicZero = 5u, ///< Register buffer transfer when counter value is CPSR and peak value detection mask counter value is 0
  77. OccrBufTrsfByCntZeroZicZeroOrCntPeakPicZero = 6u, ///< Register buffer transfer when counter value is 0x0000 and zero value detection mask counter value is 0 or
  78. ///< when counter value is CPSR and peak value detection mask counter value is 0
  79. } en_timer4_oco_occr_buf_t;
  80. /**
  81. *******************************************************************************
  82. ** \brief buffer register function of OCMR
  83. **
  84. ******************************************************************************/
  85. typedef enum en_timer4_oco_ocmr_buf
  86. {
  87. OcmrBufDisable = 0u, ///< Disable the register buffer function
  88. OcmrBufTrsfByCntZero = 1u, ///< Register buffer transfer when counter value is 0x0000
  89. OcmrBufTrsfByCntPeak = 2u, ///< Register buffer transfer when counter value is CPSR
  90. OcmrBufTrsfByCntZeroOrCntPeak = 3u, ///< Register buffer transfer when the value is both 0 and CPSR
  91. OcmrBufTrsfByCntZeroZicZero = 4u, ///< Register buffer transfer when CNT counter value is 0x0000 and zero value detection mask counter value is 0
  92. OcmrBufTrsfByCntPeakPicZero = 5u, ///< Register buffer transfer when CNT counter value is CPSR and peak value detection mask counter value is 0
  93. OcmrBufTrsfByCntZeroZicZeroOrCntPeakPicZero = 6u, ///< Register buffer transfer when CNT counter value is 0x0000 and zero value detection mask counter value is 0 or
  94. ///< when CNT counter value is CPSR and peak value detection mask counter value is 0
  95. } en_timer4_oco_ocmr_buf_t;
  96. /**
  97. *******************************************************************************
  98. ** \brief OP output status enumeration
  99. **
  100. ******************************************************************************/
  101. typedef enum en_timer4_oco_op_state
  102. {
  103. OcoOpOutputHold = 0u, ///< OP output hold
  104. OcoOpOutputHigh = 1u, ///< OP output high
  105. OcoOpOutputLow = 2u, ///< OP output low
  106. OcoOpOutputReverse = 3u, ///< OP output reverse
  107. } en_timer4_oco_op_state_t;
  108. /**
  109. *******************************************************************************
  110. ** \brief The condition for OCF set
  111. **
  112. ******************************************************************************/
  113. typedef enum en_timer4_oco_ocf_state
  114. {
  115. OcoOcfHold = 0u, ///< OCF hold
  116. OcoOcfSet = 1u, ///< OCF set
  117. } en_timer4_oco_ocf_state_t;
  118. /**
  119. *******************************************************************************
  120. ** \brief The configuration of OCO high channel(OUH/OVH/OWH)
  121. **
  122. ******************************************************************************/
  123. typedef struct stc_oco_high_ch_compare_mode
  124. {
  125. en_timer4_oco_op_state_t enCntZeroMatchOpState; ///< b11~b10 High channel's OP output status when high channel match occurs at the condition of CNT count=0x0000
  126. en_timer4_oco_op_state_t enCntZeroNotMatchOpState; ///< b15~b14 High channel's OP output status when high channel match doesn't occur at the condition of CNT count=0x0000
  127. en_timer4_oco_op_state_t enCntUpCntMatchOpState; ///< b9~b8 High channel's OP output status when high channel match occurs at the condition of CNT is counting up
  128. en_timer4_oco_op_state_t enCntPeakMatchOpState; ///< b7~b6 High channel's OP output status when high channel match occurs at the condition of CNT count=Peak
  129. en_timer4_oco_op_state_t enCntPeakNotMatchOpState; ///< b13~b12 High channel's OP output status when high channel match doesn't occur at the condition of CNT count=Peak
  130. en_timer4_oco_op_state_t enCntDownCntMatchOpState; ///< b5~b4 High channel's OP output status when high channel match occurs at the condition of CNT is counting down
  131. en_timer4_oco_ocf_state_t enCntZeroMatchOcfState; ///< b3 High channel's OCF status when high channel match occurs at the condition of CNT count=0x0000
  132. en_timer4_oco_ocf_state_t enCntUpCntMatchOcfState; ///< b2 High channel's OCF status when high channel match occurs at the condition of CNT is counting up
  133. en_timer4_oco_ocf_state_t enCntPeakMatchOcfState; ///< b1 High channel's OCF status when high channel match occurs at the condition of CNT count=Peak
  134. en_timer4_oco_ocf_state_t enCntDownCntMatchOcfState; ///< b0 High channel's OCF status when high channel match occurs at the condition of CNT is counting down
  135. en_functional_state_t enMatchConditionExtendCmd; ///< Enable: Extend the match condition
  136. ///< Disable: Don't extend the match conditio
  137. } stc_oco_high_ch_compare_mode_t;
  138. /**
  139. *******************************************************************************
  140. ** \brief The configuration of OCO low channel(OUL/OVL/OWL)
  141. **
  142. ******************************************************************************/
  143. typedef struct stc_oco_low_ch_compare_mode
  144. {
  145. en_timer4_oco_op_state_t enCntZeroLowMatchHighMatchLowChOpState; ///< b27~b26 Low channel's OP output status when high channel and low channel match occurs at the condition of CNT count=0x0000
  146. en_timer4_oco_op_state_t enCntZeroLowMatchHighNotMatchLowChOpState; ///< b11~b10 Low channel's OP output status when high channel not match and low channel match occurs at the condition of CNT count=0x0000
  147. en_timer4_oco_op_state_t enCntZeroLowNotMatchHighMatchLowChOpState; ///< b31~b30 Low channel's OP output status when high channel match and low channel not match occurs at the condition of CNT count=0x0000
  148. en_timer4_oco_op_state_t enCntZeroLowNotMatchHighNotMatchLowChOpState; ///< b15~b14 Low channel's OP output status when high channel not match and low channel not match occurs at the condition of CNT count=0x0000
  149. en_timer4_oco_op_state_t enCntUpCntLowMatchHighMatchLowChOpState; ///< b25~b24 Low channel's OP output status when high channel and low channel match occurs at the condition of CNT is counting up
  150. en_timer4_oco_op_state_t enCntUpCntLowMatchHighNotMatchLowChOpState; ///< b9~b8 Low channel's OP output status when high channel not match and low channel match occurs at the condition of CNT is counting up
  151. en_timer4_oco_op_state_t enCntUpCntLowNotMatchHighMatchLowChOpState; ///< b19~b18 Low channel's OP output status when high channel match and low channel not match occurs at the condition of CNT is counting up
  152. en_timer4_oco_op_state_t enCntPeakLowMatchHighMatchLowChOpState; ///< b23~b22 Low channel's OP output status when high channel and low channel match occurs at the condition of CNT count=Peak
  153. en_timer4_oco_op_state_t enCntPeakLowMatchHighNotMatchLowChOpState; ///< b7~b6 Low channel's OP output status when high channel not match and low channel match occurs at the condition of CNT count=Peak
  154. en_timer4_oco_op_state_t enCntPeakLowNotMatchHighMatchLowChOpState; ///< b29~b28 Low channel's OP output status when high channel match and low channel not match occurs at the condition of CNT count=Peak
  155. en_timer4_oco_op_state_t enCntPeakLowNotMatchHighNotMatchLowChOpState; ///< b13~b12 Low channel's OP output status when high channel not match and low channel not match occurs at the condition of CNT count=Peak
  156. en_timer4_oco_op_state_t enCntDownLowMatchHighMatchLowChOpState; ///< b21~b20 Low channel's OP output status when high channel and low channel match occurs at the condition of CNT is counting down
  157. en_timer4_oco_op_state_t enCntDownLowMatchHighNotMatchLowChOpState; ///< b5~b4 Low channel's OP output status when high channel not match and low channel match occurs at the condition of CNT is counting down
  158. en_timer4_oco_op_state_t enCntDownLowNotMatchHighMatchLowChOpState; ///< b17~b16 Low channel's OP output status when high channel match and low channel not match occurs at the condition of CNT is coutning down
  159. en_timer4_oco_ocf_state_t enCntZeroMatchOcfState; ///< b3 Low channel's OCF status when low channel match occurs at the condition of CNT count=0x0000
  160. en_timer4_oco_ocf_state_t enCntUpCntMatchOcfState; ///< b2 Low channel's OCF status when low channel match occurs at the condition of CNT is counting up
  161. en_timer4_oco_ocf_state_t enCntPeakMatchOcfState; ///< b1 Low channel's OCF status when low channel match occurs at the condition of CNT count=Peak
  162. en_timer4_oco_ocf_state_t enCntDownCntMatchOcfState; ///< b0 Low channel's OCF status when low channel match occurs at the condition of CNT is counting down
  163. en_functional_state_t enMatchConditionExtendCmd; ///< Enable: Extend the match condition
  164. ///< Disable: Don't extend the match conditio
  165. } stc_oco_low_ch_compare_mode_t;
  166. /**
  167. *******************************************************************************
  168. ** \brief Timer4 OCO initialization configuration
  169. **
  170. ******************************************************************************/
  171. typedef struct stc_timer4_oco_init
  172. {
  173. en_timer4_oco_occr_buf_t enOccrBufMode; ///< buffer register function of OCCR
  174. en_timer4_oco_ocmr_buf_t enOcmrBufMode; ///< buffer register function of OCMR
  175. en_timer4_oco_port_level_t enPortLevel; ///< OP output level state
  176. en_functional_state_t enOcoIntCmd; ///< Disable: Disable interrupt; Enable:Enable interrupt
  177. } stc_timer4_oco_init_t;
  178. /*******************************************************************************
  179. * Global pre-processor symbols/macros ('#define')
  180. ******************************************************************************/
  181. /*******************************************************************************
  182. * Global pre-processor symbols/macros ('#define')
  183. ******************************************************************************/
  184. /*******************************************************************************
  185. * Global variable definitions ('extern')
  186. ******************************************************************************/
  187. /*******************************************************************************
  188. * Global function prototypes (definition in C source)
  189. ******************************************************************************/
  190. en_result_t TIMER4_OCO_Init(M4_TMR4_TypeDef *TMR4x,
  191. en_timer4_oco_ch_t enCh,
  192. const stc_timer4_oco_init_t* pstcInitCfg);
  193. en_result_t TIMER4_OCO_DeInit(M4_TMR4_TypeDef *TMR4x,
  194. en_timer4_oco_ch_t enCh);
  195. en_result_t TIMER4_OCO_SetOccrBufMode(M4_TMR4_TypeDef *TMR4x,
  196. en_timer4_oco_ch_t enCh,
  197. en_timer4_oco_occr_buf_t enOccrBufMode);
  198. en_result_t TIMER4_OCO_SetOcmrBufMode(M4_TMR4_TypeDef *TMR4x,
  199. en_timer4_oco_ch_t enCh,
  200. en_timer4_oco_ocmr_buf_t enOcmrBufMode);
  201. en_result_t TIMER4_OCO_ExtMatchCondCmd(M4_TMR4_TypeDef *TMR4x,
  202. en_timer4_oco_ch_t enCh,
  203. en_functional_state_t enCmd);
  204. en_result_t TIMER4_OCO_SetHighChCompareMode(M4_TMR4_TypeDef *TMR4x,
  205. en_timer4_oco_ch_t enCh,
  206. const stc_oco_high_ch_compare_mode_t *pstcMode);
  207. en_result_t TIMER4_OCO_SetLowChCompareMode(M4_TMR4_TypeDef *TMR4x,
  208. en_timer4_oco_ch_t enCh,
  209. const stc_oco_low_ch_compare_mode_t *pstcMode);
  210. en_result_t TIMER4_OCO_OutputCompareCmd(M4_TMR4_TypeDef *TMR4x,
  211. en_timer4_oco_ch_t enCh,
  212. en_functional_state_t enCmd);
  213. en_result_t TIMER4_OCO_IrqCmd(M4_TMR4_TypeDef *TMR4x,
  214. en_timer4_oco_ch_t enCh,
  215. en_functional_state_t enCmd);
  216. en_flag_status_t TIMER4_OCO_GetIrqFlag(M4_TMR4_TypeDef *TMR4x,
  217. en_timer4_oco_ch_t enCh);
  218. en_result_t TIMER4_OCO_ClearIrqFlag(M4_TMR4_TypeDef *TMR4x,
  219. en_timer4_oco_ch_t enCh);
  220. en_result_t TIMER4_OCO_SetOpPortLevel(M4_TMR4_TypeDef *TMR4x,
  221. en_timer4_oco_ch_t enCh,
  222. en_timer4_oco_port_level_t enLevel);
  223. en_timer4_oco_port_level_t TIMER4_OCO_GetOpPinLevel(M4_TMR4_TypeDef *TMR4x,
  224. en_timer4_oco_ch_t enCh);
  225. en_result_t TIMER4_OCO_WriteOccr(M4_TMR4_TypeDef *TMR4x,
  226. en_timer4_oco_ch_t enCh,
  227. uint16_t u16Occr);
  228. uint16_t TIMER4_OCO_ReadOccr(const M4_TMR4_TypeDef *TMR4x,
  229. en_timer4_oco_ch_t enCh);
  230. //@} // Timer4OcoGroup
  231. #ifdef __cplusplus
  232. }
  233. #endif
  234. #endif /* DDL_TIMER4_OCO_ENABLE */
  235. #endif /* __HC32F460_TIMER4_OCO_H__ */
  236. /*******************************************************************************
  237. * EOF (not truncated)
  238. ******************************************************************************/