/** * @brief Set current time. * @note Fractional part will be silently ignored. There is no possibility * to change it on STM32F1xx platform. * * @param[in] rtcp pointer to RTC driver structure * @param[in] timespec pointer to a @p RTCTime structure * * @notapi */ void rtc_lld_set_time(RTCDriver *rtcp, const RTCTime *timespec) { (void)rtcp; rtc_lld_acquire(); RTC->CNTH = (uint16_t)(timespec->tv_sec >> 16); RTC->CNTL = (uint16_t)(timespec->tv_sec & 0xFFFF); rtc_lld_release(); }
/** * @brief Set alarm time. * * @note Default value after BKP domain reset is 0xFFFFFFFF * * @param[in] rtcp pointer to RTC driver structure * @param[in] alarm alarm identifier * @param[in] alarmspec pointer to a @p RTCAlarm structure * * @notapi */ void rtc_lld_set_alarm(RTCDriver *rtcp, rtcalarm_t alarm, const RTCAlarm *alarmspec) { (void)rtcp; (void)alarm; rtc_lld_acquire(); if (alarmspec != NULL) { RTC->ALRH = (uint16_t)(alarmspec->tv_sec >> 16); RTC->ALRL = (uint16_t)(alarmspec->tv_sec & 0xFFFF); }
/** * @brief Enable access to registers and initialize RTC if BKP domain * was previously reseted. * @note: Cold start time of LSE oscillator on STM32 platform * takes about 3 seconds. * * @notapi */ void rtc_lld_init(void){ /* Required because access to PRL.*/ rtc_lld_apb1_sync(); /* Writes preload register only if its value is not equal to desired value.*/ if (STM32_RTCCLK != (((uint32_t)(RTC->PRLH)) << 16) + ((uint32_t)RTC->PRLL) + 1) { rtc_lld_acquire(); RTC->PRLH = (uint16_t)((STM32_RTCCLK - 1) >> 16); RTC->PRLL = (uint16_t)((STM32_RTCCLK - 1) & 0xFFFF); rtc_lld_release(); }
/** * @brief Load value of RTCCLK to prescaler registers. * @note The pre-scaler must not be set on every reset as RTC clock * counts are lost when it is set. * @note This function designed to be called from * hal_lld_backup_domain_init(). Because there is only place * where possible to detect BKP domain reset event reliably. * * @notapi */ void rtc_lld_set_prescaler(void){ rtc_lld_acquire(); RTC->PRLH = (uint16_t)((STM32_RTCCLK - 1) >> 16) & 0x000F; RTC->PRLL = (uint16_t)(((STM32_RTCCLK - 1)) & 0xFFFF); rtc_lld_release(); }