tao_z
2022-05-25 1044ba0d2286698d0da28112bffc0f114bef2134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/**
  ******************************************************************************
  * @file     xl_pwt.c
  * @author   xu.wang
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about PWT firmware program 
  ******************************************************************************
  * @attention
    *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
 
 
/* Includes ---------------------------------------------------------------*/
#include "xl_pwt.h"
    
 
 
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup PWT PWT Module 
  * @brief PWT Driver Modules Library
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
/** @defgroup PWT_Private_Functions 
  * @{
  */ 
 
/**
  * @brief  PWTĬÈϳõʼ»¯
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
  * @retval None
  */ 
void PWT_DeInit(PWT_Type *PWTx)
{
    /* Deinitializes to default reset values */
    PWTx->R1 = 0x00000000;
}
 
/**
  * @brief  PWT³õʼ»¯
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
  * @param  PWT_InitStruct: PWT_InitTypeDefÀàÐ͵ÄÖ¸Õ룬°üº¬ÁËPWTÍâÉèµÄÉèÖÃÐÅÏ¢¡£
  * @retval None
  */
void PWT_Init(PWT_Type *PWTx,const PWT_InitTypeDef *PWT_InitStruct)
{
    uint32_t tmpreg;
 
/*---------------------------- PWT R1 Configuration ------------------------*/
    /* Get the PWT R1 value */
    tmpreg = PWTx->R1 ;
 
    /* Clear PCLKS,PINSEL,EDGE,PRE bits */
    tmpreg &= ~(PWT_R1_PCLKS_MASK | PWT_R1_PINSEL_MASK |PWT_R1_EDGE_MASK | PWT_R1_PRE_MASK);
 
    /* Set PCLKS,PINSEL,EDGE,PRE bits */
    tmpreg |= (PWT_InitStruct->PWT_ClkSource | PWT_InitStruct->PWT_PulseInputSelect | \
                         PWT_InitStruct->PWT_EdgeSensitivity | PWT_InitStruct->PWT_ClkPrescaler);    
    
    /* Write to PWT R1 */
    PWTx->R1 = tmpreg ;
}
 
/**
 * @brief  PWTʹÄÜ
 * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè¡£
 * @param  NewState: 
 *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
 *            @arg ENABLE: PWTʹÄÜ
 *            @arg DISABLE: PWTʧÄÜ
 * @retval None
 */
void PWT_EnableCmd(PWT_Type *PWTx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enable the PWT */
        PWTx->R1 |= PWT_R1_PWTEN_MASK;
    }
    else 
    {
        /* Disable the PWT */
        PWTx->R1 &= ~PWT_R1_PWTEN_MASK;
    }
}
 
/**
  * @brief  PWTÖжÏʹÄÜ
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
  * @param  NewState: PWTÖжÏʹÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: PWTÖжÏʹÄÜ
  *            @arg DISABLE: PWTÖжÏʧÄÜ
  * @retval None
  */
void PWT_InterruptEn(PWT_Type *PWTx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enables the PWT module to generate an interrupt */
        PWTx->R1 |= PWT_R1_PWTIE_MASK;
    }
    else 
    {
        /* Disable the PWT module to generate an interrupt */
        PWTx->R1 &= ~PWT_R1_PWTIE_MASK;
    }
}
 
/**
  * @brief PWTÂö¿íÊý¾Ý¾ÍÐ÷ÖжÏʹÄÜ
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
  * @param  NewState: PWTÂö¿íÊý¾Ý¾ÍÐ÷ÖжÏʹÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: PWTÂö¿íÊý¾Ý¾ÍÐ÷ÖжÏʹÄÜ
  *            @arg DISABLE: PWTÂö¿íÊý¾Ý¾ÍÐ÷ÖжÏʧÄÜ
  * @retval None
  */
void PWT_PWTRDYIntCmd(PWT_Type *PWTx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enables the data ready interrupt. */
        PWTx->R1 |= PWT_R1_PRDYIE_MASK;
    }
    else 
    {
        /* Disable the data ready interrupt. */
        PWTx->R1 &= ~PWT_R1_PRDYIE_MASK;
    }
}
 
