diff --git a/arch/arm/src/stm32/stm32_alarm.h b/arch/arm/src/stm32/stm32_alarm.h index ced1f3a464f..2660dfd8a05 100644 --- a/arch/arm/src/stm32/stm32_alarm.h +++ b/arch/arm/src/stm32/stm32_alarm.h @@ -43,6 +43,14 @@ typedef void (*alarmcb_t)(void); +/* Structure used to pass parameters to query an alarm */ + +struct alm_rdalarm_s +{ + int ar_id; /* enum alm_id_e */ + FAR struct rtc_time *ar_time; /* Argument for storing ALARM RTC time */ +}; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -90,6 +98,22 @@ int stm32_rtc_setalarm(const struct timespec *tp, alarmcb_t callback); int stm32_rtc_cancelalarm(void); +/**************************************************************************** + * Name: stm32_rtc_rdalarm + * + * Description: + * Query an alarm configured in hardware. + * + * Input Parameters: + * alminfo - Information about the alarm configuration. + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ****************************************************************************/ + +int stm32_rtc_rdalarm(FAR struct alm_rdalarm_s *alminfo); + #undef EXTERN #if defined(__cplusplus) } diff --git a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c index f5188e8f643..69c59d6f887 100644 --- a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c +++ b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c @@ -745,9 +745,16 @@ static int stm32_rdalarm(struct rtc_lowerhalf_s *lower, irqstate_t flags; DEBUGASSERT(lower != NULL && alarminfo != NULL && alarminfo->time != NULL); +#if defined(CONFIG_STM32_STM32F4XXX) || defined(CONFIG_STM32_STM32L15XX) DEBUGASSERT(alarminfo->id == RTC_ALARMA || alarminfo->id == RTC_ALARMB); if (alarminfo->id == RTC_ALARMA || alarminfo->id == RTC_ALARMB) +#else + DEBUGASSERT(alarminfo->id >= 0 && alarminfo->id < CONFIG_RTC_NALARMS); + + if (alarminfo != NULL && alarminfo->id >= 0 && + alarminfo->id < CONFIG_RTC_NALARMS) +#endif { /* Disable pre-emption while we do this so that we don't have to worry * about being suspended and working on an old time. diff --git a/arch/arm/src/stm32/stm32_rtcounter.c b/arch/arm/src/stm32/stm32_rtcounter.c index 2d97a6f33fc..62441cb3127 100644 --- a/arch/arm/src/stm32/stm32_rtcounter.c +++ b/arch/arm/src/stm32/stm32_rtcounter.c @@ -53,7 +53,10 @@ #include #include #include +#include #include +#include +#include #include "arm_internal.h" #include "stm32_pwr.h" @@ -797,3 +800,49 @@ int stm32_rtc_cancelalarm(void) return ret; } #endif + +/**************************************************************************** + * Name: stm32_rtc_rdalarm + * + * Description: + * Query an alarm configured in hardware. + * + * Input Parameters: + * alminfo - Information about the alarm configuration. + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ****************************************************************************/ + +#ifdef CONFIG_RTC_ALARM +int stm32_rtc_rdalarm(FAR struct alm_rdalarm_s *alminfo) +{ + struct rtc_regvals_s regvals; + FAR struct timespec tp; + int ret = -EINVAL; + + DEBUGASSERT(alminfo != NULL); + DEBUGASSERT(alminfo->ar_id == 0); + + switch (alminfo->ar_id) + { + case 0: + { + regvals.cnth = getreg16(STM32_RTC_ALRH); + regvals.cntl = getreg16(STM32_RTC_ALRL); + tp.tv_sec = regvals.cnth << 16 | regvals.cntl; + memcpy(alminfo->ar_time, (FAR struct tm *)gmtime(&tp.tv_sec), + sizeof(FAR struct tm)); + ret = OK; + } + break; + + default: + rtcerr("ERROR: Invalid ALARM%d\n", alminfo->ar_id); + break; + } + + return ret; +} +#endif