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
|
/**
**************************************************************************
* @file at32f413_rtc.c
* @version v2.0.5
* @date 2022-05-20
* @brief contains all the functions for the rtc firmware library
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
#include "at32f413_conf.h"
/** @addtogroup AT32F413_periph_driver
* @{
*/
/** @defgroup RTC
* @brief RTC driver modules
* @{
*/
#ifdef RTC_MODULE_ENABLED
/** @defgroup RTC_private_functions
* @{
*/
/**
* @brief rtc counter set
* @param counter_value (0x0000_0000 ~ 0xFFFF_FFFF)
* @retval none
*/
void rtc_counter_set(uint32_t counter_value)
{
/* enter rtc config mode */
RTC->ctrll = 0x003F;
/* set rtc counter */
RTC->cnth_bit.cnt = (uint16_t)(counter_value >> 16);
RTC->cntl_bit.cnt = (uint16_t)(counter_value & 0x0000FFFF);
/* exit rtc config mode */
RTC->ctrll = 0x000F;
}
/**
* @brief rtc counter get
* @param none
* @retval rtc counter
*/
uint32_t rtc_counter_get(void)
{
uint32_t cnt = 0;
cnt = RTC->cnth;
cnt = (cnt << 16) | RTC->cntl;
return cnt;
}
/**
* @brief rtc divider set
* @param div_value (0x0000_0000 ~ 0xFFFF_FFFF)
* @retval none
*/
void rtc_divider_set(uint32_t div_value)
{
/* enter rtc config mode */
RTC->ctrll = 0x003F;
/* set rtc divider */
RTC->divh_bit.div = (uint16_t)(div_value >> 16);
RTC->divl_bit.div = (uint16_t)(div_value & 0x0000FFFF);
/* exit rtc config mode */
RTC->ctrll = 0x000F;
}
/**
* @brief rtc divider get
* @param none
* @retval rtc counter
*/
uint32_t rtc_divider_get(void)
{
uint32_t div = 0;
div = RTC->divcnth;
div = (div << 16) | RTC->divcntl;
return div;
}
/**
* @brief rtc alarm value set
* @param alarm_value (0x0000_0000 ~ 0xFFFF_FFFF)
* @retval none
*/
void rtc_alarm_set(uint32_t alarm_value)
{
/* enter rtc config mode */
RTC->ctrll = 0x003F;
/* set rtc alarm value */
RTC->tah_bit.ta = (uint16_t)(alarm_value >> 16);
RTC->tal_bit.ta = (uint16_t)(alarm_value & 0x0000FFFF);
/* exit rtc config mode */
RTC->ctrll = 0x000F;
}
/**
* @brief rtc interrupt enable
* @param source
* this parameter can be any combination of the following values:
* - RTC_TS_INT: time second interrupt.
* - RTC_TA_INT: time alarm interrupt.
* - RTC_OVF_INT: overflow interrupt.
* @param new_state (TRUE or FALSE)
* @retval none
*/
void rtc_interrupt_enable(uint16_t source, confirm_state new_state)
{
if(new_state == FALSE)
{
RTC->ctrlh &= ~source;
}
else
{
RTC->ctrlh |= source;
}
}
/**
* @brief rtc flag get
* @param flag
* this parameter can be one of the following values:
* - RTC_TS_FLAG: time second flag.
* - RTC_TA_FLAG: time alarm flag.
* - RTC_OVF_FLAG: overflow flag.
* - RTC_UPDF_FLAG: rtc update finish flag.
* - RTC_CFGF_FLAG: rtc configuration finish flag.
* @retval state of rtc flag
*/
flag_status rtc_flag_get(uint16_t flag)
{
flag_status status = RESET;
if ((RTC->ctrll & flag) != (uint16_t)RESET)
{
status = SET;
}
else
{
status = RESET;
}
return status;
}
/**
* @brief rtc flag clear
* @param interrupt_flag
* this parameter can be any combination of the following values:
* - RTC_TS_FLAG: time second flag.
* - RTC_TA_FLAG: time alarm flag.
* - RTC_OVF_FLAG: overflow flag.
* - RTC_CFGF_FLAG: rtc configuration finish flag.
* @retval none
*/
void rtc_flag_clear(uint16_t flag)
{
RTC->ctrll = ~(flag | 0x10) | (RTC->ctrll_bit.cfgen << 4);
}
/**
* @brief rtc wait configuration finish
* @param none
* @retval none
*/
void rtc_wait_config_finish(void)
{
while (RTC->ctrll_bit.cfgf == 0);
}
/**
* @brief rtc wait update finish
* @param none
* @retval none
*/
void rtc_wait_update_finish(void)
{
while (RTC->ctrll_bit.updf == 0);
}
/**
* @}
*/
#endif
/**
* @}
*/
/**
* @}
*/
|