Lines Matching full:rtc

17 #include <zephyr/drivers/rtc.h>
50 /* RTC start time: 1st, Jan, 2000 */
87 /* Zephyr mask supported by RTC device, values from RTC_ALARM_TIME_MASK */
102 * After system reset, the RTC registers are protected against parasitic write access by the
104 * Hence, DBP bit must be set in order to enable RTC registers write access.
148 uint32_t hour_format = LL_RTC_GetHourFormat(RTC); in rtc_stm32_configure()
149 uint32_t sync_prescaler = LL_RTC_GetSynchPrescaler(RTC); in rtc_stm32_configure()
150 uint32_t async_prescaler = LL_RTC_GetAsynchPrescaler(RTC); in rtc_stm32_configure()
152 LL_RTC_DisableWriteProtection(RTC); in rtc_stm32_configure()
154 /* configuration process requires to stop the RTC counter so do it in rtc_stm32_configure()
160 ErrorStatus status = LL_RTC_EnterInitMode(RTC); in rtc_stm32_configure()
163 LL_RTC_SetHourFormat(RTC, LL_RTC_HOURFORMAT_24HOUR); in rtc_stm32_configure()
164 LL_RTC_SetSynchPrescaler(RTC, cfg->sync_prescaler); in rtc_stm32_configure()
165 LL_RTC_SetAsynchPrescaler(RTC, cfg->async_prescaler); in rtc_stm32_configure()
170 LL_RTC_DisableInitMode(RTC); in rtc_stm32_configure()
174 LL_RTC_CAL_SetOutputFreq(RTC, cfg->cal_out_freq); in rtc_stm32_configure()
176 LL_RTC_CAL_SetOutputFreq(RTC, LL_RTC_CALIB_OUTPUT_NONE); in rtc_stm32_configure()
180 LL_RTC_EnableShadowRegBypass(RTC); in rtc_stm32_configure()
183 LL_RTC_EnableWriteProtection(RTC); in rtc_stm32_configure()
189 static inline ErrorStatus rtc_stm32_init_alarm(RTC_TypeDef *rtc, uint32_t format, in rtc_stm32_init_alarm() argument
194 * RTC write protection is disabled & enabled again inside LL_RTC_ALMx_Init functions in rtc_stm32_init_alarm()
198 return LL_RTC_ALMA_Init(rtc, format, ll_alarm_struct); in rtc_stm32_init_alarm()
202 return LL_RTC_ALMB_Init(rtc, format, ll_alarm_struct); in rtc_stm32_init_alarm()
209 static inline void rtc_stm32_clear_alarm_flag(RTC_TypeDef *rtc, uint16_t id) in rtc_stm32_clear_alarm_flag() argument
212 LL_RTC_ClearFlag_ALRA(rtc); in rtc_stm32_clear_alarm_flag()
217 LL_RTC_ClearFlag_ALRB(rtc); in rtc_stm32_clear_alarm_flag()
222 static inline uint32_t rtc_stm32_is_active_alarm(RTC_TypeDef *rtc, uint16_t id) in rtc_stm32_is_active_alarm() argument
225 return LL_RTC_IsActiveFlag_ALRA(rtc); in rtc_stm32_is_active_alarm()
229 return LL_RTC_IsActiveFlag_ALRB(rtc); in rtc_stm32_is_active_alarm()
236 static inline void rtc_stm32_enable_interrupt_alarm(RTC_TypeDef *rtc, uint16_t id) in rtc_stm32_enable_interrupt_alarm() argument
239 LL_RTC_EnableIT_ALRA(rtc); in rtc_stm32_enable_interrupt_alarm()
244 LL_RTC_EnableIT_ALRB(rtc); in rtc_stm32_enable_interrupt_alarm()
249 static inline void rtc_stm32_disable_interrupt_alarm(RTC_TypeDef *rtc, uint16_t id) in rtc_stm32_disable_interrupt_alarm() argument
252 LL_RTC_DisableIT_ALRA(rtc); in rtc_stm32_disable_interrupt_alarm()
257 LL_RTC_DisableIT_ALRB(rtc); in rtc_stm32_disable_interrupt_alarm()
262 static inline void rtc_stm32_enable_alarm(RTC_TypeDef *rtc, uint16_t id) in rtc_stm32_enable_alarm() argument
265 LL_RTC_ALMA_Enable(rtc); in rtc_stm32_enable_alarm()
270 LL_RTC_ALMB_Enable(rtc); in rtc_stm32_enable_alarm()
275 static inline void rtc_stm32_disable_alarm(RTC_TypeDef *rtc, uint16_t id) in rtc_stm32_disable_alarm() argument
278 LL_RTC_ALMA_Disable(rtc); in rtc_stm32_disable_alarm()
283 LL_RTC_ALMB_Disable(rtc); in rtc_stm32_disable_alarm()
299 if (rtc_stm32_is_active_alarm(RTC, (uint16_t)id) != 0) { in rtc_stm32_isr()
300 LL_RTC_DisableWriteProtection(RTC); in rtc_stm32_isr()
301 rtc_stm32_clear_alarm_flag(RTC, (uint16_t)id); in rtc_stm32_isr()
302 LL_RTC_EnableWriteProtection(RTC); in rtc_stm32_isr()
347 /* Enable RTC bus clock */ in rtc_stm32_init()
361 /* Must be configured before selecting the RTC clock source */ in rtc_stm32_init()
364 /* Enable RTC clock source */ in rtc_stm32_init()
371 * On STM32WBAX series, there is no bit in BCDR register to enable RTC. in rtc_stm32_init()
372 * Enabling RTC is done directly via the RCC APB register bit. in rtc_stm32_init()
411 /* RTC does not support years before 2000 */ in rtc_stm32_set_time()
435 LL_RTC_TIME_Init(RTC, LL_RTC_FORMAT_BCD, &rtc_time); in rtc_stm32_set_time()
445 LL_RTC_DATE_Init(RTC, LL_RTC_FORMAT_BCD, &rtc_date); in rtc_stm32_set_time()
456 while (LL_RTC_IsActiveFlag_RS(RTC) != 1) { in rtc_stm32_set_time()
464 LL_RTC_DATE_GetDay(RTC), in rtc_stm32_set_time()
465 LL_RTC_DATE_GetMonth(RTC), in rtc_stm32_set_time()
466 LL_RTC_DATE_GetYear(RTC), in rtc_stm32_set_time()
467 LL_RTC_TIME_GetHour(RTC), in rtc_stm32_set_time()
468 LL_RTC_TIME_GetMinute(RTC), in rtc_stm32_set_time()
469 LL_RTC_TIME_GetSecond(RTC) in rtc_stm32_set_time()
497 if (!LL_RTC_IsActiveFlag_INITS(RTC)) { in rtc_stm32_get_time()
510 rtc_date = LL_RTC_DATE_Get(RTC); in rtc_stm32_get_time()
515 rtc_time = LL_RTC_TIME_Get(RTC); in rtc_stm32_get_time()
517 rtc_subsecond = LL_RTC_TIME_GetSubSecond(RTC); in rtc_stm32_get_time()
519 } while (rtc_time != LL_RTC_TIME_Get(RTC)); in rtc_stm32_get_time()
520 } while (rtc_date != LL_RTC_DATE_Get(RTC)); in rtc_stm32_get_time()
524 /* tm_year is the value since 1900 and Rtc year is from 2000 */ in rtc_stm32_get_time()
575 * STM32 RTC Alarm LL mask should be set for all fields beyond the broadest one in rtc_stm32_init_ll_alrm_struct()
576 * that's being matched with RTC calendar to trigger alarm periodically, in rtc_stm32_init_ll_alrm_struct()
577 * the opposite of Zephyr RTC Alarm mask which is set for active fields. in rtc_stm32_init_ll_alrm_struct()
624 timeptr->tm_sec = bcd2bin(LL_RTC_ALMA_GetSecond(RTC)); in rtc_stm32_get_ll_alrm_time()
625 timeptr->tm_min = bcd2bin(LL_RTC_ALMA_GetMinute(RTC)); in rtc_stm32_get_ll_alrm_time()
626 timeptr->tm_hour = bcd2bin(LL_RTC_ALMA_GetHour(RTC)); in rtc_stm32_get_ll_alrm_time()
627 timeptr->tm_wday = bcd2bin(LL_RTC_ALMA_GetWeekDay(RTC)); in rtc_stm32_get_ll_alrm_time()
628 timeptr->tm_mday = bcd2bin(LL_RTC_ALMA_GetDay(RTC)); in rtc_stm32_get_ll_alrm_time()
633 timeptr->tm_sec = bcd2bin(LL_RTC_ALMB_GetSecond(RTC)); in rtc_stm32_get_ll_alrm_time()
634 timeptr->tm_min = bcd2bin(LL_RTC_ALMB_GetMinute(RTC)); in rtc_stm32_get_ll_alrm_time()
635 timeptr->tm_hour = bcd2bin(LL_RTC_ALMB_GetHour(RTC)); in rtc_stm32_get_ll_alrm_time()
636 timeptr->tm_wday = bcd2bin(LL_RTC_ALMB_GetWeekDay(RTC)); in rtc_stm32_get_ll_alrm_time()
637 timeptr->tm_mday = bcd2bin(LL_RTC_ALMB_GetDay(RTC)); in rtc_stm32_get_ll_alrm_time()
649 * STM32 RTC Alarm LL mask is set for all fields beyond the broadest one in rtc_stm32_get_ll_alrm_mask()
650 * that's being matched with RTC calendar to trigger alarm periodically, in rtc_stm32_get_ll_alrm_mask()
651 * the opposite of Zephyr RTC Alarm mask which is set for active fields. in rtc_stm32_get_ll_alrm_mask()
655 ll_alarm_mask = LL_RTC_ALMA_GetMask(RTC); in rtc_stm32_get_ll_alrm_mask()
660 ll_alarm_mask = LL_RTC_ALMB_GetMask(RTC); in rtc_stm32_get_ll_alrm_mask()
675 week_day = LL_RTC_ALMA_GetWeekDay(RTC); in rtc_stm32_get_ll_alrm_mask()
679 week_day = LL_RTC_ALMB_GetWeekDay(RTC); in rtc_stm32_get_ll_alrm_mask()
786 if (rtc_stm32_is_active_alarm(RTC, id)) { in rtc_stm32_alarm_set_time()
787 LL_RTC_DisableWriteProtection(RTC); in rtc_stm32_alarm_set_time()
788 rtc_stm32_disable_alarm(RTC, id); in rtc_stm32_alarm_set_time()
789 rtc_stm32_disable_interrupt_alarm(RTC, id); in rtc_stm32_alarm_set_time()
790 LL_RTC_EnableWriteProtection(RTC); in rtc_stm32_alarm_set_time()
831 /* Disable the write protection for RTC registers */ in rtc_stm32_alarm_set_time()
832 LL_RTC_DisableWriteProtection(RTC); in rtc_stm32_alarm_set_time()
835 rtc_stm32_disable_alarm(RTC, id); in rtc_stm32_alarm_set_time()
836 rtc_stm32_disable_interrupt_alarm(RTC, id); in rtc_stm32_alarm_set_time()
840 /* Wait till RTC ALRAWF flag is set before writing to RTC registers */ in rtc_stm32_alarm_set_time()
841 while (!LL_RTC_IsActiveFlag_ALRAW(RTC)) { in rtc_stm32_alarm_set_time()
849 /* Wait till RTC ALRBWF flag is set before writing to RTC registers */ in rtc_stm32_alarm_set_time()
850 while (!LL_RTC_IsActiveFlag_ALRBW(RTC)) { in rtc_stm32_alarm_set_time()
858 if (rtc_stm32_init_alarm(RTC, LL_RTC_FORMAT_BCD, p_ll_rtc_alarm, id) != SUCCESS) { in rtc_stm32_alarm_set_time()
864 /* Disable the write protection for RTC registers */ in rtc_stm32_alarm_set_time()
865 LL_RTC_DisableWriteProtection(RTC); in rtc_stm32_alarm_set_time()
868 rtc_stm32_enable_alarm(RTC, id); in rtc_stm32_alarm_set_time()
870 rtc_stm32_clear_alarm_flag(RTC, id); in rtc_stm32_alarm_set_time()
872 rtc_stm32_enable_interrupt_alarm(RTC, id); in rtc_stm32_alarm_set_time()
876 /* Enable the write protection for RTC registers */ in rtc_stm32_alarm_set_time()
877 LL_RTC_EnableWriteProtection(RTC); in rtc_stm32_alarm_set_time()
889 LL_RTC_ALMA_GetHour(RTC), in rtc_stm32_alarm_set_time()
890 LL_RTC_ALMA_GetMinute(RTC), in rtc_stm32_alarm_set_time()
891 LL_RTC_ALMA_GetSecond(RTC), in rtc_stm32_alarm_set_time()
892 LL_RTC_ALMA_GetMask(RTC)); in rtc_stm32_alarm_set_time()
897 LL_RTC_ALMB_GetHour(RTC), in rtc_stm32_alarm_set_time()
898 LL_RTC_ALMB_GetMinute(RTC), in rtc_stm32_alarm_set_time()
899 LL_RTC_ALMB_GetSecond(RTC), in rtc_stm32_alarm_set_time()
900 LL_RTC_ALMB_GetMask(RTC)); in rtc_stm32_alarm_set_time()
999 if (!WAIT_FOR(LL_RTC_IsActiveFlag_RECALP(RTC) == 0, 100000, k_msleep(1))) { in rtc_stm32_set_calibration()
1007 LL_RTC_DisableWriteProtection(RTC); in rtc_stm32_set_calibration()
1009 MODIFY_REG(RTC->CALR, RTC_CALR_CALP | RTC_CALR_CALM, calp | calm); in rtc_stm32_set_calibration()
1011 LL_RTC_EnableWriteProtection(RTC); in rtc_stm32_set_calibration()
1024 uint32_t calr = sys_read32((mem_addr_t) &RTC->CALR); in rtc_stm32_get_calibration()
1042 static DEVICE_API(rtc, rtc_stm32_driver_api) = {
1058 #error RTC calibration for devices without smooth calibration feature is not supported yet
1065 BUILD_ASSERT(DT_INST_CLOCKS_HAS_IDX(0, 1), "RTC source clock not defined in the device tree");
1069 #error RTC clock source HSE frequency should be whole MHz
1080 #error RTC does not support HSE frequency
1101 #error Invalid RTC SRC