1 /** 2 ****************************************************************************** 3 * @file ft32f0xx_rtc.h 4 * @author FMD AE 5 * @brief This file contains all the functions prototypes for the RTC firmware 6 * library. 7 * @version V1.0.0 8 * @data 2021-07-01 9 ****************************************************************************** 10 */ 11 12 13 /* Define to prevent recursive inclusion -------------------------------------*/ 14 #ifndef __FT32F0XX_RTC_H 15 #define __FT32F0XX_RTC_H 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /* Includes ------------------------------------------------------------------*/ 22 #include "ft32f0xx.h" 23 24 25 26 /** @addtogroup RTC 27 * @{ 28 */ 29 30 /* Exported types ------------------------------------------------------------*/ 31 32 /** 33 * @brief RTC Init structures definition 34 */ 35 typedef struct 36 { 37 uint32_t RTC_HourFormat; /*!< Specifies the RTC Hour Format. 38 This parameter can be a value of @ref RTC_Hour_Formats */ 39 40 uint32_t RTC_AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value. 41 This parameter must be set to a value lower than 0x7F */ 42 43 uint32_t RTC_SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value. 44 This parameter must be set to a value lower than 0x1FFF */ 45 }RTC_InitTypeDef; 46 47 /** 48 * @brief RTC Time structure definition 49 */ 50 typedef struct 51 { 52 uint8_t RTC_Hours; /*!< Specifies the RTC Time Hour. 53 This parameter must be set to a value in the 0-12 range 54 if the RTC_HourFormat_12 is selected or 0-23 range if 55 the RTC_HourFormat_24 is selected. */ 56 57 uint8_t RTC_Minutes; /*!< Specifies the RTC Time Minutes. 58 This parameter must be set to a value in the 0-59 range. */ 59 60 uint8_t RTC_Seconds; /*!< Specifies the RTC Time Seconds. 61 This parameter must be set to a value in the 0-59 range. */ 62 63 uint8_t RTC_H12; /*!< Specifies the RTC AM/PM Time. 64 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 65 }RTC_TimeTypeDef; 66 67 /** 68 * @brief RTC Date structure definition 69 */ 70 typedef struct 71 { 72 uint8_t RTC_WeekDay; /*!< Specifies the RTC Date WeekDay. 73 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 74 75 uint8_t RTC_Month; /*!< Specifies the RTC Date Month. 76 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 77 78 uint8_t RTC_Date; /*!< Specifies the RTC Date. 79 This parameter must be set to a value in the 1-31 range. */ 80 81 uint8_t RTC_Year; /*!< Specifies the RTC Date Year. 82 This parameter must be set to a value in the 0-99 range. */ 83 }RTC_DateTypeDef; 84 85 /** 86 * @brief RTC Alarm structure definition 87 */ 88 typedef struct 89 { 90 RTC_TimeTypeDef RTC_AlarmTime; /*!< Specifies the RTC Alarm Time members. */ 91 92 uint32_t RTC_AlarmMask; /*!< Specifies the RTC Alarm Masks. 93 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 94 95 uint32_t RTC_AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 96 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 97 98 uint8_t RTC_AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 99 This parameter must be set to a value in the 1-31 range 100 if the Alarm Date is selected. 101 This parameter can be a value of @ref RTC_WeekDay_Definitions 102 if the Alarm WeekDay is selected. */ 103 }RTC_AlarmTypeDef; 104 105 /* Exported constants --------------------------------------------------------*/ 106 107 /** @defgroup RTC_Exported_Constants 108 * @{ 109 */ 110 111 112 /** @defgroup RTC_Hour_Formats 113 * @{ 114 */ 115 #define RTC_HourFormat_24 ((uint32_t)0x00000000) 116 #define RTC_HourFormat_12 ((uint32_t)0x00000040) 117 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HourFormat_12) || \ 118 ((FORMAT) == RTC_HourFormat_24)) 119 /** 120 * @} 121 */ 122 123 /** @defgroup RTC_Asynchronous_Predivider 124 * @{ 125 */ 126 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7F) 127 128 /** 129 * @} 130 */ 131 132 133 /** @defgroup RTC_Synchronous_Predivider 134 * @{ 135 */ 136 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFF) 137 138 /** 139 * @} 140 */ 141 142 /** @defgroup RTC_Time_Definitions 143 * @{ 144 */ 145 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0) && ((HOUR) <= 12)) 146 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23) 147 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59) 148 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59) 149 150 /** 151 * @} 152 */ 153 154 /** @defgroup RTC_AM_PM_Definitions 155 * @{ 156 */ 157 #define RTC_H12_AM ((uint8_t)0x00) 158 #define RTC_H12_PM ((uint8_t)0x40) 159 #define IS_RTC_H12(PM) (((PM) == RTC_H12_AM) || ((PM) == RTC_H12_PM)) 160 161 /** 162 * @} 163 */ 164 165 /** @defgroup RTC_Year_Date_Definitions 166 * @{ 167 */ 168 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99) 169 170 /** 171 * @} 172 */ 173 174 /** @defgroup RTC_Month_Date_Definitions 175 * @{ 176 */ 177 #define RTC_Month_January ((uint8_t)0x01) 178 #define RTC_Month_February ((uint8_t)0x02) 179 #define RTC_Month_March ((uint8_t)0x03) 180 #define RTC_Month_April ((uint8_t)0x04) 181 #define RTC_Month_May ((uint8_t)0x05) 182 #define RTC_Month_June ((uint8_t)0x06) 183 #define RTC_Month_July ((uint8_t)0x07) 184 #define RTC_Month_August ((uint8_t)0x08) 185 #define RTC_Month_September ((uint8_t)0x09) 186 #define RTC_Month_October ((uint8_t)0x10) 187 #define RTC_Month_November ((uint8_t)0x11) 188 #define RTC_Month_December ((uint8_t)0x12) 189 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1) && ((MONTH) <= 12)) 190 #define IS_RTC_DATE(DATE) (((DATE) >= 1) && ((DATE) <= 31)) 191 192 /** 193 * @} 194 */ 195 196 /** @defgroup RTC_WeekDay_Definitions 197 * @{ 198 */ 199 200 #define RTC_Weekday_Monday ((uint8_t)0x01) 201 #define RTC_Weekday_Tuesday ((uint8_t)0x02) 202 #define RTC_Weekday_Wednesday ((uint8_t)0x03) 203 #define RTC_Weekday_Thursday ((uint8_t)0x04) 204 #define RTC_Weekday_Friday ((uint8_t)0x05) 205 #define RTC_Weekday_Saturday ((uint8_t)0x6) 206 #define RTC_Weekday_Sunday ((uint8_t)0x07) 207 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_Weekday_Monday) || \ 208 ((WEEKDAY) == RTC_Weekday_Tuesday) || \ 209 ((WEEKDAY) == RTC_Weekday_Wednesday) || \ 210 ((WEEKDAY) == RTC_Weekday_Thursday) || \ 211 ((WEEKDAY) == RTC_Weekday_Friday) || \ 212 ((WEEKDAY) == RTC_Weekday_Saturday) || \ 213 ((WEEKDAY) == RTC_Weekday_Sunday)) 214 /** 215 * @} 216 */ 217 218 219 /** @defgroup RTC_Alarm_Definitions 220 * @{ 221 */ 222 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0) && ((DATE) <= 31)) 223 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_Weekday_Monday) || \ 224 ((WEEKDAY) == RTC_Weekday_Tuesday) || \ 225 ((WEEKDAY) == RTC_Weekday_Wednesday) || \ 226 ((WEEKDAY) == RTC_Weekday_Thursday) || \ 227 ((WEEKDAY) == RTC_Weekday_Friday) || \ 228 ((WEEKDAY) == RTC_Weekday_Saturday) || \ 229 ((WEEKDAY) == RTC_Weekday_Sunday)) 230 231 /** 232 * @} 233 */ 234 235 236 /** @defgroup RTC_AlarmDateWeekDay_Definitions 237 * @{ 238 */ 239 #define RTC_AlarmDateWeekDaySel_Date ((uint32_t)0x00000000) 240 #define RTC_AlarmDateWeekDaySel_WeekDay ((uint32_t)0x40000000) 241 242 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_AlarmDateWeekDaySel_Date) || \ 243 ((SEL) == RTC_AlarmDateWeekDaySel_WeekDay)) 244 245 /** 246 * @} 247 */ 248 249 250 /** @defgroup RTC_AlarmMask_Definitions 251 * @{ 252 */ 253 #define RTC_AlarmMask_None ((uint32_t)0x00000000) 254 #define RTC_AlarmMask_DateWeekDay ((uint32_t)0x80000000) 255 #define RTC_AlarmMask_Hours ((uint32_t)0x00800000) 256 #define RTC_AlarmMask_Minutes ((uint32_t)0x00008000) 257 #define RTC_AlarmMask_Seconds ((uint32_t)0x00000080) 258 #define RTC_AlarmMask_All ((uint32_t)0x80808080) 259 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7F) == (uint32_t)RESET) 260 261 /** 262 * @} 263 */ 264 265 /** @defgroup RTC_Alarms_Definitions 266 * @{ 267 */ 268 #define RTC_Alarm_A ((uint32_t)0x00000100) 269 #define IS_RTC_ALARM(ALARM) ((ALARM) == RTC_Alarm_A) 270 #define IS_RTC_CMD_ALARM(ALARM) (((ALARM) & (RTC_Alarm_A)) != (uint32_t)RESET) 271 272 /** 273 * @} 274 */ 275 276 /** @defgroup RTC_Alarm_Sub_Seconds_Masks Definitions. 277 * @{ 278 */ 279 #define RTC_AlarmSubSecondMask_All ((uint8_t)0x00) /*!< All Alarm SS fields are masked. 280 There is no comparison on sub seconds 281 for Alarm */ 282 #define RTC_AlarmSubSecondMask_SS14_1 ((uint8_t)0x01) /*!< SS[14:1] are don't care in Alarm 283 comparison. Only SS[0] is compared. */ 284 #define RTC_AlarmSubSecondMask_SS14_2 ((uint8_t)0x02) /*!< SS[14:2] are don't care in Alarm 285 comparison. Only SS[1:0] are compared */ 286 #define RTC_AlarmSubSecondMask_SS14_3 ((uint8_t)0x03) /*!< SS[14:3] are don't care in Alarm 287 comparison. Only SS[2:0] are compared */ 288 #define RTC_AlarmSubSecondMask_SS14_4 ((uint8_t)0x04) /*!< SS[14:4] are don't care in Alarm 289 comparison. Only SS[3:0] are compared */ 290 #define RTC_AlarmSubSecondMask_SS14_5 ((uint8_t)0x05) /*!< SS[14:5] are don't care in Alarm 291 comparison. Only SS[4:0] are compared */ 292 #define RTC_AlarmSubSecondMask_SS14_6 ((uint8_t)0x06) /*!< SS[14:6] are don't care in Alarm 293 comparison. Only SS[5:0] are compared */ 294 #define RTC_AlarmSubSecondMask_SS14_7 ((uint8_t)0x07) /*!< SS[14:7] are don't care in Alarm 295 comparison. Only SS[6:0] are compared */ 296 #define RTC_AlarmSubSecondMask_SS14_8 ((uint8_t)0x08) /*!< SS[14:8] are don't care in Alarm 297 comparison. Only SS[7:0] are compared */ 298 #define RTC_AlarmSubSecondMask_SS14_9 ((uint8_t)0x09) /*!< SS[14:9] are don't care in Alarm 299 comparison. Only SS[8:0] are compared */ 300 #define RTC_AlarmSubSecondMask_SS14_10 ((uint8_t)0x0A) /*!< SS[14:10] are don't care in Alarm 301 comparison. Only SS[9:0] are compared */ 302 #define RTC_AlarmSubSecondMask_SS14_11 ((uint8_t)0x0B) /*!< SS[14:11] are don't care in Alarm 303 comparison. Only SS[10:0] are compared */ 304 #define RTC_AlarmSubSecondMask_SS14_12 ((uint8_t)0x0C) /*!< SS[14:12] are don't care in Alarm 305 comparison.Only SS[11:0] are compared */ 306 #define RTC_AlarmSubSecondMask_SS14_13 ((uint8_t)0x0D) /*!< SS[14:13] are don't care in Alarm 307 comparison. Only SS[12:0] are compared */ 308 #define RTC_AlarmSubSecondMask_SS14 ((uint8_t)0x0E) /*!< SS[14] is don't care in Alarm 309 comparison.Only SS[13:0] are compared */ 310 #define RTC_AlarmSubSecondMask_None ((uint8_t)0x0F) /*!< SS[14:0] are compared and must match 311 to activate alarm. */ 312 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_AlarmSubSecondMask_All) || \ 313 ((MASK) == RTC_AlarmSubSecondMask_SS14_1) || \ 314 ((MASK) == RTC_AlarmSubSecondMask_SS14_2) || \ 315 ((MASK) == RTC_AlarmSubSecondMask_SS14_3) || \ 316 ((MASK) == RTC_AlarmSubSecondMask_SS14_4) || \ 317 ((MASK) == RTC_AlarmSubSecondMask_SS14_5) || \ 318 ((MASK) == RTC_AlarmSubSecondMask_SS14_6) || \ 319 ((MASK) == RTC_AlarmSubSecondMask_SS14_7) || \ 320 ((MASK) == RTC_AlarmSubSecondMask_SS14_8) || \ 321 ((MASK) == RTC_AlarmSubSecondMask_SS14_9) || \ 322 ((MASK) == RTC_AlarmSubSecondMask_SS14_10) || \ 323 ((MASK) == RTC_AlarmSubSecondMask_SS14_11) || \ 324 ((MASK) == RTC_AlarmSubSecondMask_SS14_12) || \ 325 ((MASK) == RTC_AlarmSubSecondMask_SS14_13) || \ 326 ((MASK) == RTC_AlarmSubSecondMask_SS14) || \ 327 ((MASK) == RTC_AlarmSubSecondMask_None)) 328 /** 329 * @} 330 */ 331 332 /** @defgroup RTC_Alarm_Sub_Seconds_Value 333 * @{ 334 */ 335 336 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFF) 337 338 /** 339 * @} 340 */ 341 342 /** 343 * @} 344 */ 345 346 /** @defgroup RTC_Time_Stamp_Edges_definitions 347 * @{ 348 */ 349 #define RTC_TimeStampEdge_Rising ((uint32_t)0x00000000) 350 #define RTC_TimeStampEdge_Falling ((uint32_t)0x00000008) 351 #define IS_RTC_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TimeStampEdge_Rising) || \ 352 ((EDGE) == RTC_TimeStampEdge_Falling)) 353 /** 354 * @} 355 */ 356 357 /** @defgroup RTC_Output_selection_Definitions 358 * @{ 359 */ 360 #define RTC_Output_Disable ((uint32_t)0x00000000) 361 #define RTC_Output_AlarmA ((uint32_t)0x00200000) 362 #define RTC_Output_WakeUp ((uint32_t)0x00600000) 363 364 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_Output_Disable) || \ 365 ((OUTPUT) == RTC_Output_AlarmA) || \ 366 ((OUTPUT) == RTC_Output_WakeUp)) 367 368 /** 369 * @} 370 */ 371 372 /** @defgroup RTC_Output_Polarity_Definitions 373 * @{ 374 */ 375 #define RTC_OutputPolarity_High ((uint32_t)0x00000000) 376 #define RTC_OutputPolarity_Low ((uint32_t)0x00100000) 377 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OutputPolarity_High) || \ 378 ((POL) == RTC_OutputPolarity_Low)) 379 /** 380 * @} 381 */ 382 383 384 /** @defgroup RTC_Calib_Output_selection_Definitions 385 * @{ 386 */ 387 #define RTC_CalibOutput_512Hz ((uint32_t)0x00000000) 388 #define RTC_CalibOutput_1Hz ((uint32_t)0x00080000) 389 #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CalibOutput_512Hz) || \ 390 ((OUTPUT) == RTC_CalibOutput_1Hz)) 391 /** 392 * @} 393 */ 394 395 /** @defgroup RTC_Smooth_calib_period_Definitions 396 * @{ 397 */ 398 #define RTC_SmoothCalibPeriod_32sec ((uint32_t)0x00000000) /*!< if RTCCLK = 32768 Hz, Smooth calibation 399 period is 32s, else 2exp20 RTCCLK seconds */ 400 #define RTC_SmoothCalibPeriod_16sec ((uint32_t)0x00002000) /*!< if RTCCLK = 32768 Hz, Smooth calibation 401 period is 16s, else 2exp19 RTCCLK seconds */ 402 #define RTC_SmoothCalibPeriod_8sec ((uint32_t)0x00004000) /*!< if RTCCLK = 32768 Hz, Smooth calibation 403 period is 8s, else 2exp18 RTCCLK seconds */ 404 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SmoothCalibPeriod_32sec) || \ 405 ((PERIOD) == RTC_SmoothCalibPeriod_16sec) || \ 406 ((PERIOD) == RTC_SmoothCalibPeriod_8sec)) 407 408 /** 409 * @} 410 */ 411 412 /** @defgroup RTC_Smooth_calib_Plus_pulses_Definitions 413 * @{ 414 */ 415 #define RTC_SmoothCalibPlusPulses_Set ((uint32_t)0x00008000) /*!< The number of RTCCLK pulses added 416 during a X -second window = Y - CALM[8:0]. 417 with Y = 512, 256, 128 when X = 32, 16, 8 */ 418 #define RTC_SmoothCalibPlusPulses_Reset ((uint32_t)0x00000000) /*!< The number of RTCCLK pulses subbstited 419 during a 32-second window = CALM[8:0]. */ 420 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SmoothCalibPlusPulses_Set) || \ 421 ((PLUS) == RTC_SmoothCalibPlusPulses_Reset)) 422 423 /** 424 * @} 425 */ 426 427 /** @defgroup RTC_Smooth_calib_Minus_pulses_Definitions 428 * @{ 429 */ 430 #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= 0x000001FF) 431 432 /** 433 * @} 434 */ 435 436 /** @defgroup RTC_DayLightSaving_Definitions 437 * @{ 438 */ 439 #define RTC_DayLightSaving_SUB1H ((uint32_t)0x00020000) 440 #define RTC_DayLightSaving_ADD1H ((uint32_t)0x00010000) 441 #define IS_RTC_DAYLIGHT_SAVING(SAVING) (((SAVING) == RTC_DayLightSaving_SUB1H) || \ 442 ((SAVING) == RTC_DayLightSaving_ADD1H)) 443 444 #define RTC_StoreOperation_Reset ((uint32_t)0x00000000) 445 #define RTC_StoreOperation_Set ((uint32_t)0x00040000) 446 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_StoreOperation_Reset) || \ 447 ((OPERATION) == RTC_StoreOperation_Set)) 448 /** 449 * @} 450 */ 451 452 /** @defgroup RTC_Tamper_Trigger_Definitions 453 * @{ 454 */ 455 #define RTC_TamperTrigger_RisingEdge ((uint32_t)0x00000000) 456 #define RTC_TamperTrigger_FallingEdge ((uint32_t)0x00000001) 457 #define RTC_TamperTrigger_LowLevel ((uint32_t)0x00000000) 458 #define RTC_TamperTrigger_HighLevel ((uint32_t)0x00000001) 459 #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TamperTrigger_RisingEdge) || \ 460 ((TRIGGER) == RTC_TamperTrigger_FallingEdge) || \ 461 ((TRIGGER) == RTC_TamperTrigger_LowLevel) || \ 462 ((TRIGGER) == RTC_TamperTrigger_HighLevel)) 463 464 /** 465 * @} 466 */ 467 468 /** @defgroup RTC_Tamper_Filter_Definitions 469 * @{ 470 */ 471 #define RTC_TamperFilter_Disable ((uint32_t)0x00000000) /*!< Tamper filter is disabled */ 472 473 #define RTC_TamperFilter_2Sample ((uint32_t)0x00000800) /*!< Tamper is activated after 2 474 consecutive samples at the active level */ 475 #define RTC_TamperFilter_4Sample ((uint32_t)0x00001000) /*!< Tamper is activated after 4 476 consecutive samples at the active level */ 477 #define RTC_TamperFilter_8Sample ((uint32_t)0x00001800) /*!< Tamper is activated after 8 478 consecutive samples at the active leve. */ 479 #define IS_RTC_TAMPER_FILTER(FILTER) (((FILTER) == RTC_TamperFilter_Disable) || \ 480 ((FILTER) == RTC_TamperFilter_2Sample) || \ 481 ((FILTER) == RTC_TamperFilter_4Sample) || \ 482 ((FILTER) == RTC_TamperFilter_8Sample)) 483 /** 484 * @} 485 */ 486 487 /** @defgroup RTC_Tamper_Sampling_Frequencies_Definitions 488 * @{ 489 */ 490 #define RTC_TamperSamplingFreq_RTCCLK_Div32768 ((uint32_t)0x00000000) /*!< Each of the tamper inputs are sampled 491 with a frequency = RTCCLK / 32768 */ 492 #define RTC_TamperSamplingFreq_RTCCLK_Div16384 ((uint32_t)0x00000100) /*!< Each of the tamper inputs are sampled 493 with a frequency = RTCCLK / 16384 */ 494 #define RTC_TamperSamplingFreq_RTCCLK_Div8192 ((uint32_t)0x00000200) /*!< Each of the tamper inputs are sampled 495 with a frequency = RTCCLK / 8192 */ 496 #define RTC_TamperSamplingFreq_RTCCLK_Div4096 ((uint32_t)0x00000300) /*!< Each of the tamper inputs are sampled 497 with a frequency = RTCCLK / 4096 */ 498 #define RTC_TamperSamplingFreq_RTCCLK_Div2048 ((uint32_t)0x00000400) /*!< Each of the tamper inputs are sampled 499 with a frequency = RTCCLK / 2048 */ 500 #define RTC_TamperSamplingFreq_RTCCLK_Div1024 ((uint32_t)0x00000500) /*!< Each of the tamper inputs are sampled 501 with a frequency = RTCCLK / 1024 */ 502 #define RTC_TamperSamplingFreq_RTCCLK_Div512 ((uint32_t)0x00000600) /*!< Each of the tamper inputs are sampled 503 with a frequency = RTCCLK / 512 */ 504 #define RTC_TamperSamplingFreq_RTCCLK_Div256 ((uint32_t)0x00000700) /*!< Each of the tamper inputs are sampled 505 with a frequency = RTCCLK / 256 */ 506 #define IS_RTC_TAMPER_SAMPLING_FREQ(FREQ) (((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div32768) || \ 507 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div16384) || \ 508 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div8192) || \ 509 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div4096) || \ 510 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div2048) || \ 511 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div1024) || \ 512 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div512) || \ 513 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div256)) 514 515 /** 516 * @} 517 */ 518 519 /** @defgroup RTC_Tamper_Pin_Precharge_Duration_Definitions 520 * @{ 521 */ 522 #define RTC_TamperPrechargeDuration_1RTCCLK ((uint32_t)0x00000000) /*!< Tamper pins are pre-charged before 523 sampling during 1 RTCCLK cycle */ 524 #define RTC_TamperPrechargeDuration_2RTCCLK ((uint32_t)0x00002000) /*!< Tamper pins are pre-charged before 525 sampling during 2 RTCCLK cycles */ 526 #define RTC_TamperPrechargeDuration_4RTCCLK ((uint32_t)0x00004000) /*!< Tamper pins are pre-charged before 527 sampling during 4 RTCCLK cycles */ 528 #define RTC_TamperPrechargeDuration_8RTCCLK ((uint32_t)0x00006000) /*!< Tamper pins are pre-charged before 529 sampling during 8 RTCCLK cycles */ 530 531 #define IS_RTC_TAMPER_PRECHARGE_DURATION(DURATION) (((DURATION) == RTC_TamperPrechargeDuration_1RTCCLK) || \ 532 ((DURATION) == RTC_TamperPrechargeDuration_2RTCCLK) || \ 533 ((DURATION) == RTC_TamperPrechargeDuration_4RTCCLK) || \ 534 ((DURATION) == RTC_TamperPrechargeDuration_8RTCCLK)) 535 /** 536 * @} 537 */ 538 539 /** @defgroup RTC_Tamper_Pins_Definitions 540 * @{ 541 */ 542 #define RTC_Tamper_1 RTC_TAFCR_TAMP1E /*!< Tamper detection enable for 543 input tamper 1 */ 544 #define RTC_Tamper_2 RTC_TAFCR_TAMP2E /*!< Tamper detection enable for 545 input tamper 2 */ 546 #define RTC_Tamper_3 RTC_TAFCR_TAMP3E /*!< Tamper detection enable for 547 input tamper 3*/ 548 #define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & (uint32_t)0xFFFFFFD6) == 0x00) && ((TAMPER) != (uint32_t)RESET)) 549 550 /** 551 * @} 552 */ 553 554 /** @defgroup RTC_Output_Type_ALARM_OUT 555 * @{ 556 */ 557 #define RTC_OutputType_OpenDrain ((uint32_t)0x00000000) 558 #define RTC_OutputType_PushPull ((uint32_t)0x00040000) 559 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OutputType_OpenDrain) || \ 560 ((TYPE) == RTC_OutputType_PushPull)) 561 562 /** 563 * @} 564 */ 565 566 /** @defgroup RTC_Add_1_Second_Parameter_Definitions 567 * @{ 568 */ 569 #define RTC_ShiftAdd1S_Reset ((uint32_t)0x00000000) 570 #define RTC_ShiftAdd1S_Set ((uint32_t)0x80000000) 571 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_ShiftAdd1S_Reset) || \ 572 ((SEL) == RTC_ShiftAdd1S_Set)) 573 /** 574 * @} 575 */ 576 577 /** @defgroup RTC_Substract_Fraction_Of_Second_Value 578 * @{ 579 */ 580 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= 0x00007FFF) 581 582 /** 583 * @} 584 */ 585 586 /** 587 * @} 588 */ 589 590 /** @defgroup RTC_Input_parameter_format_definitions 591 * @{ 592 */ 593 #define RTC_Format_BIN ((uint32_t)0x000000000) 594 #define RTC_Format_BCD ((uint32_t)0x000000001) 595 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_Format_BIN) || ((FORMAT) == RTC_Format_BCD)) 596 597 /** 598 * @} 599 */ 600 601 /** @defgroup RTC_Flags_Definitions 602 * @{ 603 */ 604 #define RTC_FLAG_RECALPF RTC_ISR_RECALPF 605 #define RTC_FLAG_TAMP3F RTC_ISR_TAMP3F 606 #define RTC_FLAG_TAMP2F RTC_ISR_TAMP2F 607 #define RTC_FLAG_TAMP1F RTC_ISR_TAMP1F 608 #define RTC_FLAG_TSOVF RTC_ISR_TSOVF 609 #define RTC_FLAG_TSF RTC_ISR_TSF 610 #define RTC_FLAG_WUTF RTC_ISR_WUTF 611 #define RTC_FLAG_ALRAF RTC_ISR_ALRAF 612 #define RTC_FLAG_INITF RTC_ISR_INITF 613 #define RTC_FLAG_RSF RTC_ISR_RSF 614 #define RTC_FLAG_INITS RTC_ISR_INITS 615 #define RTC_FLAG_SHPF RTC_ISR_SHPF 616 #define RTC_FLAG_WUTWF RTC_ISR_WUTWF 617 #define RTC_FLAG_ALRAWF RTC_ISR_ALRAWF 618 619 #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_TSOVF) || ((FLAG) == RTC_FLAG_TSF) || \ 620 ((FLAG) == RTC_FLAG_WUTF) || ((FLAG) == RTC_FLAG_ALRAWF) || \ 621 ((FLAG) == RTC_FLAG_ALRAF) || ((FLAG) == RTC_FLAG_INITF) || \ 622 ((FLAG) == RTC_FLAG_RSF) || ((FLAG) == RTC_FLAG_WUTWF) || \ 623 ((FLAG) == RTC_FLAG_TAMP1F) || ((FLAG) == RTC_FLAG_TAMP2F) || \ 624 ((FLAG) == RTC_FLAG_TAMP3F) || ((FLAG) == RTC_FLAG_RECALPF) || \ 625 ((FLAG) == RTC_FLAG_SHPF)) 626 #define IS_RTC_CLEAR_FLAG(FLAG) (((FLAG) != (uint32_t)RESET) && (((FLAG) & 0xFFFF02DF) == (uint32_t)RESET)) 627 628 /** 629 * @} 630 */ 631 632 /** @defgroup RTC_Interrupts_Definitions 633 * @{ 634 */ 635 #define RTC_IT_TS ((uint32_t)0x00008000) 636 #define RTC_IT_WUT ((uint32_t)0x00004000) 637 #define RTC_IT_ALRA ((uint32_t)0x00001000) 638 #define RTC_IT_TAMP ((uint32_t)0x00000004) /* Used only to Enable the Tamper Interrupt */ 639 #define RTC_IT_TAMP1 ((uint32_t)0x00020000) 640 #define RTC_IT_TAMP2 ((uint32_t)0x00040000) 641 #define RTC_IT_TAMP3 ((uint32_t)0x00080000) 642 643 #define IS_RTC_CONFIG_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFFF2FFB) == (uint32_t)RESET)) 644 #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_TS) || ((IT) == RTC_IT_ALRA) || \ 645 ((IT) == RTC_IT_TAMP1) || ((IT) == RTC_IT_WUT) || \ 646 ((IT) == RTC_IT_TAMP2) || ((IT) == RTC_IT_TAMP3)) 647 648 #define IS_RTC_CLEAR_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFF12FFF) == (uint32_t)RESET)) 649 650 /** 651 * @} 652 */ 653 654 /** 655 * @} 656 */ 657 658 659 /* Exported macro ------------------------------------------------------------*/ 660 /* Exported functions ------------------------------------------------------- */ 661 /* Function used to set the RTC configuration to the default reset state *****/ 662 ErrorStatus RTC_DeInit(void); 663 664 665 /* Initialization and Configuration functions *********************************/ 666 ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct); 667 void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct); 668 void RTC_WriteProtectionCmd(FunctionalState NewState); 669 ErrorStatus RTC_EnterInitMode(void); 670 void RTC_ExitInitMode(void); 671 ErrorStatus RTC_WaitForSynchro(void); 672 ErrorStatus RTC_RefClockCmd(FunctionalState NewState); 673 void RTC_BypassShadowCmd(FunctionalState NewState); 674 675 /* Time and Date configuration functions **************************************/ 676 ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct); 677 void RTC_TimeStructInit(RTC_TimeTypeDef* RTC_TimeStruct); 678 void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct); 679 uint32_t RTC_GetSubSecond(void); 680 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct); 681 void RTC_DateStructInit(RTC_DateTypeDef* RTC_DateStruct); 682 void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct); 683 684 /* Alarms (Alarm A) configuration functions **********************************/ 685 void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct); 686 void RTC_AlarmStructInit(RTC_AlarmTypeDef* RTC_AlarmStruct); 687 void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct); 688 ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState); 689 void RTC_AlarmSubSecondConfig(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint8_t RTC_AlarmSubSecondMask); 690 uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm); 691 692 /* Daylight Saving configuration functions ************************************/ 693 void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation); 694 uint32_t RTC_GetStoreOperation(void); 695 696 /* Output pin Configuration function ******************************************/ 697 void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity); 698 699 /* Digital Calibration configuration functions ********************************/ 700 void RTC_CalibOutputCmd(FunctionalState NewState); 701 void RTC_CalibOutputConfig(uint32_t RTC_CalibOutput); 702 ErrorStatus RTC_SmoothCalibConfig(uint32_t RTC_SmoothCalibPeriod, 703 uint32_t RTC_SmoothCalibPlusPulses, 704 uint32_t RTC_SmouthCalibMinusPulsesValue); 705 706 /* TimeStamp configuration functions ******************************************/ 707 void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState); 708 void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_StampTimeStruct, RTC_DateTypeDef* RTC_StampDateStruct); 709 uint32_t RTC_GetTimeStampSubSecond(void); 710 711 /* Tampers configuration functions ********************************************/ 712 void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger); 713 void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState); 714 void RTC_TamperFilterConfig(uint32_t RTC_TamperFilter); 715 void RTC_TamperSamplingFreqConfig(uint32_t RTC_TamperSamplingFreq); 716 void RTC_TamperPinsPrechargeDuration(uint32_t RTC_TamperPrechargeDuration); 717 void RTC_TimeStampOnTamperDetectionCmd(FunctionalState NewState); 718 void RTC_TamperPullUpCmd(FunctionalState NewState); 719 720 /* Output Type Config configuration functions *********************************/ 721 void RTC_OutputTypeConfig(uint32_t RTC_OutputType); 722 723 /* RTC_Shift_control_synchonisation_functions *********************************/ 724 ErrorStatus RTC_SynchroShiftConfig(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS); 725 726 /* Interrupts and flags management functions **********************************/ 727 void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState); 728 FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG); 729 void RTC_ClearFlag(uint32_t RTC_FLAG); 730 ITStatus RTC_GetITStatus(uint32_t RTC_IT); 731 void RTC_ClearITPendingBit(uint32_t RTC_IT); 732 733 #ifdef __cplusplus 734 } 735 #endif 736 737 #endif /*__FT32F0XX_RTC_H */ 738 739 /** 740 * @} 741 */ 742 743 /** 744 * @} 745 */ 746 747 /************************ (C) COPYRIGHT FMD *****END OF FILE****/ 748