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
/**
  ******************************************************************************
  * @file     xl_rtc.c
  * @author   Kirk ,xu.wang
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about RTC 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_rtc.h"
    
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup RTC RTC Module 
  * @brief RTC Driver Modules Library
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
    
/** @defgroup RTC_Private_Functions
  * @{
  */ 
 
/**
  * @brief  RTCĬÈϳõʼ»¯
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè
  * @retval None
  */
void RTC_DeInit(RTC_Type *RTCx)
{
    /* Deinitializes to default reset values */
    RTCx->SC = 0x0000;
}
 
/**
  * @brief ³õʼ»¯RTC
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£
  * @param  RTC_InitStruct:RTC_InitTypeDefÀàÐ͵ÄÖ¸Õ룬°üº¬ÁËRTCÍâÉèµÄÉèÖÃÐÅÏ¢
  * @retval None
  */
void RTC_Init(RTC_Type *RTCx, const RTC_InitTypeDef *RTC_InitStruct)
{
    uint32_t tmpreg;
 
    /*---------------------------- RTC SC Configuration ------------------------*/
    /* Get the RTC SC value. */
    tmpreg = RTCx->SC ;
 
    /* Clear bits Value in SC register.*/
    tmpreg &= ~(RTC_SC_RTCLKS_MASK | RTC_SC_RTCPS_MASK);
 
    /* Set the bit RTCLKS,RTCPS in CR Register. */
 
    tmpreg |= (uint32_t)((((uint32_t)(((uint32_t)(RTC_InitStruct->RTC_ClkSrc))<<RTC_SC_RTCLKS_SHIFT))&RTC_SC_RTCLKS_MASK) \
                            |(((uint32_t)(((uint32_t)(RTC_InitStruct->RTC_ClkPres))<<RTC_SC_RTCPS_SHIFT))&RTC_SC_RTCPS_MASK));
 
    /* Write to RTC SC Register. */
    RTCx->SC = tmpreg ;
}
 
/**
  * @brief RTCʹÄÜ
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£
  * @param  NewState: RTCʹÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: RTCʹÄÜ
  *            @arg DISABLE: RTCʧÄÜ
  * @retval None
  */
void RTC_EnableCmd(RTC_Type *RTCx, FunctionalState NewState)
{
    if(NewState == ENABLE)
    {
        RTCx->SC |= RTC_SC_RTCEN_MASK;
    }
    else
    {
        RTCx->SC &= (~RTC_SC_RTCEN_MASK);
    }
}
 
/**
  * @brief RTCÖжÏʹÄÜ
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£
  * @param  NewState: RTCÖжÏʹÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: RTCÖжÏʹÄÜ
  *            @arg DISABLE: RTCÖжÏʧÄÜ
  * @retval None
  */
void RTC_InterruptEn(RTC_Type *RTCx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Real-time interrupt requests are enabled. */
        RTCx->SC |= RTC_SC_RTIE_MASK;
    }
    else 
    {
        /* Real-time interrupt requests are disabled. */
        RTCx->SC &= ~RTC_SC_RTIE_MASK;
    }
}
 
/**
  * @brief RTCʵʱÊä³öʹÄÜ
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè
  * @param  NewState: RTCʵʱÊä³öʹÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: Ê¹ÄÜRTCʵʱÊä³ö
  *            @arg DISABLE: Ê§ÄÜRTCʵʱÊä³ö
  * @retval None
  */
void RTC_CountOutputEn(RTC_Type *RTCx,FunctionalState NewState)
{
    if(NewState != DISABLE )
    {
        /* Real-time counter output enabled. */
        RTCx->SC |= RTC_SC_RTCO_MASK;
    }
    else 
    {
        /* Real-time counter output disabled. */
        RTCx->SC &= ~RTC_SC_RTCO_MASK;
    }
}
 
/**
  * @brief »ñÈ¡RTCʵʱÖжϱê־λ
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£
  * @retval ÊµÊ±Öжϱê־λ
  */
ITStatus RTC_GetInterruptFlag(const RTC_Type *RTCx)
{
    return ((RTCx->SC  & RTC_SC_RTIF_MASK) == RTC_SC_RTIF_MASK);
}
 
/**
  * @brief Çå¿ÕRTCʵʱÖжϱê־λ
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£
  * @retval None
  */
void RTC_ClrInterruptFlag(RTC_Type *RTCx)
{
    /* Writing a logic 1 clears the bit and the real-time interrupt request */
    RTCx->SC |= RTC_SC_RTIF_MASK;
}
 
/**
  * @brief ÉèÖÃRTCÄ£Êý¼Ä´æÆ÷
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè
  * @param  RTC_ModValue: RTCµÄÄ£ÊýÖµ
  * @retval None
  */
void RTC_SetModValue(RTC_Type *RTCx,uint16_t RTC_ModValue)
{
    /* modulo Value of RTC. */
    RTCx->MOD = RTC_ModValue;
}
 
/**
  * @brief »ñµÃRTC¼ÆÊýÆ÷µÄµ±Ç°Öµ
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£
  * @retval None
  */
uint16_t RTC_GetCountValue(const RTC_Type *RTCx)
{
    uint16_t countvalue;
 
    /* the value of the current RTC count. */
    countvalue= (uint16_t)RTCx->CNT ;
 
    return countvalue;
}
 
 
/**
  * @brief RTCʱ¼ä´Á¼ÆÊýÆ÷ʹÄÜ
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè
  * @param  NewState: RTCʱ¼ä´ÁʹÄÜ״̬
  *        Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ:
  *            @arg ENABLE: Ê¹ÄÜRTCʱ¼ä´Á¼ÆÊý
  *            @arg DISABLE: Ê§ÄÜRTCʱ¼ä´Á¼ÆÊý
  * @retval None
  */
void RTC_TimeStampEnableCmd(RTC_Type *RTCx, FunctionalState NewState)
{
    if(NewState == ENABLE)
    {
        RTCx->STAMP_CFG |= RTC_STAMP_CFG_CNTEN_MASK;
    }
    else
    {
        RTCx->STAMP_CFG &= ~RTC_STAMP_CFG_CNTEN_MASK;
    }
}
 
/**
  * @brief »ñÈ¡RTCʱ¼ä´Á¼ÆÊý
  * @param  RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£
  * @retval None
  */
uint64_t RTC_GetStampCountValue(const RTC_Type *RTCx)
{
    uint64_t countvalue;
 
    /* the value of the current RTC count. */
    countvalue= (uint64_t)RTCx->STAMP_CNT ;
 
    return countvalue;
}
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/**
  * @}
  */
 
#ifdef __cplusplus
}
#endif /* __cplusplus */