/**
  * @brief PWTÒç³öÖжÏʹÄÜ
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
  * @param  NewState: PWTÒç³öÖжÏʹÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: PWTÒç³öÖжÏʹÄÜ
  *            @arg DISABLE: PWTÒç³öÖжÏʧÄÜ
  * @retval None
  */
void PWT_OverflowIntCmd(PWT_Type *PWTx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enables the counter overflow interrupt. */
        PWTx->R1 |= PWT_R1_POVIE_MASK;
    }
    else 
    {
        /* Disable the counter overflow interrupt. */
        PWTx->R1 &= ~PWT_R1_POVIE_MASK;
    }
}
 
/**
  * @brief PWTÈí¼þ¸´Î»
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
  * @retval None
  */
void PWT_SetSoftReset(PWT_Type *PWTx)
{
    /* Performs a soft reset to the PWT. This field always reads as 0. */
    PWTx->R1 |= PWT_R1_PWTSR_MASK;
}
 
/**
 * @brief »ñÈ¡PWTÒç³ö±êÖ¾
 * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
 * @retval ·µ»ØÒç³ö±êÖ¾
 */
FlagStatus PWT_GetOverflowFlag(const PWT_Type *PWTx)
{
    return ((PWTx->R1 & PWT_R1_PWTOV_MASK) == PWT_R1_PWTOV_MASK);
}
 
/**
  * @brief Çå¿ÕPWTÒç³ö±ê־λ
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
  * @retval ·µ»ØÒç³ö±êÖ¾
  */
void PWT_ClrOverflowFlag(PWT_Type *PWTx)
{
    if((PWTx->R1 & PWT_R1_PWTOV_MASK) == PWT_R1_PWTOV_MASK)
    {
        PWTx->R1 &= ~PWT_R1_PWTOV_MASK;
    }
}
 
/**
  * @brief »ñÈ¡PWTÂö¿íÊÇ·ñÓÐЧ±êÖ¾
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
  * @retval ·µ»ØÒç³ö±êÖ¾
  */
FlagStatus PWT_GetPWTRDY(const PWT_Type *PWTx)
{
    return ((PWTx->R1 & PWT_R1_PWTRDY_MASK) == PWT_R1_PWTRDY_MASK);
}
 
/**
  * @brief Çå¿ÕPWTÂö¿íÓÐЧ±êÖ¾
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè
  * @retval ·µ»ØÒç³ö±êÖ¾
  */
void PWT_ClrPWTRDYFlag(PWT_Type *PWTx)
{
    /* Dummy read while CHF is set */
    if((PWTx->R1 & PWT_R1_PWTRDY_MASK) == PWT_R1_PWTRDY_MASK)
    {
        PWTx->R1 &= ~PWT_R1_PWTRDY_MASK;
    }
}
 
/**
  * @brief  »ñÈ¡PWTµÄÕýÂö³å¿í¶È
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè¡£
  * @retval ·µ»ØPWTµÄÕýÂö³å¿í¶È
  */
uint16_t PWT_GetPPW(const PWT_Type *PWTx)
{
    uint16_t  PPWVal;
    PPWVal = (uint16_t )((PWTx->R1 & PWT_R1_PPW_MASK) >> 16); 
    return PPWVal ;
}
 
/**
  * @brief »ñÈ¡PWTµÄ¸ºÂö³å¿í¶È
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè¡£
  * @retval ·µ»ØPWTµÄ¸ºÂö³å¿í¶È
  */
uint16_t PWT_GetNPW(const PWT_Type *PWTx)
{
    uint16_t NPWVal;
    NPWVal = (uint16_t )(PWTx->R2 & PWT_R2_NPW_MASK);
    return NPWVal ;
}
 
/**
  * @brief »ñµÃPWT¼ÆÊýÆ÷µÄÖµ
  * @param  PWTx: ÊäÈë¿ÉÓõÄPWTÍâÉè¡£
  * @retval ·µ»ØPWT¼ÆÊýÆ÷µÄÖµ
  */
uint16_t PWT_GetPWTCounter(const PWT_Type *PWTx)
{
    uint16_t PWTCounter;
    PWTCounter = (uint16_t )((PWTx->R2 & PWT_R2_PWTC_MASK) >> 16);
    return PWTCounter ;
}
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/**
  * @}
  */
 
#ifdef __cplusplus
}
#endif /* __cplusplus */