From 1ea7b486776bc1f9ada908c1a0d909464ba0a761 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 4 Apr 2016 08:23:09 -0600 Subject: [PATCH] RTC lower half was missing call to F4 alarm cancel function --- arch/arm/src/stm32/stm32_rtc_lowerhalf.c | 25 +++++++++++++++++++++--- arch/arm/src/stm32/stm32f40xxx_alarm.h | 16 +++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c index a9f90304e6..20275ee921 100644 --- a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c +++ b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c @@ -617,13 +617,30 @@ static int stm32_setrelative(FAR struct rtc_lowerhalf_s *lower, static int stm32_cancelalarm(FAR struct rtc_lowerhalf_s *lower, int alarmid) { #ifdef CONFIG_STM32_STM32F40XX - /* ID0-> Alarm A; ID1 -> Alarm B */ + FAR struct stm32_lowerhalf_s *priv; + FAR struct stm32_cbinfo_s *cbinfo; + int ret = -EINVAL; DEBUGASSERT(lower != NULL); DEBUGASSERT(alarmid == RTC_ALARMA || alarmid == RTC_ALARMB); + priv = (FAR struct stm32_lowerhalf_s *)lower; -# warning Missing logic - return -ENOSYS; + /* ID0-> Alarm A; ID1 -> Alarm B */ + + if (alarmid == RTC_ALARMA || alarmid == RTC_ALARMB) + { + /* Nullify callback information to reduce window for race conditions */ + + cbinfo = &priv->cbinfo[alarmid]; + cbinfo->cb = NULL; + cbinfo->priv = NULL; + + /* Then cancel the alarm */ + + ret = stm32_rtc_cancelalarm((enum alm_id_e)alarmid); + } + + return ret; #else FAR struct stm32_lowerhalf_s *priv; @@ -639,6 +656,8 @@ static int stm32_cancelalarm(FAR struct rtc_lowerhalf_s *lower, int alarmid) cbinfo->cb = NULL; cbinfo->priv = NULL; + /* Then cancel the alarm */ + return stm32_rtc_cancelalarm(); #endif } diff --git a/arch/arm/src/stm32/stm32f40xxx_alarm.h b/arch/arm/src/stm32/stm32f40xxx_alarm.h index bd58643844..5d8d94a197 100644 --- a/arch/arm/src/stm32/stm32f40xxx_alarm.h +++ b/arch/arm/src/stm32/stm32f40xxx_alarm.h @@ -93,5 +93,21 @@ struct alm_setalarm_s int stm32_rtc_setalarm(FAR struct alm_setalarm_s *alminfo); +/**************************************************************************** + * Name: stm32_rtc_cancelalarm + * + * Description: + * Cancel an alaram. + * + * Input Parameters: + * alarmid - Identifies the alarm to be cancelled + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ****************************************************************************/ + +int stm32_rtc_cancelalarm(enum alm_id_e alarmid); + #endif /* CONFIG_RTC_ALARM */ #endif /* __ARCH_ARM_SRC_STM32_STM32F40XXX_ALARM_H */