lpt.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /******************************************************************************
  2. * Copyright (C) 2017, 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 lpt.h
  44. **
  45. ** 低功耗定时器数据结构及API声明
  46. **
  47. **
  48. ** History:
  49. ** - 2018-04-15 Husj First version
  50. **
  51. *****************************************************************************/
  52. #ifndef __LPT_H__
  53. #define __LPT_H__
  54. /*****************************************************************************
  55. * Include files
  56. *****************************************************************************/
  57. #include "ddl.h"
  58. #include "interrupts_hc32l136.h"
  59. #ifdef __cplusplus
  60. extern "C"
  61. {
  62. #endif
  63. /**
  64. *******************************************************************************
  65. ** \defgroup LptGroup Low Power Timer (LPT)
  66. **
  67. **
  68. ******************************************************************************/
  69. //@{
  70. /******************************************************************************/
  71. /* Global pre-processor symbols/macros ('#define') */
  72. /******************************************************************************/
  73. /******************************************************************************
  74. * Global type definitions
  75. ******************************************************************************/
  76. /**
  77. ******************************************************************************
  78. ** \brief GATE 极性控制数据类型重定义 (GATE_P)
  79. *****************************************************************************/
  80. typedef enum en_lpt_gatep
  81. {
  82. LptActHighLevel = 0u, ///< 高电平有效
  83. LptActLowLevel = 1u, ///< 低电平有效
  84. }en_lpt_gatep_t;
  85. /**
  86. ******************************************************************************
  87. ** \brief 定时器门控数据类型重定义 (GATE)
  88. *****************************************************************************/
  89. typedef enum en_lpt_gate
  90. {
  91. LptGateDisable = 0u, ///< 无门控
  92. LptGateEnable = 1u, ///< 门控使能
  93. }en_lpt_gate_t;
  94. /**
  95. ******************************************************************************
  96. ** \brief Lptimer 时钟选择数据类型重定义 (TCK_SEL)
  97. *****************************************************************************/
  98. typedef enum en_lpt_clksel
  99. {
  100. LptPCLK = 0u, ///< PCLK
  101. LptXIL32K = 2u, ///< XIL32K
  102. LptIRC32K = 3u, ///< IRC32K
  103. }en_lpt_clksel_t;
  104. /**
  105. ******************************************************************************
  106. ** \brief 翻转输出使能数据类型重定义 (TOG_EN)
  107. *****************************************************************************/
  108. typedef enum en_lpt_toggle
  109. {
  110. LptTogDisable = 0u, ///< 翻转输出禁止
  111. LptTogEnable = 1u, ///< 翻转输出使能
  112. }en_lpt_toggle_t;
  113. /**
  114. ******************************************************************************
  115. ** \brief 计数/定时器功能选择数据类型重定义 (CT)
  116. *****************************************************************************/
  117. typedef enum en_lpt_function
  118. {
  119. LptTimer = 0u, ///< 定时器功能
  120. LptCounter = 1u, ///< 计数器功能
  121. }en_lpt_function_t;
  122. /**
  123. ******************************************************************************
  124. ** \brief 定时器工作模式数据类型重定义 (MD)
  125. *****************************************************************************/
  126. typedef enum en_lpt_mode
  127. {
  128. Lpt16bitFreeMode = 0u, ///< 无重载16位计数器/定时器
  129. Lpt16bitArrMode = 1u, ///< 自动重装载16位计数器/定时器
  130. }en_lpt_mode_t;
  131. /**
  132. ******************************************************************************
  133. ** \brief 定时器运行控制数据类型重定义 (TR)
  134. *****************************************************************************/
  135. typedef enum en_lpt_start
  136. {
  137. LptTRDisable = 0u, ///< 停止
  138. LptTREnable = 1u, ///< 运行
  139. }en_lpt_start_t;
  140. /**
  141. ******************************************************************************
  142. ** \brief Lptimer 配置结构体定义
  143. *****************************************************************************/
  144. typedef struct stc_lpt_config
  145. {
  146. en_lpt_gatep_t enGateP; ///< 门控极性控制
  147. en_lpt_gate_t enGate; ///< 门控使能
  148. en_lpt_clksel_t enTckSel; ///< 时钟选择
  149. en_lpt_toggle_t enTog; ///< 翻转输出使能
  150. en_lpt_function_t enCT; ///< 定时/计数模式选择
  151. en_lpt_mode_t enMD; ///< 工作模式选择
  152. func_ptr_t pfnLpTimCb; ///< LpTimer中断服务回调函数[void function(void)]
  153. }stc_lpt_config_t;
  154. /******************************************************************************
  155. * Global variable declarations ('extern', definition in C source)
  156. *****************************************************************************/
  157. /******************************************************************************
  158. * Global function prototypes (definition in C source)
  159. *****************************************************************************/
  160. //中断相关函数
  161. //中断标志获取
  162. boolean_t Lpt_GetIntFlag(void);
  163. //中断标志清除
  164. en_result_t Lpt_ClearIntFlag(void);
  165. //中断使能/禁止
  166. en_result_t Lpt_EnableIrq (void);
  167. en_result_t Lpt_DisableIrq(void);
  168. //初始化及相关功能操作
  169. //Lptimer配置及初始化
  170. en_result_t Lpt_Init(stc_lpt_config_t* pstcConfig);
  171. //Lptimer 启动/停止
  172. en_result_t Lpt_Run(void);
  173. en_result_t Lpt_Stop(void);
  174. //重载值设置
  175. en_result_t Lpt_ARRSet(uint16_t u16Data);
  176. //计数值获取
  177. en_result_t Lpt_Cnt16Set(uint16_t u16Data);
  178. uint16_t Lpt_Cnt16Get(void);
  179. //@} // LptGroup
  180. #ifdef __cplusplus
  181. #endif
  182. #endif /* __LPT_H__ */
  183. /******************************************************************************
  184. * EOF (not truncated)
  185. *****************************************************************************/