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