1 /*
2  * Copyright (c) 2024 STMicroelectronics
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_RTC_RTC_LL_STM32_H_
8 #define ZEPHYR_DRIVERS_RTC_RTC_LL_STM32_H_
9 
10 #ifdef CONFIG_RTC_ALARM
11 
12 /* STM32 RTC alarms, A & B, LL masks are equal */
13 #define RTC_STM32_ALRM_MASK_ALL		LL_RTC_ALMA_MASK_ALL
14 #define RTC_STM32_ALRM_MASK_SECONDS	LL_RTC_ALMA_MASK_SECONDS
15 #define RTC_STM32_ALRM_MASK_MINUTES	LL_RTC_ALMA_MASK_MINUTES
16 #define RTC_STM32_ALRM_MASK_HOURS	LL_RTC_ALMA_MASK_HOURS
17 #define RTC_STM32_ALRM_MASK_DATEWEEKDAY	LL_RTC_ALMA_MASK_DATEWEEKDAY
18 
19 #define RTC_STM32_ALRM_DATEWEEKDAYSEL_WEEKDAY	LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY
20 #define RTC_STM32_ALRM_DATEWEEKDAYSEL_DATE	LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
21 
ll_func_exti_enable_rtc_alarm_it(uint32_t exti_line)22 static inline void ll_func_exti_enable_rtc_alarm_it(uint32_t exti_line)
23 {
24 #if defined(CONFIG_SOC_SERIES_STM32H7X) && defined(CONFIG_CPU_CORTEX_M4)
25 	LL_C2_EXTI_EnableIT_0_31(exti_line);
26 	LL_EXTI_EnableRisingTrig_0_31(exti_line);
27 #elif defined(CONFIG_SOC_SERIES_STM32U5X) || defined(CONFIG_SOC_SERIES_STM32WBAX)
28 	/* in STM32U5 & STM32WBAX series, RTC Alarm event is not routed to EXTI */
29 #else
30 	LL_EXTI_EnableIT_0_31(exti_line);
31 	LL_EXTI_EnableRisingTrig_0_31(exti_line);
32 #endif /* CONFIG_SOC_SERIES_STM32H7X and CONFIG_CPU_CORTEX_M4 */
33 }
34 
ll_func_exti_clear_rtc_alarm_flag(uint32_t exti_line)35 static inline void ll_func_exti_clear_rtc_alarm_flag(uint32_t exti_line)
36 {
37 #if defined(CONFIG_SOC_SERIES_STM32H7X) && defined(CONFIG_CPU_CORTEX_M4)
38 	LL_C2_EXTI_ClearFlag_0_31(exti_line);
39 #elif defined(CONFIG_SOC_SERIES_STM32U5X) || defined(CONFIG_SOC_SERIES_STM32WBAX)
40 	/* in STM32U5 & STM32WBAX series, RTC Alarm event is not routed to EXTI */
41 #elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32g0_exti)
42 	LL_EXTI_ClearRisingFlag_0_31(exti_line);
43 #else
44 	LL_EXTI_ClearFlag_0_31(exti_line);
45 #endif /* CONFIG_SOC_SERIES_STM32H7X and CONFIG_CPU_CORTEX_M4 */
46 }
47 #endif /* CONFIG_RTC_ALARM */
48 
49 #endif	/* ZEPHYR_DRIVERS_RTC_RTC_LL_STM32_H_ */
50