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 lptim.h
44  **
45  **
46  **
47  **
48  ** History:
49  **   - 2019-04-09        First version
50  **
51  *****************************************************************************/
52 #ifndef __LPTIM_H__
53 #define __LPTIM_H__
54 
55 /*****************************************************************************
56  * Include files
57  *****************************************************************************/
58 #include "ddl.h"
59 
60 #ifdef __cplusplus
61 extern "C"
62 {
63 #endif
64 
65 /**
66  *******************************************************************************
67  ** \brief LPTIMx  预除频
68  ** \note  LPTIMx_CR  PRS     在定时器运行时不可以更改该值
69  ******************************************************************************/
70 typedef enum
71 {
72     LptimPrsDiv1   = 0,       // 1分频
73     LptimPrsDiv2   = 1,       // 2分频
74     LptimPrsDiv4   = 2,       // 4分频
75     LptimPrsDiv8   = 3,       // 8分频
76     LptimPrsDiv16  = 4,       // 16分频
77     LptimPrsDiv32  = 5,       // 32分频
78     LptimPrsDiv64  = 6,       // 64分频
79     LptimPrsDiv256 = 7        // 256分频
80 }en_lptim_prs_t;
81 
82 /**
83  *******************************************************************************
84  ** \brief LPTIMx  时钟选择
85  ** \note  LPTIMx_CR  TCK_SEL
86  ******************************************************************************/
87 typedef enum
88 {
89     LptimPclk   = 0,
90     LptimXtl    = 2,
91     LptimRcl    = 3
92 }en_lptim_tcksel_t;
93 
94 /**
95  *******************************************************************************
96  ** \brief LPTIMx  GATE极性控制位
97  ** \note  LPTIMx_CR  GATE_P
98  ******************************************************************************/
99 typedef enum
100 {
101     LptimGatePLow  = 0,
102     LptimGatePHigh = 1
103 }en_lptim_gatep_t;
104 
105 /**
106  *******************************************************************************
107  ** \brief LPTIMx  时钟选择
108  ** \note  LPTIMx_CR  GATE
109  ******************************************************************************/
110 typedef enum
111 {
112     LptimGateLow  = 0,
113     LptimGateHigh = 1
114 }en_lptim_gate_t;
115 
116 /**
117  *******************************************************************************
118  ** \brief LPTIMx  TOG输出使能位
119  ** \note  LPTIMx_CR  TOG
120  ******************************************************************************/
121 typedef enum
122 {
123     LptimTogEnLow  = 0,
124     LptimTogEnHigh = 1
125 }en_lptim_togen_t;
126 
127 /**
128  *******************************************************************************
129  ** \brief LPTIMx  CT计数器/定时器功能选择
130  ** \note  LPTIMx_CR  CT
131  ******************************************************************************/
132 typedef enum
133 {
134     LptimTimerFun = 0,  //警示器功能,定时器使用TCK_SEL选择的时钟进行计数
135     LptimCntFun   = 1   //计数器功能,计数器使用外部输入的下降沿进行计数,采样时钟使用TCK_SEL选择的时钟
136 }en_lptim_ct_t;
137 
138 /**
139  *******************************************************************************
140  ** \brief LPTIMx  定时器工作模式
141  ** \note  LPTIMx_CR  MD
142  ******************************************************************************/
143 typedef enum
144 {
145     LptimMode1 = 0,  //模式1无重载16位计数器/定时器
146     LptimMode2 = 1   //模式2自动重载16位计数器/定时器
147 }en_lptim_md_t;
148 
149 /**
150  *******************************************************************************
151  ** \brief LPTIMx 初始化配置的结构体
152  ** \note
153  ******************************************************************************/
154 typedef struct
155 {
156     en_lptim_prs_t       enPrs;
157     en_lptim_tcksel_t    enTcksel;
158     en_lptim_gatep_t     enGatep;
159     en_lptim_gate_t      enGate;
160     en_lptim_togen_t     enTogen;
161     en_lptim_ct_t        enCt;
162     en_lptim_md_t        enMd;
163     uint16_t             u16Arr;
164 }stc_lptim_cfg_t;
165 
166 /******************************************************************************
167  * Global variable declarations ('extern', definition in C source)
168  *****************************************************************************/
169 
170 /******************************************************************************
171  * Global function prototypes (definition in C source)
172  *****************************************************************************/
173 extern void Lptim_ConfIt(M0P_LPTIMER_TypeDef* Lptimx, boolean_t NewStatus);
174 extern void Lptim_Cmd(M0P_LPTIMER_TypeDef* Lptimx, boolean_t NewStatus);
175 extern boolean_t Lptim_GetItStatus(M0P_LPTIMER_TypeDef* Lptimx);
176 extern void Lptim_ClrItStatus(M0P_LPTIMER_TypeDef* Lptimx);
177 extern en_result_t Lptim_Init(M0P_LPTIMER_TypeDef* Lptimx, stc_lptim_cfg_t* InitStruct);
178 
179 #ifdef __cplusplus
180 #endif
181 
182 #endif //__LPTIM_H__
183 /******************************************************************************
184  * EOF (not truncated)
185  *****************************************************************************/
186