1 /*! 2 \file gd32f4xx_rtc.c 3 \brief definitions for the RTC 4 5 \version 2016-08-15, V1.0.0, firmware for GD32F4xx 6 \version 2018-12-12, V2.0.0, firmware for GD32F4xx 7 \version 2020-09-30, V2.1.0, firmware for GD32F4xx 8 \version 2022-03-09, V3.0.0, firmware for GD32F4xx 9 */ 10 11 /* 12 Copyright (c) 2022, GigaDevice Semiconductor Inc. 13 14 Redistribution and use in source and binary forms, with or without modification, 15 are permitted provided that the following conditions are met: 16 17 1. Redistributions of source code must retain the above copyright notice, this 18 list of conditions and the following disclaimer. 19 2. Redistributions in binary form must reproduce the above copyright notice, 20 this list of conditions and the following disclaimer in the documentation 21 and/or other materials provided with the distribution. 22 3. Neither the name of the copyright holder nor the names of its contributors 23 may be used to endorse or promote products derived from this software without 24 specific prior written permission. 25 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 30 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 33 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 35 OF SUCH DAMAGE. 36 */ 37 38 39 #ifndef GD32F4XX_RTC_H 40 #define GD32F4XX_RTC_H 41 42 #include "gd32f4xx.h" 43 44 /* RTC definitions */ 45 #define RTC RTC_BASE 46 47 /* registers definitions */ 48 #define RTC_TIME REG32((RTC) + 0x00U) /*!< RTC time of day register */ 49 #define RTC_DATE REG32((RTC) + 0x04U) /*!< RTC date register */ 50 #define RTC_CTL REG32((RTC) + 0x08U) /*!< RTC control register */ 51 #define RTC_STAT REG32((RTC) + 0x0CU) /*!< RTC status register */ 52 #define RTC_PSC REG32((RTC) + 0x10U) /*!< RTC time prescaler register */ 53 #define RTC_WUT REG32((RTC) + 0x14U) /*!< RTC wakeup timer regiser */ 54 #define RTC_COSC REG32((RTC) + 0x18U) /*!< RTC coarse calibration register */ 55 #define RTC_ALRM0TD REG32((RTC) + 0x1CU) /*!< RTC alarm 0 time and date register */ 56 #define RTC_ALRM1TD REG32((RTC) + 0x20U) /*!< RTC alarm 1 time and date register */ 57 #define RTC_WPK REG32((RTC) + 0x24U) /*!< RTC write protection key register */ 58 #define RTC_SS REG32((RTC) + 0x28U) /*!< RTC sub second register */ 59 #define RTC_SHIFTCTL REG32((RTC) + 0x2CU) /*!< RTC shift function control register */ 60 #define RTC_TTS REG32((RTC) + 0x30U) /*!< RTC time of timestamp register */ 61 #define RTC_DTS REG32((RTC) + 0x34U) /*!< RTC date of timestamp register */ 62 #define RTC_SSTS REG32((RTC) + 0x38U) /*!< RTC sub second of timestamp register */ 63 #define RTC_HRFC REG32((RTC) + 0x3CU) /*!< RTC high resolution frequency compensation registor */ 64 #define RTC_TAMP REG32((RTC) + 0x40U) /*!< RTC tamper register */ 65 #define RTC_ALRM0SS REG32((RTC) + 0x44U) /*!< RTC alarm 0 sub second register */ 66 #define RTC_ALRM1SS REG32((RTC) + 0x48U) /*!< RTC alarm 1 sub second register */ 67 #define RTC_BKP0 REG32((RTC) + 0x50U) /*!< RTC backup register */ 68 #define RTC_BKP1 REG32((RTC) + 0x54U) /*!< RTC backup register */ 69 #define RTC_BKP2 REG32((RTC) + 0x58U) /*!< RTC backup register */ 70 #define RTC_BKP3 REG32((RTC) + 0x5CU) /*!< RTC backup register */ 71 #define RTC_BKP4 REG32((RTC) + 0x60U) /*!< RTC backup register */ 72 #define RTC_BKP5 REG32((RTC) + 0x64U) /*!< RTC backup register */ 73 #define RTC_BKP6 REG32((RTC) + 0x68U) /*!< RTC backup register */ 74 #define RTC_BKP7 REG32((RTC) + 0x6CU) /*!< RTC backup register */ 75 #define RTC_BKP8 REG32((RTC) + 0x70U) /*!< RTC backup register */ 76 #define RTC_BKP9 REG32((RTC) + 0x74U) /*!< RTC backup register */ 77 #define RTC_BKP10 REG32((RTC) + 0x78U) /*!< RTC backup register */ 78 #define RTC_BKP11 REG32((RTC) + 0x7CU) /*!< RTC backup register */ 79 #define RTC_BKP12 REG32((RTC) + 0x80U) /*!< RTC backup register */ 80 #define RTC_BKP13 REG32((RTC) + 0x84U) /*!< RTC backup register */ 81 #define RTC_BKP14 REG32((RTC) + 0x88U) /*!< RTC backup register */ 82 #define RTC_BKP15 REG32((RTC) + 0x8CU) /*!< RTC backup register */ 83 #define RTC_BKP16 REG32((RTC) + 0x90U) /*!< RTC backup register */ 84 #define RTC_BKP17 REG32((RTC) + 0x94U) /*!< RTC backup register */ 85 #define RTC_BKP18 REG32((RTC) + 0x98U) /*!< RTC backup register */ 86 #define RTC_BKP19 REG32((RTC) + 0x9CU) /*!< RTC backup register */ 87 88 /* bits definitions */ 89 /* RTC_TIME */ 90 #define RTC_TIME_SCU BITS(0,3) /*!< second units in BCD code */ 91 #define RTC_TIME_SCT BITS(4,6) /*!< second tens in BCD code */ 92 #define RTC_TIME_MNU BITS(8,11) /*!< minute units in BCD code */ 93 #define RTC_TIME_MNT BITS(12,14) /*!< minute tens in BCD code */ 94 #define RTC_TIME_HRU BITS(16,19) /*!< hour units in BCD code */ 95 #define RTC_TIME_HRT BITS(20,21) /*!< hour tens in BCD code */ 96 #define RTC_TIME_PM BIT(22) /*!< AM/PM notation */ 97 98 /* RTC_DATE */ 99 #define RTC_DATE_DAYU BITS(0,3) /*!< date units in BCD code */ 100 #define RTC_DATE_DAYT BITS(4,5) /*!< date tens in BCD code */ 101 #define RTC_DATE_MONU BITS(8,11) /*!< month units in BCD code */ 102 #define RTC_DATE_MONT BIT(12) /*!< month tens in BCD code */ 103 #define RTC_DATE_DOW BITS(13,15) /*!< day of week units */ 104 #define RTC_DATE_YRU BITS(16,19) /*!< year units in BCD code */ 105 #define RTC_DATE_YRT BITS(20,23) /*!< year tens in BCD code */ 106 107 /* RTC_CTL */ 108 #define RTC_CTL_WTCS BITS(0,2) /*!< auto wakeup timer clock selection */ 109 #define RTC_CTL_TSEG BIT(3) /*!< valid event edge of time-stamp */ 110 #define RTC_CTL_REFEN BIT(4) /*!< reference clock detection function enable */ 111 #define RTC_CTL_BPSHAD BIT(5) /*!< shadow registers bypass control */ 112 #define RTC_CTL_CS BIT(6) /*!< display format of clock system */ 113 #define RTC_CTL_CCEN BIT(7) /*!< coarse calibration function enable */ 114 #define RTC_CTL_ALRM0EN BIT(8) /*!< alarm0 function enable */ 115 #define RTC_CTL_ALRM1EN BIT(9) /*!< alarm1 function enable */ 116 #define RTC_CTL_WTEN BIT(10) /*!< auto wakeup timer function enable */ 117 #define RTC_CTL_TSEN BIT(11) /*!< time-stamp function enable */ 118 #define RTC_CTL_ALRM0IE BIT(12) /*!< RTC alarm0 interrupt enable */ 119 #define RTC_CTL_ALRM1IE BIT(13) /*!< RTC alarm1 interrupt enable */ 120 #define RTC_CTL_WTIE BIT(14) /*!< auto wakeup timer interrupt enable */ 121 #define RTC_CTL_TSIE BIT(15) /*!< time-stamp interrupt enable */ 122 #define RTC_CTL_A1H BIT(16) /*!< add 1 hour(summer time change) */ 123 #define RTC_CTL_S1H BIT(17) /*!< subtract 1 hour(winter time change) */ 124 #define RTC_CTL_DSM BIT(18) /*!< daylight saving mark */ 125 #define RTC_CTL_COS BIT(19) /*!< calibration output selection */ 126 #define RTC_CTL_OPOL BIT(20) /*!< output polarity */ 127 #define RTC_CTL_OS BITS(21,22) /*!< output selection */ 128 #define RTC_CTL_COEN BIT(23) /*!< calibration output enable */ 129 130 /* RTC_STAT */ 131 #define RTC_STAT_ALRM0WF BIT(0) /*!< alarm0 configuration can be write flag */ 132 #define RTC_STAT_ALRM1WF BIT(1) /*!< alarm1 configuration can be write flag */ 133 #define RTC_STAT_WTWF BIT(2) /*!< wakeup timer can be write flag */ 134 #define RTC_STAT_SOPF BIT(3) /*!< shift function operation pending flag */ 135 #define RTC_STAT_YCM BIT(4) /*!< year configuration mark status flag */ 136 #define RTC_STAT_RSYNF BIT(5) /*!< register synchronization flag */ 137 #define RTC_STAT_INITF BIT(6) /*!< initialization state flag */ 138 #define RTC_STAT_INITM BIT(7) /*!< enter initialization mode */ 139 #define RTC_STAT_ALRM0F BIT(8) /*!< alarm0 occurs flag */ 140 #define RTC_STAT_ALRM1F BIT(9) /*!< alarm1 occurs flag */ 141 #define RTC_STAT_WTF BIT(10) /*!< wakeup timer occurs flag */ 142 #define RTC_STAT_TSF BIT(11) /*!< time-stamp flag */ 143 #define RTC_STAT_TSOVRF BIT(12) /*!< time-stamp overflow flag */ 144 #define RTC_STAT_TP0F BIT(13) /*!< RTC tamper 0 detected flag */ 145 #define RTC_STAT_TP1F BIT(14) /*!< RTC tamper 1 detected flag */ 146 #define RTC_STAT_SCPF BIT(16) /*!< smooth calibration pending flag */ 147 148 /* RTC_PSC */ 149 #define RTC_PSC_FACTOR_S BITS(0,14) /*!< synchronous prescaler factor */ 150 #define RTC_PSC_FACTOR_A BITS(16,22) /*!< asynchronous prescaler factor */ 151 152 /* RTC_WUT */ 153 #define RTC_WUT_WTRV BITS(0,15) /*!< auto wakeup timer reloads value */ 154 155 /* RTC_COSC */ 156 #define RTC_COSC_COSS BITS(0,4) /*!< coarse calibration step */ 157 #define RTC_COSC_COSD BIT(7) /*!< coarse calibration direction */ 158 159 /* RTC_ALRMxTD */ 160 #define RTC_ALRMXTD_SCU BITS(0,3) /*!< second units in BCD code */ 161 #define RTC_ALRMXTD_SCT BITS(4,6) /*!< second tens in BCD code */ 162 #define RTC_ALRMXTD_MSKS BIT(7) /*!< alarm second mask bit */ 163 #define RTC_ALRMXTD_MNU BITS(8,11) /*!< minutes units in BCD code */ 164 #define RTC_ALRMXTD_MNT BITS(12,14) /*!< minutes tens in BCD code */ 165 #define RTC_ALRMXTD_MSKM BIT(15) /*!< alarm minutes mask bit */ 166 #define RTC_ALRMXTD_HRU BITS(16,19) /*!< hour units in BCD code */ 167 #define RTC_ALRMXTD_HRT BITS(20,21) /*!< hour units in BCD code */ 168 #define RTC_ALRMXTD_PM BIT(22) /*!< AM/PM flag */ 169 #define RTC_ALRMXTD_MSKH BIT(23) /*!< alarm hour mask bit */ 170 #define RTC_ALRMXTD_DAYU BITS(24,27) /*!< date units or week day in BCD code */ 171 #define RTC_ALRMXTD_DAYT BITS(28,29) /*!< date tens in BCD code */ 172 #define RTC_ALRMXTD_DOWS BIT(30) /*!< day of week selection */ 173 #define RTC_ALRMXTD_MSKD BIT(31) /*!< alarm date mask bit */ 174 175 /* RTC_WPK */ 176 #define RTC_WPK_WPK BITS(0,7) /*!< key for write protection */ 177 178 /* RTC_SS */ 179 #define RTC_SS_SSC BITS(0,15) /*!< sub second value */ 180 181 /* RTC_SHIFTCTL */ 182 #define RTC_SHIFTCTL_SFS BITS(0,14) /*!< subtract a fraction of a second */ 183 #define RTC_SHIFTCTL_A1S BIT(31) /*!< one second add */ 184 185 /* RTC_TTS */ 186 #define RTC_TTS_SCU BITS(0,3) /*!< second units in BCD code */ 187 #define RTC_TTS_SCT BITS(4,6) /*!< second units in BCD code */ 188 #define RTC_TTS_MNU BITS(8,11) /*!< minute units in BCD code */ 189 #define RTC_TTS_MNT BITS(12,14) /*!< minute tens in BCD code */ 190 #define RTC_TTS_HRU BITS(16,19) /*!< hour units in BCD code */ 191 #define RTC_TTS_HRT BITS(20,21) /*!< hour tens in BCD code */ 192 #define RTC_TTS_PM BIT(22) /*!< AM/PM notation */ 193 194 /* RTC_DTS */ 195 #define RTC_DTS_DAYU BITS(0,3) /*!< date units in BCD code */ 196 #define RTC_DTS_DAYT BITS(4,5) /*!< date tens in BCD code */ 197 #define RTC_DTS_MONU BITS(8,11) /*!< month units in BCD code */ 198 #define RTC_DTS_MONT BIT(12) /*!< month tens in BCD code */ 199 #define RTC_DTS_DOW BITS(13,15) /*!< day of week units */ 200 201 /* RTC_SSTS */ 202 #define RTC_SSTS_SSC BITS(0,15) /*!< timestamp sub second units */ 203 204 /* RTC_HRFC */ 205 #define RTC_HRFC_CMSK BITS(0,8) /*!< calibration mask number */ 206 #define RTC_HRFC_CWND16 BIT(13) /*!< calibration window select 16 seconds */ 207 #define RTC_HRFC_CWND8 BIT(14) /*!< calibration window select 16 seconds */ 208 #define RTC_HRFC_FREQI BIT(15) /*!< increase RTC frequency by 488.5ppm */ 209 210 /* RTC_TAMP */ 211 #define RTC_TAMP_TP0EN BIT(0) /*!< tamper 0 detection enable */ 212 #define RTC_TAMP_TP0EG BIT(1) /*!< tamper 0 event trigger edge for RTC tamp 0 input */ 213 #define RTC_TAMP_TPIE BIT(2) /*!< tamper detection interrupt enable */ 214 #define RTC_TAMP_TP1EN BIT(3) /*!< tamper 1 detection enable */ 215 #define RTC_TAMP_TP1EG BIT(4) /*!< Tamper 1 event trigger edge for RTC tamp 1 input */ 216 #define RTC_TAMP_TPTS BIT(7) /*!< make tamper function used for timestamp function */ 217 #define RTC_TAMP_FREQ BITS(8,10) /*!< sample frequency of tamper event detection */ 218 #define RTC_TAMP_FLT BITS(11,12) /*!< RTC tamp x filter count setting */ 219 #define RTC_TAMP_PRCH BITS(13,14) /*!< precharge duration time of RTC tamp x */ 220 #define RTC_TAMP_DISPU BIT(15) /*!< RTC tamp x pull up disable bit */ 221 #define RTC_TAMP_TP0SEL BIT(16) /*!< Tamper 0 function input mapping selection */ 222 #define RTC_TAMP_TSSEL BIT(17) /*!< Timestamp input mapping selection */ 223 #define RTC_TAMP_AOT BIT(18) /*!< RTC_ALARM output Type */ 224 225 /* RTC_ALRM0SS */ 226 #define RTC_ALRM0SS_SSC BITS(0,14) /*!< alarm0 sub second value */ 227 #define RTC_ALRM0SS_MASKSSC BITS(24,27) /*!< mask control bit of SS */ 228 229 /* RTC_ALRM1SS */ 230 #define RTC_ALRM1SS_SSC BITS(0,14) /*!< alarm1 sub second value */ 231 #define RTC_ALRM1SS_MASKSSC BITS(24,27) /*!< mask control bit of SS */ 232 233 /* constants definitions */ 234 /* structure for initialization of the RTC */ 235 typedef struct 236 { 237 uint8_t year; /*!< RTC year value: 0x0 - 0x99(BCD format) */ 238 uint8_t month; /*!< RTC month value */ 239 uint8_t date; /*!< RTC date value: 0x1 - 0x31(BCD format) */ 240 uint8_t day_of_week; /*!< RTC weekday value */ 241 uint8_t hour; /*!< RTC hour value */ 242 uint8_t minute; /*!< RTC minute value: 0x0 - 0x59(BCD format) */ 243 uint8_t second; /*!< RTC second value: 0x0 - 0x59(BCD format) */ 244 uint16_t factor_asyn; /*!< RTC asynchronous prescaler value: 0x0 - 0x7F */ 245 uint16_t factor_syn; /*!< RTC synchronous prescaler value: 0x0 - 0x7FFF */ 246 uint32_t am_pm; /*!< RTC AM/PM value */ 247 uint32_t display_format; /*!< RTC time notation */ 248 }rtc_parameter_struct; 249 250 /* structure for RTC alarm configuration */ 251 typedef struct 252 { 253 uint32_t alarm_mask; /*!< RTC alarm mask */ 254 uint32_t weekday_or_date; /*!< specify RTC alarm is on date or weekday */ 255 uint8_t alarm_day; /*!< RTC alarm date or weekday value*/ 256 uint8_t alarm_hour; /*!< RTC alarm hour value */ 257 uint8_t alarm_minute; /*!< RTC alarm minute value: 0x0 - 0x59(BCD format) */ 258 uint8_t alarm_second; /*!< RTC alarm second value: 0x0 - 0x59(BCD format) */ 259 uint32_t am_pm; /*!< RTC alarm AM/PM value */ 260 }rtc_alarm_struct; 261 262 /* structure for RTC time-stamp configuration */ 263 typedef struct 264 { 265 uint8_t timestamp_month; /*!< RTC time-stamp month value */ 266 uint8_t timestamp_date; /*!< RTC time-stamp date value: 0x1 - 0x31(BCD format) */ 267 uint8_t timestamp_day; /*!< RTC time-stamp weekday value */ 268 uint8_t timestamp_hour; /*!< RTC time-stamp hour value */ 269 uint8_t timestamp_minute; /*!< RTC time-stamp minute value: 0x0 - 0x59(BCD format) */ 270 uint8_t timestamp_second; /*!< RTC time-stamp second value: 0x0 - 0x59(BCD format) */ 271 uint32_t am_pm; /*!< RTC time-stamp AM/PM value */ 272 }rtc_timestamp_struct; 273 274 /* structure for RTC tamper configuration */ 275 typedef struct 276 { 277 uint32_t tamper_source; /*!< RTC tamper source */ 278 uint32_t tamper_trigger; /*!< RTC tamper trigger */ 279 uint32_t tamper_filter; /*!< RTC tamper consecutive samples needed during a voltage level detection */ 280 uint32_t tamper_sample_frequency; /*!< RTC tamper sampling frequency during a voltage level detection */ 281 ControlStatus tamper_precharge_enable; /*!< RTC tamper precharge feature during a voltage level detection */ 282 uint32_t tamper_precharge_time; /*!< RTC tamper precharge duration if precharge feature is enabled */ 283 ControlStatus tamper_with_timestamp; /*!< RTC tamper time-stamp feature */ 284 }rtc_tamper_struct; 285 286 /* time register value */ 287 #define TIME_SC(regval) (BITS(0,6) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_TIME_SC bit field */ 288 #define GET_TIME_SC(regval) GET_BITS((regval),0,6) /*!< get value of RTC_TIME_SC bit field */ 289 290 #define TIME_MN(regval) (BITS(8,14) & ((uint32_t)(regval) << 8)) /*!< write value to RTC_TIME_MN bit field */ 291 #define GET_TIME_MN(regval) GET_BITS((regval),8,14) /*!< get value of RTC_TIME_MN bit field */ 292 293 #define TIME_HR(regval) (BITS(16,21) & ((uint32_t)(regval) << 16)) /*!< write value to RTC_TIME_HR bit field */ 294 #define GET_TIME_HR(regval) GET_BITS((regval),16,21) /*!< get value of RTC_TIME_HR bit field */ 295 296 #define RTC_AM ((uint32_t)0x00000000U) /*!< AM format */ 297 #define RTC_PM RTC_TIME_PM /*!< PM format */ 298 299 /* date register value */ 300 #define DATE_DAY(regval) (BITS(0,5) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_DATE_DAY bit field */ 301 #define GET_DATE_DAY(regval) GET_BITS((regval),0,5) /*!< get value of RTC_DATE_DAY bit field */ 302 303 #define DATE_MON(regval) (BITS(8,12) & ((uint32_t)(regval) << 8)) /*!< write value to RTC_DATE_MON bit field */ 304 #define GET_DATE_MON(regval) GET_BITS((regval),8,12) /*!< get value of RTC_DATE_MON bit field */ 305 #define RTC_JAN ((uint8_t)0x01U) /*!< janurary */ 306 #define RTC_FEB ((uint8_t)0x02U) /*!< february */ 307 #define RTC_MAR ((uint8_t)0x03U) /*!< march */ 308 #define RTC_APR ((uint8_t)0x04U) /*!< april */ 309 #define RTC_MAY ((uint8_t)0x05U) /*!< may */ 310 #define RTC_JUN ((uint8_t)0x06U) /*!< june */ 311 #define RTC_JUL ((uint8_t)0x07U) /*!< july */ 312 #define RTC_AUG ((uint8_t)0x08U) /*!< august */ 313 #define RTC_SEP ((uint8_t)0x09U) /*!< september */ 314 #define RTC_OCT ((uint8_t)0x10U) /*!< october */ 315 #define RTC_NOV ((uint8_t)0x11U) /*!< november */ 316 #define RTC_DEC ((uint8_t)0x12U) /*!< december */ 317 318 #define DATE_DOW(regval) (BITS(13,15) & ((uint32_t)(regval) << 13)) /*!< write value to RTC_DATE_DOW bit field */ 319 #define GET_DATE_DOW(regval) GET_BITS((uint32_t)(regval),13,15) /*!< get value of RTC_DATE_DOW bit field */ 320 #define RTC_MONDAY ((uint8_t)0x01) /*!< monday */ 321 #define RTC_TUESDAY ((uint8_t)0x02) /*!< tuesday */ 322 #define RTC_WEDSDAY ((uint8_t)0x03) /*!< wednesday */ 323 #define RTC_THURSDAY ((uint8_t)0x04) /*!< thursday */ 324 #define RTC_FRIDAY ((uint8_t)0x05) /*!< friday */ 325 #define RTC_SATURDAY ((uint8_t)0x06) /*!< saturday */ 326 #define RTC_SUNDAY ((uint8_t)0x07) /*!< sunday */ 327 328 #define DATE_YR(regval) (BITS(16,23) & ((uint32_t)(regval) << 16)) /*!< write value to RTC_DATE_YR bit field */ 329 #define GET_DATE_YR(regval) GET_BITS((regval),16,23) /*!< get value of RTC_DATE_YR bit field */ 330 331 /* ctl register value */ 332 #define CTL_OS(regval) (BITS(21,22) & ((uint32_t)(regval) << 21)) /*!< write value to RTC_CTL_OS bit field */ 333 #define RTC_OS_DISABLE CTL_OS(0) /*!< disable output RTC_ALARM */ 334 #define RTC_OS_ALARM0 CTL_OS(1) /*!< enable alarm0 flag output */ 335 #define RTC_OS_ALARM1 CTL_OS(2) /*!< enable alarm1 flag output */ 336 #define RTC_OS_WAKEUP CTL_OS(3) /*!< enable wakeup flag output */ 337 338 #define RTC_CALIBRATION_512HZ RTC_CTL_COEN /*!< calibration output of 512Hz is enable */ 339 #define RTC_CALIBRATION_1HZ (RTC_CTL_COEN | RTC_CTL_COS) /*!< calibration output of 1Hz is enable */ 340 #define RTC_ALARM0_HIGH RTC_OS_ALARM0 /*!< enable alarm0 flag output with high level */ 341 #define RTC_ALARM0_LOW (RTC_OS_ALARM0 | RTC_CTL_OPOL) /*!< enable alarm0 flag output with low level*/ 342 #define RTC_ALARM1_HIGH RTC_OS_ALARM1 /*!< enable alarm1 flag output with high level */ 343 #define RTC_ALARM1_LOW (RTC_OS_ALARM1 | RTC_CTL_OPOL) /*!< enable alarm1 flag output with low level*/ 344 #define RTC_WAKEUP_HIGH RTC_OS_WAKEUP /*!< enable wakeup flag output with high level */ 345 #define RTC_WAKEUP_LOW (RTC_OS_WAKEUP | RTC_CTL_OPOL) /*!< enable wakeup flag output with low level*/ 346 347 #define RTC_24HOUR ((uint32_t)0x00000000U) /*!< 24-hour format */ 348 #define RTC_12HOUR RTC_CTL_CS /*!< 12-hour format */ 349 350 #define RTC_TIMESTAMP_RISING_EDGE ((uint32_t)0x00000000U) /*!< rising edge is valid event edge for time-stamp event */ 351 #define RTC_TIMESTAMP_FALLING_EDGE RTC_CTL_TSEG /*!< falling edge is valid event edge for time-stamp event */ 352 353 /* psc register value */ 354 #define PSC_FACTOR_S(regval) (BITS(0,14) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_PSC_FACTOR_S bit field */ 355 #define GET_PSC_FACTOR_S(regval) GET_BITS((regval),0,14) /*!< get value of RTC_PSC_FACTOR_S bit field */ 356 357 #define PSC_FACTOR_A(regval) (BITS(16,22) & ((uint32_t)(regval) << 16)) /*!< write value to RTC_PSC_FACTOR_A bit field */ 358 #define GET_PSC_FACTOR_A(regval) GET_BITS((regval),16,22) /*!< get value of RTC_PSC_FACTOR_A bit field */ 359 360 /* alrmtd register value */ 361 #define ALRMTD_SC(regval) (BITS(0,6) & ((uint32_t)(regval)<< 0)) /*!< write value to RTC_ALRMTD_SC bit field */ 362 #define GET_ALRMTD_SC(regval) GET_BITS((regval),0,6) /*!< get value of RTC_ALRMTD_SC bit field */ 363 364 #define ALRMTD_MN(regval) (BITS(8,14) & ((uint32_t)(regval) << 8)) /*!< write value to RTC_ALRMTD_MN bit field */ 365 #define GET_ALRMTD_MN(regval) GET_BITS((regval),8,14) /*!< get value of RTC_ALRMTD_MN bit field */ 366 367 #define ALRMTD_HR(regval) (BITS(16,21) & ((uint32_t)(regval) << 16)) /*!< write value to RTC_ALRMTD_HR bit field */ 368 #define GET_ALRMTD_HR(regval) GET_BITS((regval),16,21) /*!< get value of RTC_ALRMTD_HR bit field */ 369 370 #define ALRMTD_DAY(regval) (BITS(24,29) & ((uint32_t)(regval) << 24)) /*!< write value to RTC_ALRMTD_DAY bit field */ 371 #define GET_ALRMTD_DAY(regval) GET_BITS((regval),24,29) /*!< get value of RTC_ALRMTD_DAY bit field */ 372 373 #define RTC_ALARM_NONE_MASK ((uint32_t)0x00000000U) /*!< alarm none mask */ 374 #define RTC_ALARM_DATE_MASK RTC_ALRMXTD_MSKD /*!< alarm date mask */ 375 #define RTC_ALARM_HOUR_MASK RTC_ALRMXTD_MSKH /*!< alarm hour mask */ 376 #define RTC_ALARM_MINUTE_MASK RTC_ALRMXTD_MSKM /*!< alarm minute mask */ 377 #define RTC_ALARM_SECOND_MASK RTC_ALRMXTD_MSKS /*!< alarm second mask */ 378 #define RTC_ALARM_ALL_MASK (RTC_ALRMXTD_MSKD|RTC_ALRMXTD_MSKH|RTC_ALRMXTD_MSKM|RTC_ALRMXTD_MSKS) /*!< alarm all mask */ 379 380 #define RTC_ALARM_DATE_SELECTED ((uint32_t)0x00000000U) /*!< alarm date format selected */ 381 #define RTC_ALARM_WEEKDAY_SELECTED RTC_ALRMXTD_DOWS /*!< alarm weekday format selected */ 382 383 /* wpk register value */ 384 #define WPK_WPK(regval) (BITS(0,7) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_WPK_WPK bit field */ 385 386 /* ss register value */ 387 #define SS_SSC(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_SS_SSC bit field */ 388 389 /* shiftctl register value */ 390 #define SHIFTCTL_SFS(regval) (BITS(0,14) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_SHIFTCTL_SFS bit field */ 391 392 #define RTC_SHIFT_ADD1S_RESET ((uint32_t)0x00000000U) /*!< not add 1 second */ 393 #define RTC_SHIFT_ADD1S_SET RTC_SHIFTCTL_A1S /*!< add one second to the clock */ 394 395 /* tts register value */ 396 #define TTS_SC(regval) (BITS(0,6) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_TTS_SC bit field */ 397 #define GET_TTS_SC(regval) GET_BITS((regval),0,6) /*!< get value of RTC_TTS_SC bit field */ 398 399 #define TTS_MN(regval) (BITS(8,14) & ((uint32_t)(regval) << 8)) /*!< write value to RTC_TTS_MN bit field */ 400 #define GET_TTS_MN(regval) GET_BITS((regval),8,14) /*!< get value of RTC_TTS_MN bit field */ 401 402 #define TTS_HR(regval) (BITS(16,21) & ((uint32_t)(regval) << 16)) /*!< write value to RTC_TTS_HR bit field */ 403 #define GET_TTS_HR(regval) GET_BITS((regval),16,21) /*!< get value of RTC_TTS_HR bit field */ 404 405 /* dts register value */ 406 #define DTS_DAY(regval) (BITS(0,5) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_DTS_DAY bit field */ 407 #define GET_DTS_DAY(regval) GET_BITS((regval),0,5) /*!< get value of RTC_DTS_DAY bit field */ 408 409 #define DTS_MON(regval) (BITS(8,12) & ((uint32_t)(regval) << 8)) /*!< write value to RTC_DTS_MON bit field */ 410 #define GET_DTS_MON(regval) GET_BITS((regval),8,12) /*!< get value of RTC_DTS_MON bit field */ 411 412 #define DTS_DOW(regval) (BITS(13,15) & ((uint32_t)(regval) << 13)) /*!< write value to RTC_DTS_DOW bit field */ 413 #define GET_DTS_DOW(regval) GET_BITS((regval),13,15) /*!< get value of RTC_DTS_DOW bit field */ 414 415 /* ssts register value */ 416 #define SSTS_SSC(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_SSTS_SSC bit field */ 417 418 /* hrfc register value */ 419 #define HRFC_CMSK(regval) (BITS(0,8) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_HRFC_CMSK bit field */ 420 421 #define RTC_CALIBRATION_WINDOW_32S ((uint32_t)0x00000000U) /*!< 2exp20 RTCCLK cycles, 32s if RTCCLK = 32768 Hz */ 422 #define RTC_CALIBRATION_WINDOW_16S RTC_HRFC_CWND16 /*!< 2exp19 RTCCLK cycles, 16s if RTCCLK = 32768 Hz */ 423 #define RTC_CALIBRATION_WINDOW_8S RTC_HRFC_CWND8 /*!< 2exp18 RTCCLK cycles, 8s if RTCCLK = 32768 Hz */ 424 425 #define RTC_CALIBRATION_PLUS_SET RTC_HRFC_FREQI /*!< increase RTC frequency by 488.5ppm */ 426 #define RTC_CALIBRATION_PLUS_RESET ((uint32_t)0x00000000U) /*!< no effect */ 427 428 /* tamp register value */ 429 #define TAMP_FREQ(regval) (BITS(8,10) & ((uint32_t)(regval) << 8)) /*!< write value to RTC_TAMP_FREQ bit field */ 430 #define RTC_FREQ_DIV32768 TAMP_FREQ(0) /*!< sample once every 32768 RTCCLK(1Hz if RTCCLK=32.768KHz) */ 431 #define RTC_FREQ_DIV16384 TAMP_FREQ(1) /*!< sample once every 16384 RTCCLK(2Hz if RTCCLK=32.768KHz) */ 432 #define RTC_FREQ_DIV8192 TAMP_FREQ(2) /*!< sample once every 8192 RTCCLK(4Hz if RTCCLK=32.768KHz) */ 433 #define RTC_FREQ_DIV4096 TAMP_FREQ(3) /*!< sample once every 4096 RTCCLK(8Hz if RTCCLK=32.768KHz) */ 434 #define RTC_FREQ_DIV2048 TAMP_FREQ(4) /*!< sample once every 2048 RTCCLK(16Hz if RTCCLK=32.768KHz) */ 435 #define RTC_FREQ_DIV1024 TAMP_FREQ(5) /*!< sample once every 1024 RTCCLK(32Hz if RTCCLK=32.768KHz) */ 436 #define RTC_FREQ_DIV512 TAMP_FREQ(6) /*!< sample once every 512 RTCCLK(64Hz if RTCCLK=32.768KHz) */ 437 #define RTC_FREQ_DIV256 TAMP_FREQ(7) /*!< sample once every 256 RTCCLK(128Hz if RTCCLK=32.768KHz) */ 438 439 #define TAMP_FLT(regval) (BITS(11,12) & ((uint32_t)(regval) << 11)) /*!< write value to RTC_TAMP_FLT bit field */ 440 #define RTC_FLT_EDGE TAMP_FLT(0) /*!< detecting tamper event using edge mode. precharge duration is disabled automatically */ 441 #define RTC_FLT_2S TAMP_FLT(1) /*!< detecting tamper event using level mode.2 consecutive valid level samples will make a effective tamper event */ 442 #define RTC_FLT_4S TAMP_FLT(2) /*!< detecting tamper event using level mode.4 consecutive valid level samples will make an effective tamper event */ 443 #define RTC_FLT_8S TAMP_FLT(3) /*!< detecting tamper event using level mode.8 consecutive valid level samples will make a effective tamper event */ 444 445 #define TAMP_PRCH(regval) (BITS(13,14) & ((uint32_t)(regval) << 13)) /*!< write value to RTC_TAMP_PRCH bit field */ 446 #define RTC_PRCH_1C TAMP_PRCH(0) /*!< 1 RTC clock prechagre time before each sampling */ 447 #define RTC_PRCH_2C TAMP_PRCH(1) /*!< 2 RTC clock prechagre time before each sampling */ 448 #define RTC_PRCH_4C TAMP_PRCH(2) /*!< 4 RTC clock prechagre time before each sampling */ 449 #define RTC_PRCH_8C TAMP_PRCH(3) /*!< 8 RTC clock prechagre time before each sampling */ 450 451 #define RTC_TAMPER0 RTC_TAMP_TP0EN /*!< tamper 0 detection enable */ 452 #define RTC_TAMPER1 RTC_TAMP_TP1EN /*!< tamper 1 detection enable */ 453 454 #define RTC_TAMPER_TRIGGER_EDGE_RISING ((uint32_t)0x00000000U) /*!< tamper detection is in rising edge mode */ 455 #define RTC_TAMPER_TRIGGER_EDGE_FALLING RTC_TAMP_TP0EG /*!< tamper detection is in falling edge mode */ 456 #define RTC_TAMPER_TRIGGER_LEVEL_LOW ((uint32_t)0x00000000U) /*!< tamper detection is in low level mode */ 457 #define RTC_TAMPER_TRIGGER_LEVEL_HIGH RTC_TAMP_TP0EG /*!< tamper detection is in high level mode */ 458 459 #define RTC_TAMPER_TRIGGER_POS ((uint32_t)0x00000001U) /* shift position of trigger relative to source */ 460 461 #define RTC_ALARM_OUTPUT_OD ((uint32_t)0x00000000U) /*!< RTC alarm output open-drain mode */ 462 #define RTC_ALARM_OUTPUT_PP RTC_TAMP_AOT /*!< RTC alarm output push-pull mode */ 463 464 /* ALRMXSS register value */ 465 #define ALRMXSS_SSC(regval) (BITS(0,14) & ((uint32_t)(regval)<< 0)) /*!< write value to RTC_ALRMXSS_SSC bit field */ 466 467 #define ALRMXSS_MASKSSC(regval) (BITS(24,27) & ((uint32_t)(regval) << 24)) /*!< write value to RTC_ALRMXSS_MASKSSC bit field */ 468 #define RTC_MASKSSC_0_14 ALRMXSS_MASKSSC(0) /*!< mask alarm subsecond configuration */ 469 #define RTC_MASKSSC_1_14 ALRMXSS_MASKSSC(1) /*!< mask RTC_ALRMXSS_SSC[14:1], and RTC_ALRMXSS_SSC[0] is to be compared */ 470 #define RTC_MASKSSC_2_14 ALRMXSS_MASKSSC(2) /*!< mask RTC_ALRMXSS_SSC[14:2], and RTC_ALRMXSS_SSC[1:0] is to be compared */ 471 #define RTC_MASKSSC_3_14 ALRMXSS_MASKSSC(3) /*!< mask RTC_ALRMXSS_SSC[14:3], and RTC_ALRMXSS_SSC[2:0] is to be compared */ 472 #define RTC_MASKSSC_4_14 ALRMXSS_MASKSSC(4) /*!< mask RTC_ALRMXSS_SSC[14:4]], and RTC_ALRMXSS_SSC[3:0] is to be compared */ 473 #define RTC_MASKSSC_5_14 ALRMXSS_MASKSSC(5) /*!< mask RTC_ALRMXSS_SSC[14:5], and RTC_ALRMXSS_SSC[4:0] is to be compared */ 474 #define RTC_MASKSSC_6_14 ALRMXSS_MASKSSC(6) /*!< mask RTC_ALRMXSS_SSC[14:6], and RTC_ALRMXSS_SSC[5:0] is to be compared */ 475 #define RTC_MASKSSC_7_14 ALRMXSS_MASKSSC(7) /*!< mask RTC_ALRMXSS_SSC[14:7], and RTC_ALRMXSS_SSC[6:0] is to be compared */ 476 #define RTC_MASKSSC_8_14 ALRMXSS_MASKSSC(8) /*!< mask RTC_ALRMXSS_SSC[14:7], and RTC_ALRMXSS_SSC[6:0] is to be compared */ 477 #define RTC_MASKSSC_9_14 ALRMXSS_MASKSSC(9) /*!< mask RTC_ALRMXSS_SSC[14:9], and RTC_ALRMXSS_SSC[8:0] is to be compared */ 478 #define RTC_MASKSSC_10_14 ALRMXSS_MASKSSC(10) /*!< mask RTC_ALRMXSS_SSC[14:10], and RTC_ALRMXSS_SSC[9:0] is to be compared */ 479 #define RTC_MASKSSC_11_14 ALRMXSS_MASKSSC(11) /*!< mask RTC_ALRMXSS_SSC[14:11], and RTC_ALRMXSS_SSC[10:0] is to be compared */ 480 #define RTC_MASKSSC_12_14 ALRMXSS_MASKSSC(12) /*!< mask RTC_ALRMXSS_SSC[14:12], and RTC_ALRMXSS_SSC[11:0] is to be compared */ 481 #define RTC_MASKSSC_13_14 ALRMXSS_MASKSSC(13) /*!< mask RTC_ALRMXSS_SSC[14:13], and RTC_ALRMXSS_SSC[12:0] is to be compared */ 482 #define RTC_MASKSSC_14 ALRMXSS_MASKSSC(14) /*!< mask RTC_ALRMXSS_SSC[14], and RTC_ALRMXSS_SSC[13:0] is to be compared */ 483 #define RTC_MASKSSC_NONE ALRMXSS_MASKSSC(15) /*!< mask none, and RTC_ALRMXSS_SSC[14:0] is to be compared */ 484 485 /* RTC interrupt source */ 486 #define RTC_INT_TIMESTAMP RTC_CTL_TSIE /*!< time-stamp interrupt enable */ 487 #define RTC_INT_ALARM0 RTC_CTL_ALRM0IE /*!< RTC alarm0 interrupt enable */ 488 #define RTC_INT_ALARM1 RTC_CTL_ALRM1IE /*!< RTC alarm1 interrupt enable */ 489 #define RTC_INT_TAMP RTC_TAMP_TPIE /*!< tamper detection interrupt enable */ 490 #define RTC_INT_WAKEUP RTC_CTL_WTIE /*!< RTC wakeup timer interrupt enable */ 491 492 /* write protect key */ 493 #define RTC_UNLOCK_KEY1 ((uint8_t)0xCAU) /*!< RTC unlock key1 */ 494 #define RTC_UNLOCK_KEY2 ((uint8_t)0x53U) /*!< RTC unlock key2 */ 495 #define RTC_LOCK_KEY ((uint8_t)0xFFU) /*!< RTC lock key */ 496 497 /* registers reset value */ 498 #define RTC_REGISTER_RESET ((uint32_t)0x00000000U) /*!< RTC common register reset value */ 499 #define RTC_DATE_RESET ((uint32_t)0x00002101U) /*!< RTC_DATE register reset value */ 500 #define RTC_STAT_RESET ((uint32_t)0x00000000U) /*!< RTC_STAT register reset value */ 501 #define RTC_PSC_RESET ((uint32_t)0x007F00FFU) /*!< RTC_PSC register reset value */ 502 #define RTC_WUT_RESET ((uint32_t)0x0000FFFFU) /*!< RTC_WUT register reset value */ 503 504 /* RTC alarm */ 505 #define RTC_ALARM0 ((uint8_t)0x01U) /*!< RTC alarm 0 */ 506 #define RTC_ALARM1 ((uint8_t)0x02U) /*!< RTC alarm 1 */ 507 508 /* RTC coarse calibration direction */ 509 #define CALIB_INCREASE ((uint8_t)0x01U) /*!< RTC coarse calibration increase */ 510 #define CALIB_DECREASE ((uint8_t)0x02U) /*!< RTC coarse calibration decrease */ 511 512 /* RTC wakeup timer clock */ 513 #define CTL_WTCS(regval) (BITS(0,2) & ((regval)<< 0)) 514 #define WAKEUP_RTCCK_DIV16 CTL_WTCS(0) /*!< wakeup timer clock is RTC clock divided by 16 */ 515 #define WAKEUP_RTCCK_DIV8 CTL_WTCS(1) /*!< wakeup timer clock is RTC clock divided by 8 */ 516 #define WAKEUP_RTCCK_DIV4 CTL_WTCS(2) /*!< wakeup timer clock is RTC clock divided by 4 */ 517 #define WAKEUP_RTCCK_DIV2 CTL_WTCS(3) /*!< wakeup timer clock is RTC clock divided by 2 */ 518 #define WAKEUP_CKSPRE CTL_WTCS(4) /*!< wakeup timer clock is ckapre */ 519 #define WAKEUP_CKSPRE_2EXP16 CTL_WTCS(6) /*!< wakeup timer clock is ckapre and wakeup timer add 2exp16 */ 520 521 /* RTC_AF pin */ 522 #define RTC_AF0_TIMESTAMP ((uint32_t)0x00000000) /*!< RTC_AF0 use for timestamp */ 523 #define RTC_AF1_TIMESTAMP RTC_TAMP_TSSEL /*!< RTC_AF1 use for timestamp */ 524 #define RTC_AF0_TAMPER0 ((uint32_t)0x00000000) /*!< RTC_AF0 use for tamper0 */ 525 #define RTC_AF1_TAMPER0 RTC_TAMP_TP0SEL /*!< RTC_AF1 use for tamper0 */ 526 527 /* RTC flags */ 528 #define RTC_FLAG_ALRM0W RTC_STAT_ALRM0WF /*!< alarm0 configuration can be write flag */ 529 #define RTC_FLAG_ALRM1W RTC_STAT_ALRM1WF /*!< alarm1 configuration can be write flag */ 530 #define RTC_FLAG_WTW RTC_STAT_WTWF /*!< wakeup timer can be write flag */ 531 #define RTC_FLAG_SOP RTC_STAT_SOPF /*!< shift function operation pending flag */ 532 #define RTC_FLAG_YCM RTC_STAT_YCM /*!< year configuration mark status flag */ 533 #define RTC_FLAG_RSYN RTC_STAT_RSYNF /*!< register synchronization flag */ 534 #define RTC_FLAG_INIT RTC_STAT_INITF /*!< initialization state flag */ 535 #define RTC_FLAG_ALRM0 RTC_STAT_ALRM0F /*!< alarm0 occurs flag */ 536 #define RTC_FLAG_ALRM1 RTC_STAT_ALRM1F /*!< alarm1 occurs flag */ 537 #define RTC_FLAG_WT RTC_STAT_WTF /*!< wakeup timer occurs flag */ 538 #define RTC_FLAG_TS RTC_STAT_TSF /*!< time-stamp flag */ 539 #define RTC_FLAG_TSOVR RTC_STAT_TSOVRF /*!< time-stamp overflow flag */ 540 #define RTC_FLAG_TP0 RTC_STAT_TP0F /*!< RTC tamper 0 detected flag */ 541 #define RTC_FLAG_TP1 RTC_STAT_TP1F /*!< RTC tamper 1 detected flag */ 542 #define RTC_STAT_SCP RTC_STAT_SCPF /*!< smooth calibration pending flag */ 543 544 /* function declarations */ 545 /* reset most of the RTC registers */ 546 ErrStatus rtc_deinit(void); 547 /* initialize RTC registers */ 548 ErrStatus rtc_init(rtc_parameter_struct* rtc_initpara_struct); 549 /* enter RTC init mode */ 550 ErrStatus rtc_init_mode_enter(void); 551 /* exit RTC init mode */ 552 void rtc_init_mode_exit(void); 553 /* wait until RTC_TIME and RTC_DATE registers are synchronized with APB clock, and the shadow registers are updated */ 554 ErrStatus rtc_register_sync_wait(void); 555 556 /* get current time and date */ 557 void rtc_current_time_get(rtc_parameter_struct* rtc_initpara_struct); 558 /* get current subsecond value */ 559 uint32_t rtc_subsecond_get(void); 560 561 /* configure RTC alarm */ 562 void rtc_alarm_config(uint8_t rtc_alarm, rtc_alarm_struct* rtc_alarm_time); 563 /* configure subsecond of RTC alarm */ 564 void rtc_alarm_subsecond_config(uint8_t rtc_alarm, uint32_t mask_subsecond, uint32_t subsecond); 565 /* get RTC alarm */ 566 void rtc_alarm_get(uint8_t rtc_alarm,rtc_alarm_struct* rtc_alarm_time); 567 /* get RTC alarm subsecond */ 568 uint32_t rtc_alarm_subsecond_get(uint8_t rtc_alarm); 569 /* enable RTC alarm */ 570 void rtc_alarm_enable(uint8_t rtc_alarm); 571 /* disable RTC alarm */ 572 ErrStatus rtc_alarm_disable(uint8_t rtc_alarm); 573 574 /* enable RTC time-stamp */ 575 void rtc_timestamp_enable(uint32_t edge); 576 /* disable RTC time-stamp */ 577 void rtc_timestamp_disable(void); 578 /* get RTC timestamp time and date */ 579 void rtc_timestamp_get(rtc_timestamp_struct* rtc_timestamp); 580 /* get RTC time-stamp subsecond */ 581 uint32_t rtc_timestamp_subsecond_get(void); 582 /* RTC time-stamp pin map */ 583 void rtc_timestamp_pin_map(uint32_t rtc_af); 584 585 /* enable RTC tamper */ 586 void rtc_tamper_enable(rtc_tamper_struct* rtc_tamper); 587 /* disable RTC tamper */ 588 void rtc_tamper_disable(uint32_t source); 589 /* RTC tamper0 pin map */ 590 void rtc_tamper0_pin_map(uint32_t rtc_af); 591 592 /* enable specified RTC interrupt */ 593 void rtc_interrupt_enable(uint32_t interrupt); 594 /* disble specified RTC interrupt */ 595 void rtc_interrupt_disable(uint32_t interrupt); 596 /* check specified flag */ 597 FlagStatus rtc_flag_get(uint32_t flag); 598 /* clear specified flag */ 599 void rtc_flag_clear(uint32_t flag); 600 601 /* configure RTC alarm output source */ 602 void rtc_alarm_output_config(uint32_t source, uint32_t mode); 603 /* configure RTC calibration output source */ 604 void rtc_calibration_output_config(uint32_t source); 605 606 /* adjust the daylight saving time by adding or substracting one hour from the current time */ 607 void rtc_hour_adjust(uint32_t operation); 608 /* adjust RTC second or subsecond value of current time */ 609 ErrStatus rtc_second_adjust(uint32_t add, uint32_t minus); 610 611 /* enable RTC bypass shadow registers function */ 612 void rtc_bypass_shadow_enable(void); 613 /* disable RTC bypass shadow registers function */ 614 void rtc_bypass_shadow_disable(void); 615 616 /* enable RTC reference clock detection function */ 617 ErrStatus rtc_refclock_detection_enable(void); 618 /* disable RTC reference clock detection function */ 619 ErrStatus rtc_refclock_detection_disable(void); 620 621 /* enable RTC wakeup timer */ 622 void rtc_wakeup_enable(void); 623 /* disable RTC wakeup timer */ 624 ErrStatus rtc_wakeup_disable(void); 625 /* set auto wakeup timer clock */ 626 ErrStatus rtc_wakeup_clock_set(uint8_t wakeup_clock); 627 /* set auto wakeup timer value */ 628 ErrStatus rtc_wakeup_timer_set(uint16_t wakeup_timer); 629 /* get auto wakeup timer value */ 630 uint16_t rtc_wakeup_timer_get(void); 631 632 /* configure RTC smooth calibration */ 633 ErrStatus rtc_smooth_calibration_config(uint32_t window, uint32_t plus, uint32_t minus); 634 /* enable RTC coarse calibration */ 635 ErrStatus rtc_coarse_calibration_enable(void); 636 /* disable RTC coarse calibration */ 637 ErrStatus rtc_coarse_calibration_disable(void); 638 /* configure RTC coarse calibration direction and step */ 639 ErrStatus rtc_coarse_calibration_config(uint8_t direction, uint8_t step); 640 641 #endif /* GD32F4XX_RTC_H */ 642