1 /* 2 * SPDX-FileCopyrightText: 2016 STMicroelectronics 3 * SPDX-FileCopyrightText: 2019-2025 SiFli Technologies(Nanjing) Co., Ltd 4 * 5 * SPDX-License-Identifier: BSD-3-Clause AND Apache-2.0 6 */ 7 8 #ifndef __BF0_HAL_RTC_H 9 #define __BF0_HAL_RTC_H 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 /* Includes ------------------------------------------------------------------*/ 16 #include "bf0_hal_def.h" 17 18 /** @addtogroup BF0_HAL_Driver 19 * @{ 20 */ 21 #ifndef RC10K_FREQ 22 #define RC10K_FREQ 9000 23 #endif 24 25 #ifndef RC32K_FREQ 26 #define RC32K_FREQ 26665 27 #endif 28 29 #ifndef LXT_FREQ 30 #define LXT_FREQ 32768 31 #endif 32 33 #define RC10K_SUB_SEC_DIVB 256 /*!< RTC DIVB default setting */ 34 35 /** @addtogroup RTC Real timer clock 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @defgroup RTC_Exported_Types RTC Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief HAL State structures definition 46 */ 47 typedef enum 48 { 49 HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */ 50 HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */ 51 HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */ 52 HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */ 53 HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */ 54 } HAL_RTCStateTypeDef; 55 56 /** 57 * @brief RTC Configuration Structure definition 58 */ 59 typedef struct 60 { 61 uint32_t HourFormat; /*!< Specifies the RTC Hour Format. 62 This parameter can be a value of @ref RTC_Hour_Formats */ 63 64 uint32_t DivAInt; /*!< Specifies the RTC Divider A integrate value. 65 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x80 */ 66 67 uint32_t DivAFrac; /*!< Specifies the RTC Divider A fraction value. */ 68 69 uint32_t DivB; /*!< Specifies the RTC Divider B value. 70 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x100U */ 71 } RTC_InitTypeDef; 72 73 /** 74 * @brief RTC Time structure definition 75 */ 76 typedef struct 77 { 78 uint8_t Hours; /*!< Specifies the RTC Time Hour. 79 This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected. 80 This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */ 81 82 uint8_t Minutes; /*!< Specifies the RTC Time Minutes. 83 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 84 85 uint8_t Seconds; /*!< Specifies the RTC Time Seconds. 86 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 87 88 uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. 89 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 90 91 uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content. 92 This parameter corresponds to a time unit range between [0-1] Second 93 with [1 Sec / SecondFraction] granularity */ 94 95 uint32_t SecondFractionInt; /*!< Specifies the range or granularity of Sub Second register content 96 corresponding to Synchronous DivA integrade factor value 97 This parameter corresponds to SecondFraction integrade part. SecondFraction is 98 calcualted by [Fclk << 2^14 / (SecondFractionInt << 2^14) + SecondFractionFrac]. 99 This field will be used only by HAL_RTC_GetTime function */ 100 uint32_t SecondFractionFrac; /*!< Specifies the range or granularity of Sub Second register content 101 corresponding to Synchronous DivA fraction factor value 102 This parameter corresponds to SecondFraction fraction part. SecondFraction is 103 calcualted by [Fclk << 2^14 / (SecondFractionInt << 2^14) + SecondFractionFrac]. 104 This field will be used only by HAL_RTC_GetTime function */ 105 uint32_t DayLightSaving; /*!< Specifies DayLight Save Operation. 106 This parameter can be a value of @ref RTC_DayLightSaving_Definitions */ 107 108 uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BCK bit 109 in CR register to store the operation. 110 This parameter can be a value of @ref RTC_StoreOperation_Definitions */ 111 } RTC_TimeTypeDef; 112 113 /** 114 * @brief RTC Date structure definition 115 */ 116 typedef struct 117 { 118 uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. 119 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 120 121 uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). 122 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 123 124 uint8_t Date; /*!< Specifies the RTC Date. 125 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ 126 #define RTC_CENTURY_BIT 0x80 127 uint8_t Year; /*!< Specifies the RTC Date Year as offset of 1900. 128 This parameter must be a number between Min_Data = 0 and Max_Data = 199 129 if Year<70, The year will be 2000+Year, RTC_CENTURY_BIT will be set 130 Other wise, The year will be 1900+Year, RTC_CENTURY_BIT will be clear 131 */ 132 133 } RTC_DateTypeDef; 134 135 /** 136 * @brief RTC Alarm structure definition 137 */ 138 typedef struct 139 { 140 RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ 141 RTC_DateTypeDef AlarmDate; /*!< Specifies the RTC Alarm date members */ 142 143 uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. 144 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 145 146 uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. 147 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ 148 149 uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 150 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 151 152 uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 153 If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range. 154 If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */ 155 156 } RTC_AlarmTypeDef; 157 158 #define RTC_CBK_ALARM 0 159 #define RTC_CBK_WAKEUP 1 160 /** 161 **************************************************************************************** 162 * @brief Call back definition of RTC module 163 * 164 * @param[in] reason Callback reason, should be RTC_CBK_XXX, -1 if unknown reason. 165 **************************************************************************************** 166 */ 167 typedef void (*RTC_cb)(int reason); 168 169 /** 170 * @brief RTC Handle Structure definition 171 */ 172 173 typedef struct 174 { 175 RTC_TypeDef *Instance; /*!< Register base address */ 176 177 RTC_InitTypeDef Init; /*!< RTC required parameters */ 178 179 HAL_LockTypeDef Lock; /*!< RTC locking object */ 180 181 __IO HAL_RTCStateTypeDef State; /*!< Time communication state */ 182 183 RTC_cb callback; /*!< RTC callback*/ 184 185 } RTC_HandleTypeDef; 186 187 /** 188 * @} 189 */ 190 191 /* Exported constants --------------------------------------------------------*/ 192 /** @defgroup RTC_Exported_Constants RTC Exported Constants 193 * @{ 194 */ 195 196 /** @defgroup RTC_Hour_Formats RTC Hour Formats 197 * @{ 198 */ 199 #define RTC_HOURFORMAT_24 0x00000000U 200 #define RTC_HOURFORMAT_12 0x00000040U 201 /** 202 * @} 203 */ 204 205 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions 206 * @{ 207 */ 208 #define RTC_HOURFORMAT12_AM ((uint8_t)0x00) 209 #define RTC_HOURFORMAT12_PM ((uint8_t)0x40) 210 /** 211 * @} 212 */ 213 214 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions 215 * @{ 216 */ 217 #define RTC_DAYLIGHTSAVING_SUB1H 0x00020000U 218 #define RTC_DAYLIGHTSAVING_ADD1H 0x00010000U 219 #define RTC_DAYLIGHTSAVING_NONE 0x00000000U 220 /** 221 * @} 222 */ 223 224 /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions 225 * @{ 226 */ 227 #define RTC_STOREOPERATION_RESET 0x00000000U 228 #define RTC_STOREOPERATION_SET 0x00040000U 229 /** 230 * @} 231 */ 232 233 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions 234 * @{ 235 */ 236 #define RTC_FORMAT_BIN 0x00000000U 237 #define RTC_FORMAT_BCD 0x00000001U 238 /** 239 * @} 240 */ 241 242 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions 243 * @{ 244 */ 245 /* Coded in BCD format */ 246 #define RTC_MONTH_JANUARY ((uint8_t)0x01) 247 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02) 248 #define RTC_MONTH_MARCH ((uint8_t)0x03) 249 #define RTC_MONTH_APRIL ((uint8_t)0x04) 250 #define RTC_MONTH_MAY ((uint8_t)0x05) 251 #define RTC_MONTH_JUNE ((uint8_t)0x06) 252 #define RTC_MONTH_JULY ((uint8_t)0x07) 253 #define RTC_MONTH_AUGUST ((uint8_t)0x08) 254 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09) 255 #define RTC_MONTH_OCTOBER ((uint8_t)0x10) 256 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11) 257 #define RTC_MONTH_DECEMBER ((uint8_t)0x12) 258 /** 259 * @} 260 */ 261 262 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions 263 * @{ 264 */ 265 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01) 266 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02) 267 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03) 268 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04) 269 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05) 270 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06) 271 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07) 272 /** 273 * @} 274 */ 275 276 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions 277 * @{ 278 */ 279 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000U 280 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY 0x40000000U 281 /** 282 * @} 283 */ 284 285 /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions 286 * @{ 287 */ 288 #define RTC_ALARMMASK_NONE 0x00000000U 289 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMDR_MSKWD 290 #define RTC_ALARMMASK_MONTH RTC_ALRMDR_MSKM 291 #define RTC_ALARMMASK_DAY RTC_ALRMDR_MSKD 292 #define RTC_ALARMMASK_SECONDS RTC_ALRMDR_MSKS 293 #define RTC_ALARMMASK_HOURS RTC_ALRMDR_MSKH 294 #define RTC_ALARMMASK_MINUTES RTC_ALRMDR_MSKMN 295 #define RTC_ALARMMASK_ALL 0x3FF00000U 296 /** 297 * @} 298 */ 299 300 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions 301 * @{ 302 */ 303 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U /*!< All Alarm SS fields are masked. 304 There is no comparison on sub seconds 305 for Alarm */ 306 #define RTC_ALARMSUBSECONDMASK_SS14_1 0x01000000U /*!< SS[14:1] are don't care in Alarm 307 comparison. Only SS[0] is compared. */ 308 #define RTC_ALARMSUBSECONDMASK_SS14_2 0x02000000U /*!< SS[14:2] are don't care in Alarm 309 comparison. Only SS[1:0] are compared */ 310 #define RTC_ALARMSUBSECONDMASK_SS14_3 0x03000000U /*!< SS[14:3] are don't care in Alarm 311 comparison. Only SS[2:0] are compared */ 312 #define RTC_ALARMSUBSECONDMASK_SS14_4 0x04000000U /*!< SS[14:4] are don't care in Alarm 313 comparison. Only SS[3:0] are compared */ 314 #define RTC_ALARMSUBSECONDMASK_SS14_5 0x05000000U /*!< SS[14:5] are don't care in Alarm 315 comparison. Only SS[4:0] are compared */ 316 #define RTC_ALARMSUBSECONDMASK_SS14_6 0x06000000U /*!< SS[14:6] are don't care in Alarm 317 comparison. Only SS[5:0] are compared */ 318 #define RTC_ALARMSUBSECONDMASK_SS14_7 0x07000000U /*!< SS[14:7] are don't care in Alarm 319 comparison. Only SS[6:0] are compared */ 320 #define RTC_ALARMSUBSECONDMASK_SS14_8 0x08000000U /*!< SS[14:8] are don't care in Alarm 321 comparison. Only SS[7:0] are compared */ 322 #define RTC_ALARMSUBSECONDMASK_SS14_9 0x09000000U /*!< SS[14:9] are don't care in Alarm 323 comparison. Only SS[8:0] are compared */ 324 #define RTC_ALARMSUBSECONDMASK_SS14_10 0x0A000000U /*!< SS[14:10] are don't care in Alarm 325 comparison. Only SS[9:0] are compared */ 326 #define RTC_ALARMSUBSECONDMASK_SS14_11 0x0B000000U /*!< SS[14:11] are don't care in Alarm 327 comparison. Only SS[10:0] are compared */ 328 #define RTC_ALARMSUBSECONDMASK_SS14_12 0x0C000000U /*!< SS[14:12] are don't care in Alarm 329 comparison.Only SS[11:0] are compared */ 330 #define RTC_ALARMSUBSECONDMASK_SS14_13 0x0D000000U /*!< SS[14:13] are don't care in Alarm 331 comparison. Only SS[12:0] are compared */ 332 #define RTC_ALARMSUBSECONDMASK_SS14 0x0E000000U /*!< SS[14] is don't care in Alarm 333 comparison.Only SS[13:0] are compared */ 334 #define RTC_ALARMSUBSECONDMASK_NONE 0x0F000000U /*!< SS[14:0] are compared and must match 335 to activate alarm. */ 336 /** 337 * @} 338 */ 339 340 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions 341 * @{ 342 */ 343 #define RTC_IT_TS 0x00008000U 344 #define RTC_IT_WUT 0x00004000U 345 #define RTC_IT_ALRB 0x00002000U 346 #define RTC_IT_ALRA 0x00001000U 347 #define RTC_IT_TAMP 0x00000004U /* Used only to Enable the Tamper Interrupt */ 348 #define RTC_IT_TAMP1 0x00020000U 349 #define RTC_IT_TAMP2 0x00040000U 350 /** 351 * @} 352 */ 353 354 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions 355 * @{ 356 */ 357 #define RTC_FLAG_RECALPF 0x00010000U 358 #define RTC_FLAG_TAMP2F 0x00004000U 359 #define RTC_FLAG_TAMP1F 0x00002000U 360 #define RTC_FLAG_TSOVF 0x00001000U 361 #define RTC_FLAG_TSF 0x00000800U 362 #define RTC_FLAG_WUTF 0x00000400U 363 #define RTC_FLAG_ALRBF 0x00000200U 364 #define RTC_FLAG_ALRAF 0x00000100U 365 #define RTC_FLAG_INITF 0x00000040U 366 #define RTC_FLAG_RSF 0x00000020U 367 #define RTC_FLAG_INITS 0x00000010U 368 #define RTC_FLAG_SHPF 0x00000008U 369 #define RTC_FLAG_WUTWF 0x00000004U 370 #define RTC_FLAG_ALRBWF 0x00000002U 371 #define RTC_FLAG_ALRAWF 0x00000001U 372 /** 373 * @} 374 */ 375 376 /** @defgroup RTC_Wakeup_Clock RTC wakeup clock selection 377 * @{ 378 */ 379 #define RTC_WAKEUP_SEC 0x00000000U // From Prescalar B 380 #define RTC_WAKEUP_SUBSEC 0x00000001U // From Prescalar A 381 /** 382 * @} 383 */ 384 385 386 /** 387 * @} 388 */ 389 390 /* Exported macro ------------------------------------------------------------*/ 391 /** @defgroup RTC_Exported_Macros RTC Exported Macros 392 * @{ 393 */ 394 395 /** @brief Reset RTC handle state 396 * @param \__HANDLE__ specifies the RTC handle. 397 * @retval None 398 */ 399 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) 400 401 /** 402 * @brief Enable the RTC ALARM peripheral. 403 * @param \__HANDLE__ specifies the RTC handle. 404 * @retval None 405 */ 406 #define __HAL_RTC_ALARM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRME)) 407 408 /** 409 * @brief Disable the RTC ALARM peripheral. 410 * @param \__HANDLE__ specifies the RTC handle. 411 * @retval None 412 */ 413 #define __HAL_RTC_ALARM_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRME)) 414 415 /** 416 * @brief Enable the RTC Alarm interrupt. 417 * @param \__HANDLE__ specifies the RTC handle. 418 * @retval None 419 */ 420 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRMIE)) 421 422 /** 423 * @brief Disable the RTC Alarm interrupt. 424 * @param \__HANDLE__ specifies the RTC handle. 425 * @retval None 426 */ 427 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRMIE)) 428 429 /** 430 * @brief Check whether the specified RTC Alarm interrupt has occurred or not. 431 * @param \__HANDLE__ specifies the RTC handle. 432 433 * @retval None 434 */ 435 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__) (((((__HANDLE__)->Instance->ISR)& RTC_ISR_ALRMF) != RESET)? SET : RESET) 436 437 /** 438 * @brief Get the selected RTC Alarm's flag status. 439 * @param \__HANDLE__ specifies the RTC handle. 440 * @param \__FLAG__ specifies the RTC Alarm Flag to check. 441 * This parameter can be: 442 * @arg RTC_ISR_ALRMF 443 * @arg RTC_ISR_ALRMWF 444 * @retval None 445 */ 446 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET) 447 448 /** 449 * @brief Clear the RTC Alarm's pending flags. 450 * @param \__HANDLE__ specifies the RTC handle. 451 * @param \__FLAG__ specifies the RTC Alarm Flag sources to be enabled or disabled. 452 * This parameter can be: 453 * @arg RTC_FLAG_ALRAF 454 * @arg RTC_FLAG_ALRBF 455 * @retval None 456 */ 457 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) 458 459 460 /** 461 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not. 462 * @param \__HANDLE__ specifies the RTC handle. 463 * @param \__INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 464 * This parameter can be: 465 * @arg RTC_IT_ALRA: Alarm A interrupt 466 * @arg RTC_IT_ALRB: Alarm B interrupt 467 * @retval None 468 */ 469 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET) 470 471 /** 472 * @brief Enable interrupt on the RTC Alarm associated Exti line. 473 * @retval None 474 */ 475 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT) 476 477 /** 478 * @brief Disable interrupt on the RTC Alarm associated Exti line. 479 * @retval None 480 */ 481 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 482 483 /** 484 * @brief Enable event on the RTC Alarm associated Exti line. 485 * @retval None. 486 */ 487 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT) 488 489 /** 490 * @brief Disable event on the RTC Alarm associated Exti line. 491 * @retval None. 492 */ 493 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 494 495 /** 496 * @brief Enable falling edge trigger on the RTC Alarm associated Exti line. 497 * @retval None. 498 */ 499 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT) 500 501 /** 502 * @brief Disable falling edge trigger on the RTC Alarm associated Exti line. 503 * @retval None. 504 */ 505 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 506 507 /** 508 * @brief Enable rising edge trigger on the RTC Alarm associated Exti line. 509 * @retval None. 510 */ 511 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT) 512 513 /** 514 * @brief Disable rising edge trigger on the RTC Alarm associated Exti line. 515 * @retval None. 516 */ 517 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 518 519 /** 520 * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line. 521 * @retval None. 522 */ 523 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \ 524 __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE();\ 525 } while(0U) 526 527 /** 528 * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line. 529 * @retval None. 530 */ 531 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();\ 532 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE();\ 533 } while(0U) 534 535 /** 536 * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not. 537 * @retval Line Status. 538 */ 539 #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT) 540 541 /** 542 * @brief Clear the RTC Alarm associated Exti line flag. 543 * @retval None. 544 */ 545 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT) 546 547 /** 548 * @brief Generate a Software interrupt on RTC Alarm associated Exti line. 549 * @retval None. 550 */ 551 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT) 552 553 /** 554 * @brief Get the selected RTC WakeUpTimer's flag status. 555 * @param \__HANDLE__ specifies the RTC handle. 556 * @param \__FLAG__ specifies the RTC WakeUpTimer Flag to check. 557 * This parameter can be: 558 * @arg RTC_FLAG_WUTF 559 * @arg RTC_FLAG_WUTWF 560 * @retval None 561 */ 562 #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET) 563 564 /** 565 * @brief Enable the RTC WakeUp Timer peripheral. 566 * @param \__HANDLE__ specifies the RTC handle. 567 * @retval None 568 */ 569 #define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_WUTE)) 570 571 /** 572 * @brief Disable the RTC Wake-up Timer peripheral. 573 * @param \__HANDLE__ specifies the RTC handle. 574 * @retval None 575 */ 576 #define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_WUTE)) 577 578 579 /** 580 * @brief Enable the RTC WakeUpTimer interrupt. 581 * @param \__HANDLE__ specifies the RTC handle. 582 * @retval None 583 */ 584 585 #define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_WUTIE)) 586 587 /** 588 * @brief Disable the RTC Alarm interrupt. 589 * @param \__HANDLE__ specifies the RTC handle. 590 * @retval None 591 */ 592 #define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_WUTIE)) 593 594 /** 595 * @brief Check whether the specified RTC WakeUpTimer interrupt has occurred or not. 596 * @param \__HANDLE__ specifies the RTC handle. 597 * @retval None 598 */ 599 #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__) (((((__HANDLE__)->Instance->ISR)& RTC_ISR_WUTF) != RESET)? SET : RESET) 600 601 /** 602 * @brief Clear the RTC Wake Up timer's pending flags. 603 * @param \__HANDLE__ specifies the RTC handle. 604 * @param \__FLAG__ specifies the RTC Tamper Flag sources to be enabled or disabled. 605 * This parameter can be: 606 * @arg RTC_FLAG_WUTF 607 * @retval None 608 */ 609 #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) 610 611 612 #ifdef hwp_pbr 613 #ifdef SF32LB58X 614 #define HAL_PBR_MAX (5) 615 #elif defined SF32LB56X 616 #define HAL_PBR_MAX (3) 617 #else 618 #define HAL_PBR_MAX (3) 619 #endif 620 #endif /* hwp_pbr */ 621 622 #ifdef SF32LB52X 623 #define HAL_RTC_LXT_ENABLED() (hwp_rtc->CR&RTC_CR_LPCKSEL) 624 #define HAL_RTC_ENABLE_LXT() hwp_rtc->CR |= RTC_CR_LPCKSEL 625 #else 626 #define HAL_RTC_LXT_ENABLED() HAL_PMU_LXT_ENABLED() 627 #define HAL_RTC_ENABLE_LXT() 628 #endif /* SF32LB52X */ 629 630 /** 631 * @} 632 */ 633 634 /* Include RTC HAL Extension module */ 635 #include "bf0_hal_rtc_ex.h" 636 637 /* Exported functions --------------------------------------------------------*/ 638 /** @addtogroup RTC_Exported_Functions 639 * @{ 640 */ 641 642 /** @addtogroup RTC_Exported_Functions_Group1 643 * @{ 644 */ 645 /* Initialization and de-initialization functions ****************************/ 646 647 #define RTC_INIT_NORMAL 0 // Normal Init 648 #define RTC_INIT_SKIP 1 // Skip RTC hardware init 649 #define RTC_INIT_REINIT 2 // RTC Reinit, should not clear Alarm and wakeup timer 650 651 /** 652 * @brief Initializes the RTC peripheral 653 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 654 * the configuration information for RTC. 655 * @param wakesrc wakeup source, see RTC_INIT_XXX 656 * @retval HAL status 657 */ 658 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc, uint32_t wakesrc); 659 /** 660 * @brief DeInitializes the RTC peripheral 661 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 662 * the configuration information for RTC. 663 * @note This function doesn't reset the RTC Backup Data registers. 664 * @retval HAL status 665 */ 666 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); 667 /** 668 * @brief Initializes the RTC MSP. 669 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 670 * the configuration information for RTC. 671 * @retval None 672 */ 673 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); 674 /** 675 * @brief DeInitializes the RTC MSP. 676 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 677 * the configuration information for RTC. 678 * @retval None 679 */ 680 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); 681 /** 682 * @} 683 */ 684 685 /** @addtogroup RTC_Exported_Functions_Group2 686 * @{ 687 */ 688 /* RTC Time and Date functions ************************************************/ 689 /** 690 * @brief Sets RTC current time. 691 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 692 * the configuration information for RTC. 693 * @param sTime Pointer to Time structure 694 * @param Format Specifies the format of the entered parameters. 695 * This parameter can be one of the following values: 696 * @arg RTC_FORMAT_BIN: Binary data format 697 * @arg RTC_FORMAT_BCD: BCD data format 698 * @retval HAL status 699 */ 700 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 701 702 /** 703 * @brief Gets RTC current time. 704 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 705 * the configuration information for RTC. 706 * @param sTime Pointer to Time structure 707 * @param Format Specifies the format of the entered parameters. 708 * This parameter can be one of the following values: 709 * @arg RTC_FORMAT_BIN: Binary data format 710 * @arg RTC_FORMAT_BCD: BCD data format 711 * @note You can use SubSeconds and SecondFraction (sTime structure fields returned) to convert SubSeconds 712 * value in second fraction ratio with time unit following generic formula: 713 * Second fraction ratio * time_unit= [(SecondFraction-SubSeconds)/(SecondFraction+1)] * time_unit 714 * This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS 715 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values 716 * in the higher-order calendar shadow registers to ensure consistency between the time and date values. 717 * Reading RTC current time locks the values in calendar shadow registers until current date is read. 718 * @retval HAL status 719 */ 720 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 721 /** 722 * @brief Sets RTC current date. 723 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 724 * the configuration information for RTC. 725 * @param sDate Pointer to date structure 726 * @param Format specifies the format of the entered parameters. 727 * This parameter can be one of the following values: 728 * @arg RTC_FORMAT_BIN: Binary data format 729 * @arg RTC_FORMAT_BCD: BCD data format 730 * @retval HAL status 731 */ 732 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 733 /** 734 * @brief Gets RTC current date. 735 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 736 * the configuration information for RTC. 737 * @param sDate Pointer to Date structure 738 * @param Format Specifies the format of the entered parameters. 739 * This parameter can be one of the following values: 740 * @arg RTC_FORMAT_BIN: Binary data format 741 * @arg RTC_FORMAT_BCD: BCD data format 742 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values 743 * in the higher-order calendar shadow registers to ensure consistency between the time and date values. 744 * Reading RTC current time locks the values in calendar shadow registers until Current date is read. 745 * @retval HAL status 746 */ 747 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 748 749 /** 750 * @brief Increase/Decrease RTC by 1 second.. 751 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 752 * the configuration information for RTC. 753 * @param increase >0: increase, <0:decrease, 0 no change 754 * @retval HAL status 755 */ 756 HAL_StatusTypeDef HAL_RTC_IncOneSecond(RTC_HandleTypeDef *hrtc, int32_t increase); 757 758 /** 759 * @} 760 */ 761 762 /** @addtogroup RTC_Exported_Functions_Group3 763 * @{ 764 */ 765 /* RTC Alarm functions ********************************************************/ 766 /** 767 * @brief Sets the specified RTC Alarm. 768 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 769 * the configuration information for RTC. 770 * @param sAlarm Pointer to Alarm structure 771 * @param Format Specifies the format of the entered parameters. 772 * This parameter can be one of the following values: 773 * @arg RTC_FORMAT_BIN: Binary data format 774 * @arg RTC_FORMAT_BCD: BCD data format 775 * @retval HAL status 776 */ 777 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 778 779 /** 780 * @brief Sets the specified RTC Alarm. 781 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 782 * the configuration information for RTC. 783 * @param sAlarm Pointer to Alarm structure 784 * @param Format Specifies the format of the entered parameters. 785 * This parameter can be one of the following values: 786 * @arg RTC_FORMAT_BIN: Binary data format 787 * @arg RTC_FORMAT_BCD: BCD data format 788 * @retval HAL status 789 */ 790 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 791 /** 792 * @brief Deactivate the specified RTC Alarm 793 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 794 * the configuration information for RTC. 795 * @retval HAL status 796 */ 797 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc); 798 /** 799 * @brief Gets the RTC Alarm value and masks. 800 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 801 * the configuration information for RTC. 802 * @param sAlarm Pointer to Date structure 803 * @param Format Specifies the format of the entered parameters. 804 * This parameter can be one of the following values: 805 * @arg RTC_FORMAT_BIN: Binary data format 806 * @arg RTC_FORMAT_BCD: BCD data format 807 * @retval HAL status 808 */ 809 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 810 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); 811 812 /** 813 * @brief This function handles AlarmA Polling request. 814 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 815 * the configuration information for RTC. 816 * @param Timeout Timeout duration 817 * @retval HAL status 818 */ 819 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 820 /** 821 * @brief Alarm A callback. 822 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 823 * the configuration information for RTC. 824 * @retval None 825 */ 826 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); 827 /** 828 * @brief Sets wake up timer with interrupt 829 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 830 * the configuration information for RTC. 831 * @param WakeUpCounter Wake up counter 832 * @param WakeUpClock Wake up clock, see @ref RTC_Wakeup_Clock 833 * @retval HAL status 834 */ 835 HAL_StatusTypeDef HAL_RTC_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock); 836 /** 837 * @brief Deactivates wake up timer counter. 838 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 839 * the configuration information for RTC. 840 * @retval HAL status 841 */ 842 uint32_t HAL_RTC_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc); 843 /** 844 * @brief Gets wake up timer counter. 845 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 846 * the configuration information for RTC. 847 * @retval Counter value 848 */ 849 uint32_t HAL_RTC_GetWakeUpTimer(RTC_HandleTypeDef *hrtc); 850 /** 851 * @brief Wakeup Timer callback. 852 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 853 * the configuration information for RTC. 854 * @retval None 855 */ 856 void HAL_RTC_WakeupTimerEventCallback(RTC_HandleTypeDef *hrtc); 857 /** 858 * @brief This function handles Alarm interrupt request. 859 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 860 * the configuration information for RTC. 861 * @retval None 862 */ 863 void HAL_RTC_IRQHandler(RTC_HandleTypeDef *hrtc); 864 865 866 867 /** 868 * @} 869 */ 870 871 /** @addtogroup RTC_Exported_Functions_Group4 872 * @{ 873 */ 874 /* Peripheral Control functions ***********************************************/ 875 /** 876 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are 877 * synchronized with RTC APB clock. 878 * @note To read the calendar through the shadow registers after Calendar 879 * initialization, calendar update or after wake-up from low power modes 880 * the software must first clear the RSF flag. 881 * The software must then wait until it is set again before reading 882 * the calendar, which means that the calendar registers have been 883 * correctly copied into the RTC_TR and RTC_DR shadow registers. 884 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 885 * the configuration information for RTC. 886 * @retval HAL status 887 */ 888 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc); 889 /** 890 * @} 891 */ 892 893 /** @addtogroup RTC_Exported_Functions_Group5 894 * @{ 895 */ 896 /* Peripheral State functions *************************************************/ 897 /** 898 * @brief Returns the RTC state. 899 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 900 * the configuration information for RTC. 901 * @retval HAL state 902 */ 903 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc); 904 905 /** 906 * @brief Set the RTC backup register. 907 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 908 * the configuration information for RTC. 909 * @param idx index of backup register 910 * @param value value to set into backup register 911 * @retval None 912 */ 913 void HAL_RTC_set_backup(RTC_HandleTypeDef *hrtc, uint8_t idx, uint32_t value); 914 915 /** 916 * @brief get the RTC backup register value. 917 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 918 * the configuration information for RTC. 919 * @param idx index of backup register 920 * @retval value saved in the backup register 921 */ 922 uint32_t HAL_RTC_get_backup(RTC_HandleTypeDef *hrtc, uint8_t idx); 923 924 925 /** 926 * @brief Register call back functions for RTC module. 927 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 928 * the configuration information for RTC. 929 * @param cbk callback function to be registered. 930 * @retval None 931 */ 932 void HAL_RTC_RegCallback(RTC_HandleTypeDef *hrtc, RTC_cb cbk); 933 934 /** 935 * @brief config PBR pin mode 936 * @param[in] pin PBR pin index, starting from 0 937 * @param[in] output_en true: output mode, false: input mode 938 * @retval HAL status 939 */ 940 HAL_StatusTypeDef HAL_PBR_ConfigMode(uint8_t pin, bool output_en); 941 942 /** 943 * @brief Read PBR pin state 944 * @param[in] pin PBR pin index, starting from 0 945 * 946 * @retval 0 and 1 are valid value, if less than 0, some error happens, e.g. pin is invalid 947 */ 948 int8_t HAL_PBR_ReadPin(uint8_t pin); 949 950 /** 951 * @brief Set PBR pin state 952 * @param[in] pin PBR pin index, starting from 0 953 * @param[in] state pin state, 0 and 1 are valid vallue 954 * 955 * @retval HAL status 956 */ 957 HAL_StatusTypeDef HAL_PBR_WritePin(uint8_t pin, uint8_t state); 958 959 /** 960 * @brief Get PBR pin mode 961 * @param[in] pin PBR pin index, starting from 0 962 * @param[in,out] output_en pointer to pin mode, true: output mode, false: input mode 963 * 964 * @retval HAL status 965 */ 966 HAL_StatusTypeDef HAL_PBR_GetMode(uint8_t pin, bool *output_en); 967 968 969 #define HAL_PBR0_FORCE1_ENABLE() (hwp_rtc->PBR0R |= RTC_PBR0R_FORCE1) 970 #define HAL_PBR0_FORCE1_DISABLE() (hwp_rtc->PBR0R &= ~RTC_PBR0R_FORCE1) 971 972 /** 973 * @} 974 */ 975 976 /** 977 * @} 978 */ 979 980 /* Private types -------------------------------------------------------------*/ 981 /* Private variables ---------------------------------------------------------*/ 982 /* Private constants ---------------------------------------------------------*/ 983 /** @defgroup RTC_Private_Constants RTC Private Constants 984 * @{ 985 */ 986 /* Masks Definition */ 987 #define RTC_TR_RESERVED_MASK 0x007F7F7FU 988 #define RTC_DR_RESERVED_MASK 0x01FFFF3FU 989 #define RTC_INIT_MASK 0xFFFFFFFFU 990 #define RTC_RSF_MASK 0xFFFFFF5FU 991 #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \ 992 RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \ 993 RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \ 994 RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F | \ 995 RTC_FLAG_RECALPF | RTC_FLAG_SHPF)) 996 997 #define RTC_TIMEOUT_VALUE 1000 998 999 #define RTC_EXTI_LINE_ALARM_EVENT ((uint32_t)EXTI_IMR_MR17) /*!< External interrupt line 17 Connected to the RTC Alarm event */ 1000 /** 1001 * @} 1002 */ 1003 1004 /* Private macros ------------------------------------------------------------*/ 1005 /** @defgroup RTC_Private_Macros RTC Private Macros 1006 * @{ 1007 */ 1008 1009 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters 1010 * @{ 1011 */ 1012 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \ 1013 ((FORMAT) == RTC_HOURFORMAT_24)) 1014 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \ 1015 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \ 1016 ((OUTPUT) == RTC_OUTPUT_ALARMB) || \ 1017 ((OUTPUT) == RTC_OUTPUT_WAKEUP)) 1018 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \ 1019 ((POL) == RTC_OUTPUT_POLARITY_LOW)) 1020 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \ 1021 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL)) 1022 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U)) 1023 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U) 1024 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU) 1025 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFFU) 1026 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U) 1027 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U) 1028 1029 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || ((PM) == RTC_HOURFORMAT12_PM)) 1030 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \ 1031 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \ 1032 ((SAVE) == RTC_DAYLIGHTSAVING_NONE)) 1033 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \ 1034 ((OPERATION) == RTC_STOREOPERATION_SET)) 1035 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD)) 1036 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U) 1037 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U)) 1038 #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U)) 1039 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 1040 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 1041 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 1042 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 1043 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 1044 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 1045 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 1046 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U)) 1047 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 1048 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 1049 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 1050 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 1051 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 1052 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 1053 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 1054 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ 1055 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) 1056 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7FU) == (uint32_t)RESET) 1057 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B)) 1058 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFFU) 1059 1060 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \ 1061 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \ 1062 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \ 1063 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \ 1064 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \ 1065 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \ 1066 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \ 1067 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \ 1068 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \ 1069 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \ 1070 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \ 1071 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \ 1072 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \ 1073 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \ 1074 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \ 1075 ((MASK) == RTC_ALARMSUBSECONDMASK_NONE)) 1076 /** 1077 * @} 1078 */ 1079 1080 /** 1081 * @} 1082 */ 1083 1084 /* Private functions ---------------------------------------------------------*/ 1085 /** @defgroup RTC_Private_Functions RTC Private Functions 1086 * @{ 1087 */ 1088 /** 1089 * @brief Enters the RTC Initialization mode. 1090 * @note The RTC Initialization mode is write protected, use the 1091 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. 1092 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains 1093 * the configuration information for RTC. 1094 * @retval HAL status 1095 */ 1096 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc); 1097 1098 /** 1099 * @brief Converts a 2 digit decimal to BCD format. 1100 * @param Value Byte to be converted 1101 * @retval Converted byte 1102 */ 1103 uint8_t RTC_ByteToBcd2(uint8_t Value); 1104 1105 /** 1106 * @brief Converts from 2 digit BCD to Binary. 1107 * @param Value BCD value to be converted 1108 * @retval Converted word 1109 */ 1110 uint8_t RTC_Bcd2ToByte(uint8_t Value); 1111 /** 1112 * @} 1113 */ 1114 1115 /** 1116 * @} 1117 */ 1118 1119 /** 1120 * @} 1121 */ 1122 1123 #ifdef __cplusplus 1124 } 1125 #endif 1126 1127 #endif /* __BF0_HAL_RTC_H */