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
/**
  ******************************************************************************
  * @file     xl_pit.c
  * @author   Kirk ,xu.wang
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about PIT 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_pit.h"
 
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup PIT PIT Module 
  * @brief PIT Driver Modules Library
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/    
    #define PIT_CLEAR_MASK     ((uint8_t)0x02)    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
 
/** @defgroup PIT_Private_Functions
  * @{
  */ 
    
/**
  * @brief  PITĬÈϳõʼ»¯
  * @param  None
  * @retval None
  */
void PIT_DeInit(void)
{
    /* Deinitializes to default reset values */
    PIT->CHANNEL[0].CTR = 0x00;
    PIT->CHANNEL[1].CTR = 0x00;
    PIT->CHAIN=0x00;    
}
 
/**
  * @brief PTT³õʼ»¯
  * @param  Channel: PITͨµÀºÅ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *        @arg PIT_Channel0: PITͨµÀ0
  *        @arg PIT_Channel1: PITͨµÀ1
  * @param  PIT_Mode: Ä£Ê½Ñ¡Ôñ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *        @arg PIT_Run_Mode: ×ÔÓÉÔËÐÐģʽ
  *        @arg PIT_Count_Mode: Óû§¶¨Ò弯Êýģʽ
  * @param  CLK_DIV: Ê±ÖÓ·ÖÆµ(0~65535)
  * @retval None
  */
void PIT_Init(uint8_t Channel,uint8_t PIT_Mode,uint16_t CLK_DIV)
{
    uint32_t tmpreg;
 
    /*---------------------------- PIT CTR Configuration ------------------------*/    
    /* Get the PIT CTR value. */
    tmpreg = PIT->CHANNEL[Channel].CTR ;
 
    /* Clear MODE bit Value in CTR register.*/
    tmpreg &= ~PIT_CLEAR_MASK;
 
    /* Set the bit MODE in CTR Register. */
    tmpreg |= (PIT_Mode);
 
    //Aaron He add clock divider
    PIT->PIT_DIV[Channel] = CLK_DIV;
 
    /* Write to PIT CTR Register. */
    PIT->CHANNEL[Channel].CTR = tmpreg ;
}
 
/**
  * @brief PITʹÄÜ
  * @param  Channel: PITͨµÀºÅ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *        @arg PIT_Channel0: PITͨµÀ0
  *        @arg PIT_Channel1: PITͨµÀ1
  * @param  NewState: Ê¹ÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: PITʹÄÜ
  *            @arg DISABLE: PITʧÄÜ
  * @retval None.
  */
void PIT_EnableCmd(uint8_t Channel,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Enable PIT bits for PIT. */
        PIT->CHANNEL[Channel].CTR |= PIT_CTR_EN_MASK;
    }
    else 
    {
        /* Disable PIT bits for PIT. */
        PIT->CHANNEL[Channel].CTR &= ~PIT_CTR_EN_MASK;
    }
}
 
/**
  * @brief PITÖжÏʹÄÜ
  * @param  Channel: PITͨµÀºÅ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *        @arg PIT_Channel0: PITͨµÀ0
  *        @arg PIT_Channel1: PITͨµÀ1
  * @param  NewState: Ê¹ÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: PITʹÄÜ
  *            @arg DISABLE: PITʧÄÜ
  * @retval None.
  */
void PIT_InterruptEn(uint8_t Channel,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* ENABLE PIT interrupt for PIT. */
        PIT->CHANNEL[Channel].CTR &= ~PIT_CTR_IM_MASK;            
    }
    else
    {
        /* DISABLE PIT interrupt for PIT. */
        PIT->CHANNEL[Channel].CTR |= PIT_CTR_IM_MASK;
    }
}
 
/**
  * @brief ÎªPITÉèÖÃÐŵÀÄ£Öµ.
  * @param  Channel: PITͨµÀºÅ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *        @arg PIT_Channel0: PITͨµÀ0
  *        @arg PIT_Channel1: PITͨµÀ1
  * @param  loadVal: ±»¼ÓÔØµ½PITÖеÄÖµ.
  * @retval None.
  */
void PIT_SetLoadCount(uint8_t Channel,uint32_t loadVal)
{
    /* Value to be load into PIT. */
    PIT->CHANNEL[Channel].LC = loadVal ;
}
 
/**
  * @brief µÃµ½PITµÄͨµÀµçÁ÷Öµ.
  * @param  Channel: PITͨµÀºÅ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *        @arg PIT_Channel0: PITͨµÀ0
  *        @arg PIT_Channel1: PITͨµÀ1
  * @retval current Value.·µ»ØµçÁ÷Öµ.
  */
uint32_t PIT_GetCurrentVal(uint8_t Channel)
{
    uint32_t currentVal;
    
    /* get the current Value. */
    currentVal = PIT->CHANNEL[Channel].CV ;
 
    /* return the value. */
    return currentVal ;
}
 
/**
  * @brief Çå³ýPITÖжÏ.
  * @param  Channel: PITͨµÀºÅ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *        @arg PIT_Channel0: PITͨµÀ0
  *        @arg PIT_Channel1: PITͨµÀ1
  * @retval None.
  */
void PIT_ClrInterrupt(uint8_t Channel)
{
    /* clear the interrupt from PIT.*/
    PIT->CHANNEL[Channel].EOI;
}
 
/**
  * @brief ·µ»ØPITµÄÖжÏ״̬.
  * @param  Channel: PITͨµÀºÅ
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *        @arg PIT_Channel0: PITͨµÀ0
  *        @arg PIT_Channel1: PITͨµÀ1
  * @retval interrupt status.·µ»ØÖжÏ״̬.
  */
ITStatus PIT_GetIntStatus(uint8_t Channel)
{
    /* return interrupt status. */
    return ((PIT->CHANNEL[Channel].IS & PIT_IS_IS_MASK) == PIT_IS_IS_MASK);
}
 
/**
  * @brief »ñÈ¡PITµÄÖжÏ״̬.
  * @retval ÖжÏ״̬
  */
uint8_t PIT_GetAllIntStatus(void)
{
    /* return all interrupt status. */
    return (uint8_t)(PIT->AIS & PIT_AIS_AIS_MASK);
}
 
/**
  * @brief Çå³ýËùÓлÖеÄÖжÏ.
  * @param  None
  * @retval None.
  */
void PIT_ClrAllInterrupt(void)
{
    /* Dummy reading the register and clear all active interrupts. */
    (void)(PIT->AEOI);
}
 
/**
  * @brief »ñÈ¡ÎÞÆÁ±ÎÖжÏ״̬.
  * @param  None
  * @retval ·µ»ØÎÞÆÁ±ÎÖжÏ״̬
  */
uint8_t PIT_GetRawIntStatus(void)
{
    /* return unmasked interrupt status. */
    return (uint8_t)(PIT->RAWIS & PIT_RAWIS_RAWIS_MASK);
}
 
 
/**
  * @brief PIT ¶³½áģʽÆôÓûò½ûÓÃ.
  * @param  NewState: Ê¹ÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: ¶³½áģʽʹÄÜ
  *            @arg DISABLE: ¶³½áģʽʧÄÜ
  * @retval None.
  */
void PIT_FreezeCmd(FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Timers are stopped in debug mode . */
        PIT->CHAIN |= PIT_DEBUG_FRZ_MASK;            
    }
    else
    {
        /* Timers continue to run in debug mode . */
        PIT->CHAIN &= ~PIT_DEBUG_FRZ_MASK;
    }
}
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/**
  * @}
  */
 
#ifdef __cplusplus
}
#endif /* __cplusplus */