hc32l196_pcnt.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*******************************************************************************
  2. * Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
  3. *
  4. * This software is owned and published by:
  5. * Huada Semiconductor Co.,Ltd ("HDSC").
  6. *
  7. * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
  8. * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
  9. *
  10. * This software contains source code for use with HDSC
  11. * components. This software is licensed by HDSC to be adapted only
  12. * for use in systems utilizing HDSC components. HDSC shall not be
  13. * responsible for misuse or illegal use of this software for devices not
  14. * supported herein. HDSC is providing this software "AS IS" and will
  15. * not be responsible for issues arising from incorrect user implementation
  16. * of the software.
  17. *
  18. * Disclaimer:
  19. * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
  20. * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
  21. * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
  22. * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
  23. * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
  24. * WARRANTY OF NONINFRINGEMENT.
  25. * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
  26. * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
  27. * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
  28. * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
  29. * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
  30. * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
  31. * SAVINGS OR PROFITS,
  32. * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  33. * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
  34. * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
  35. * FROM, THE SOFTWARE.
  36. *
  37. * This software may be replicated in part or whole for the licensed use,
  38. * with the restriction that this Disclaimer and Copyright notice must be
  39. * included with each copy of this software, whether used in part or whole,
  40. * at all times.
  41. */
  42. /******************************************************************************/
  43. /** \file pcnt.h
  44. **
  45. ** Headerfile for PCNT functions
  46. ** @link PCNT Group Some description @endlink
  47. **
  48. ** History:
  49. ** - 2019-04-08 First Version
  50. **
  51. ******************************************************************************/
  52. #ifndef __PCNT_H__
  53. #define __PCNT_H__
  54. /*******************************************************************************
  55. * Include files
  56. ******************************************************************************/
  57. #include "ddl.h"
  58. #ifdef __cplusplus
  59. extern "C"
  60. {
  61. #endif
  62. /**
  63. ******************************************************************************
  64. ** \defgroup PCNTGroup (PCNT)
  65. **
  66. ******************************************************************************/
  67. //@{
  68. /**
  69. *******************************************************************************
  70. ** function prototypes.
  71. ******************************************************************************/
  72. /**
  73. *******************************************************************************
  74. ** \brief PCNT S0通道极性选择
  75. ** \note PCNT_CTRL S0P
  76. ******************************************************************************/
  77. typedef enum
  78. {
  79. PcntS0PNoinvert = 0u, // S0通道极性不取反
  80. PcntS0PInvert = 1u // S0通道极性取反
  81. }en_pcnt_s0polar_t;
  82. /**
  83. *******************************************************************************
  84. ** \brief PCNT S1通道极性选择
  85. ** \note PCNT_CTRL S1P
  86. ******************************************************************************/
  87. typedef enum
  88. {
  89. PcntS1PNoinvert = 0u, // S1通道极性不取反
  90. PcntS1PInvert = 1u // S1通道极性取反
  91. }en_pcnt_s1polar_t;
  92. /**
  93. *******************************************************************************
  94. ** \brief PCNT 计数方向选择
  95. ** \note PCNT_CTRL DIR
  96. ******************************************************************************/
  97. typedef enum
  98. {
  99. PcntNDoubleDirAdd = 0u, // 加计数
  100. PcntNDoubleDirSub = 1u // 减计数
  101. }en_pcnt_dir_t;
  102. /**
  103. *******************************************************************************
  104. ** \brief PCNT 计数时钟选择
  105. ** \note PCNT_CTRL ClkSel
  106. ******************************************************************************/
  107. typedef enum
  108. {
  109. PcntCLKPclk = 1u, // PCLK
  110. PcntCLKXtl = 2u, // XTL
  111. PcntCLKRcl = 3u // RCL
  112. }en_pcnt_clksel_t;
  113. /**
  114. *******************************************************************************
  115. ** \brief PCNT 脉冲计数模式选择
  116. ** \note PCNT_CTRL Mode
  117. ******************************************************************************/
  118. typedef enum
  119. {
  120. PcntSingleMode = 1u, // 单通道脉冲计数模式
  121. PcntSpecialMode = 2u, // 双通道非正交脉冲计数模式
  122. PcntDoubleMode = 3u // 双通道正交脉冲计数模式
  123. }en_pcnt_mode_t;
  124. /**
  125. ******************************************************************************
  126. ** \brief PCNT 状态
  127. ** \note PCNT_IFR & PCNT_ICR & PCNT_IEN
  128. *****************************************************************************/
  129. typedef enum
  130. {
  131. PcntS1E = 7, // S1通道脉冲解码错误
  132. PcntS0E = 6, // S0通道脉冲解码错误
  133. PcntBB = 5, // 脉冲解码错误
  134. PcntFE = 4, // 采样周期脉冲解码错误
  135. PcntDIR = 3, // 反向改变中断
  136. PcntTO = 2, // 超时中断标识
  137. PcntOV = 1, // 上溢中断标识
  138. PcntUF = 0, // 下溢中断标识
  139. }en_pcnt_itfce_t;
  140. /**
  141. ******************************************************************************
  142. ** \brief PCNT 状态寄存器1 PCNT_SR1
  143. ** \note PCNT_SR1 : DIR
  144. *****************************************************************************/
  145. typedef enum
  146. {
  147. PcntDoubleDirAdd = 0, // 双通道正交脉冲加计数
  148. PcntDoubleDirSub = 1 // 双通道正交脉冲加计数
  149. }en_pcnt_sr1dir_t;
  150. /**
  151. ******************************************************************************
  152. ** \brief PCNT 观测输出选择寄存器 PCNT_DBG
  153. ** \note PCNT_DBG: DBG
  154. *****************************************************************************/
  155. typedef enum
  156. {
  157. PcntDBGZero = 0, // 固定为0
  158. PcntDBGSxA = 1, // 脉冲同步之后通过S0A/S1A输出
  159. PcntDBGSxP = 2, // 脉冲极性选择之后通过S0P/S1P输出
  160. PcntDBGSxPF = 3 // 脉冲滤波之后通过S0PF/S1PF输出
  161. }en_pcnt_dbg_t;
  162. typedef enum
  163. {
  164. PcntDirUp = 0, //加计数
  165. PcntDirDown = 1 //减计数
  166. }en_pent_dir_t;
  167. /**
  168. ******************************************************************************
  169. ** \brief PCNT 整体配置结构体
  170. *****************************************************************************/
  171. typedef struct stc_pcnt_cfg
  172. {
  173. en_pcnt_s0polar_t Pcnt_S0Sel; // S0通道极性选择
  174. en_pcnt_s1polar_t Pcnt_S1Sel; // S1通道极性选择
  175. en_pcnt_clksel_t Pcnt_Clk; // 计数时钟选择
  176. en_pcnt_mode_t Pcnt_Mode; // 脉冲计数模式选择
  177. boolean_t Pcnt_FltEn; // 脉冲宽度滤波器使能控制 PCNT_FLT: EN
  178. uint8_t Pcnt_DebTop; // 计数器阀值 PCNT_FLT: DebTop
  179. uint16_t Pcnt_ClkDiv; // 滤波时钟分频系数 PCNT_FLT: ClkDiv
  180. boolean_t Pcnt_TocrEn; // 超时功能使能控制位 PCNT_TOCR : EN
  181. uint16_t Pcnt_TocrTh; // 超时阈值 PCNT_TOCR : TH
  182. en_pcnt_dbg_t Pcnt_Dbg; // 观测输出选择寄存器 PCNT_DBG
  183. en_pent_dir_t Pcnt_Dir;
  184. }stc_pcnt_initstruct_t;
  185. /******************************************************************************
  186. * Global variable declarations ('extern', definition in C source)
  187. ******************************************************************************/
  188. /******************************************************************************
  189. * Global function prototypes (definition in C source)
  190. ******************************************************************************/
  191. extern boolean_t Pcnt_Cmd(boolean_t NewState);
  192. extern en_result_t Pcnt_SetB2T(uint16_t value);
  193. extern en_result_t Pcnt_SetB2C(uint16_t value);
  194. extern en_result_t Pcnt_SetT2C(void);
  195. extern void Pcnt_Init(stc_pcnt_initstruct_t* InitStruct);
  196. extern void Pcnt_ItCfg(en_pcnt_itfce_t IT_Src, boolean_t NewState);
  197. extern boolean_t Pcnt_GetItStatus(en_pcnt_itfce_t IT_Src);
  198. extern void Pcnt_ClrItStatus(en_pcnt_itfce_t IT_Src);
  199. extern uint16_t Pcnt_GetCnt(void);
  200. extern uint16_t Pcnt_GetTop(void);
  201. extern uint16_t Pcnt_GetBuf(void);
  202. extern void Pcnt_SetCnt(uint16_t value);
  203. extern void Pcnt_SetBuf(uint16_t value);
  204. extern void Pcnt_SetTop(uint16_t value);
  205. //@} // PCNT Group
  206. #ifdef __cplusplus
  207. #endif
  208. #endif /* __PCNT_H__ */
  209. /*******************************************************************************
  210. * EOF (not truncated)
  211. ******************************************************************************/