This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3891a393a19553b2148dc7ea9e2eb7cde55eec3c Author: raiden00pl <[email protected]> AuthorDate: Mon Nov 9 13:46:38 2026 +0100 arch/arm/stm32: Use one alarm header for all RTC drivers. STM32F4 and STM32L1 had their own alarm headers with the same alarm A/B API, and common/stm32/stm32_rtc.h picked one by family name. - Move the alarm A/B API into common/stm32/stm32_alarm.h, next to the single alarm API it already had. The API is selected by the RTC IP (STM32_HAVE_IP_RTCC_M3M4_F4/L1), not by the family. - Remove stm32f4/stm32f40xxx_alarm.h and stm32l1/stm32l15xxx_alarm.h. - The RTC lower half checks STM32_RTC_HAVE_ALARMB instead of family names. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: raiden00pl <[email protected]> --- .github/CODEOWNERS | 2 - arch/arm/src/common/stm32/stm32_alarm.h | 133 ++++++++++++++++- arch/arm/src/common/stm32/stm32_rtc.h | 10 +- .../src/common/stm32/stm32_rtc_m3m4_v1_lowerhalf.c | 17 ++- arch/arm/src/stm32f4/stm32f40xxx_alarm.h | 124 ---------------- arch/arm/src/stm32l1/stm32l15xxx_alarm.h | 161 --------------------- 6 files changed, 138 insertions(+), 309 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a5a79181c1e..ad651015299 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3872,7 +3872,6 @@ arch/arm/src/stm32f4/hardware/stm32f40xxx_syscfg.h [email protected] al arch/arm/src/stm32f4/hardware/stm32f412xx_pinmap.h [email protected] [email protected] [email protected] [email protected] arch/arm/src/stm32f4/stm32.h [email protected] [email protected] [email protected] [email protected] [email protected] arch/arm/src/stm32f4/stm32_rcc.c [email protected] [email protected] [email protected] [email protected] [email protected] -arch/arm/src/stm32f4/stm32f40xxx_alarm.h [email protected] [email protected] [email protected] [email protected] [email protected] arch/arm/src/stm32f4/stm32f40xxx_rcc.c [email protected] [email protected] [email protected] [email protected] [email protected] arch/arm/src/stm32f7/Kconfig [email protected] [email protected] [email protected] [email protected] arch/arm/src/stm32f7/chip.h [email protected] [email protected] Lok Tep 1 file changed, 1 insertion(+) @@ -4290,7 +4289,6 @@ arch/arm/src/stm32l1/hardware/stm32l15xxx_pinmap.h [email protected] alin. arch/arm/src/stm32l1/hardware/stm32l15xxx_syscfg.h [email protected] [email protected] [email protected] arch/arm/src/stm32l1/stm32.h [email protected] [email protected] [email protected] [email protected] [email protected] arch/arm/src/stm32l1/stm32_rcc.c [email protected] [email protected] [email protected] [email protected] [email protected] -arch/arm/src/stm32l1/stm32l15xxx_alarm.h [email protected] [email protected] [email protected] [email protected] [email protected] arch/arm/src/stm32l1/stm32l15xxx_rcc.c [email protected] [email protected] [email protected] [email protected] [email protected] arch/arm/src/stm32l4/Kconfig [email protected] [email protected] [email protected] [email protected] arch/arm/src/stm32l4/chip.h [email protected] [email protected] [email protected] diff --git a/arch/arm/src/common/stm32/stm32_alarm.h b/arch/arm/src/common/stm32/stm32_alarm.h index 8915059a46c..1c011e5fd94 100644 --- a/arch/arm/src/common/stm32/stm32_alarm.h +++ b/arch/arm/src/common/stm32/stm32_alarm.h @@ -29,20 +29,61 @@ #include <nuttx/config.h> +#include <time.h> + #include "chip.h" -#ifdef CONFIG_RTC_ALARM +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* RTC with two alarms (A and B) and the alarm API that selects one of them. + * The others have a single alarm. + */ + +#if defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_F4) || \ + defined(CONFIG_STM32_HAVE_IP_RTCC_M3M4_L1) +# define STM32_RTC_HAVE_ALARMB 1 +#endif + +#ifndef __ASSEMBLY__ /**************************************************************************** * Public Types ****************************************************************************/ -#ifndef __ASSEMBLY__ +#ifdef CONFIG_RTC_ALARM +#ifdef STM32_RTC_HAVE_ALARMB + +/* The form of an alarm callback */ + +typedef void (*alm_callback_t)(FAR void *arg, unsigned int alarmid); + +enum alm_id_e +{ + RTC_ALARMA = 0, /* RTC ALARM A */ + RTC_ALARMB, /* RTC ALARM B */ + RTC_ALARM_LAST +}; + +/* Structure used to pass parameters to set an alarm */ + +struct alm_setalarm_s +{ + int as_id; /* enum alm_id_e */ + struct tm as_time; /* Alarm expiration time */ + alm_callback_t as_cb; /* Callback (if non-NULL) */ + FAR void *as_arg; /* Argument for callback */ +}; + +#else /* The form of an alarm callback */ typedef void (*alarmcb_t)(void); +#endif /* STM32_RTC_HAVE_ALARMB */ + /* Structure used to pass parameters to query an alarm */ struct alm_rdalarm_s @@ -50,6 +91,14 @@ struct alm_rdalarm_s int ar_id; /* enum alm_id_e */ FAR struct rtc_time *ar_time; /* Argument for storing ALARM RTC time */ }; +#endif /* CONFIG_RTC_ALARM */ + +#ifdef CONFIG_RTC_PERIODIC + +/* The form of a periodic wakeup callback */ + +typedef int (*wakeupcb_t)(void); +#endif /**************************************************************************** * Public Function Prototypes @@ -60,6 +109,43 @@ extern "C" { #endif +#ifdef CONFIG_RTC_ALARM +#ifdef STM32_RTC_HAVE_ALARMB + +/**************************************************************************** + * Name: stm32_rtc_setalarm + * + * Description: + * Set an alarm to an absolute time using associated hardware. + * + * Input Parameters: + * alminfo - Information about the alarm configuration. + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ****************************************************************************/ + +int stm32_rtc_setalarm(FAR struct alm_setalarm_s *alminfo); + +/**************************************************************************** + * Name: stm32_rtc_cancelalarm + * + * Description: + * Cancel an alarm. + * + * 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); + +#else + /**************************************************************************** * Name: stm32_rtc_setalarm * @@ -75,8 +161,7 @@ extern "C" * ****************************************************************************/ -struct timespec; -int stm32_rtc_setalarm(const struct timespec *tp, alarmcb_t callback); +int stm32_rtc_setalarm(FAR const struct timespec *tp, alarmcb_t callback); /**************************************************************************** * Name: stm32_rtc_cancelalarm @@ -94,6 +179,8 @@ int stm32_rtc_setalarm(const struct timespec *tp, alarmcb_t callback); int stm32_rtc_cancelalarm(void); +#endif /* STM32_RTC_HAVE_ALARMB */ + /**************************************************************************** * Name: stm32_rtc_rdalarm * @@ -109,11 +196,47 @@ int stm32_rtc_cancelalarm(void); ****************************************************************************/ int stm32_rtc_rdalarm(FAR struct alm_rdalarm_s *alminfo); +#endif /* CONFIG_RTC_ALARM */ + +#ifdef CONFIG_RTC_PERIODIC + +/**************************************************************************** + * Name: stm32_rtc_setperiodic + * + * Description: + * Set a periodic RTC wakeup + * + * Input Parameters: + * period - Time to sleep between wakeups + * callback - Function to call when the period expires. + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ****************************************************************************/ + +int stm32_rtc_setperiodic(FAR const struct timespec *period, + wakeupcb_t callback); + +/**************************************************************************** + * Name: stm32_rtc_cancelperiodic + * + * Description: + * Cancel a periodic wakeup + * + * Input Parameters: + * + * Returned Value: + * Zero (OK) on success; a negated errno on failure + * + ****************************************************************************/ + +int stm32_rtc_cancelperiodic(void); +#endif /* CONFIG_RTC_PERIODIC */ #if defined(__cplusplus) } #endif #endif /* __ASSEMBLY__ */ -#endif /* CONFIG_RTC_ALARM */ #endif /* __ARCH_ARM_SRC_COMMON_STM32_STM32_ALARM_H */ diff --git a/arch/arm/src/common/stm32/stm32_rtc.h b/arch/arm/src/common/stm32/stm32_rtc.h index 772f6695df7..949ac27d411 100644 --- a/arch/arm/src/common/stm32/stm32_rtc.h +++ b/arch/arm/src/common/stm32/stm32_rtc.h @@ -52,15 +52,7 @@ # include "hardware/stm32_rtcc.h" #endif -/* Alarm function differs from part to part */ - -#if defined(CONFIG_STM32_STM32F4XXX) -# include "stm32f40xxx_alarm.h" -#elif defined(CONFIG_STM32_STM32L15XX) -# include "stm32l15xxx_alarm.h" -#else -# include "stm32_alarm.h" -#endif +#include "stm32_alarm.h" /**************************************************************************** * Pre-processor Definitions diff --git a/arch/arm/src/common/stm32/stm32_rtc_m3m4_v1_lowerhalf.c b/arch/arm/src/common/stm32/stm32_rtc_m3m4_v1_lowerhalf.c index e8c1c75fc9d..2517ac96a3e 100644 --- a/arch/arm/src/common/stm32/stm32_rtc_m3m4_v1_lowerhalf.c +++ b/arch/arm/src/common/stm32/stm32_rtc_m3m4_v1_lowerhalf.c @@ -46,7 +46,7 @@ * Pre-processor Definitions ****************************************************************************/ -#if defined(CONFIG_STM32_STM32F4XXX) || defined(CONFIG_STM32_STM32L15XX) +#ifdef STM32_RTC_HAVE_ALARMB # define STM32_NALARMS 2 #else # define STM32_NALARMS 1 @@ -61,7 +61,7 @@ struct stm32_cbinfo_s { volatile rtc_alarm_callback_t cb; /* Callback when the alarm expires */ volatile void *priv; /* Private argument to accompany callback */ -#if defined(CONFIG_STM32_STM32F4XXX) || defined(CONFIG_STM32_STM32L15XX) +#ifdef STM32_RTC_HAVE_ALARMB uint8_t id; /* Identifies the alarm */ #endif }; @@ -178,7 +178,7 @@ static struct stm32_lowerhalf_s g_rtc_lowerhalf = ****************************************************************************/ #ifdef CONFIG_RTC_ALARM -#if defined(CONFIG_STM32_STM32F4XXX) || defined(CONFIG_STM32_STM32L15XX) +#ifdef STM32_RTC_HAVE_ALARMB static void stm32_alarm_callback(void *arg, unsigned int alarmid) { struct stm32_lowerhalf_s *lower; @@ -233,7 +233,7 @@ static void stm32_alarm_callback(void) } } -#endif /* CONFIG_STM32_STM32F4XXX || CONFIG_STM32_STM32L15XX */ +#endif /* STM32_RTC_HAVE_ALARMB */ #endif /* CONFIG_RTC_ALARM */ /**************************************************************************** @@ -303,6 +303,7 @@ errout: if (!gmtime_r(&timer, (struct tm *)rtctime)) { int errcode = get_errno(); + DEBUGASSERT(errcode > 0); return -errcode; } @@ -397,7 +398,7 @@ static bool stm32_havesettime(struct rtc_lowerhalf_s *lower) static int stm32_setalarm(struct rtc_lowerhalf_s *lower, const struct lower_setalarm_s *alarminfo) { -#if defined(CONFIG_STM32_STM32F4XXX) || defined(CONFIG_STM32_STM32L15XX) +#ifdef STM32_RTC_HAVE_ALARMB struct stm32_lowerhalf_s *priv; struct stm32_cbinfo_s *cbinfo; struct alm_setalarm_s lowerinfo; @@ -512,7 +513,7 @@ static int stm32_setalarm(struct rtc_lowerhalf_s *lower, static int stm32_setrelative(struct rtc_lowerhalf_s *lower, const struct lower_setrelative_s *alarminfo) { -#if defined(CONFIG_STM32_STM32F4XXX) || defined(CONFIG_STM32_STM32L15XX) +#ifdef STM32_RTC_HAVE_ALARMB struct lower_setalarm_s setalarm; struct tm time; time_t seconds; @@ -665,7 +666,7 @@ static int stm32_setrelative(struct rtc_lowerhalf_s *lower, #ifdef CONFIG_RTC_ALARM static int stm32_cancelalarm(struct rtc_lowerhalf_s *lower, int alarmid) { -#if defined(CONFIG_STM32_STM32F4XXX) || defined(CONFIG_STM32_STM32L15XX) +#ifdef STM32_RTC_HAVE_ALARMB struct stm32_lowerhalf_s *priv; struct stm32_cbinfo_s *cbinfo; int ret; @@ -745,7 +746,7 @@ 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) +#ifdef STM32_RTC_HAVE_ALARMB DEBUGASSERT(alarminfo->id == RTC_ALARMA || alarminfo->id == RTC_ALARMB); if (alarminfo->id == RTC_ALARMA || alarminfo->id == RTC_ALARMB) diff --git a/arch/arm/src/stm32f4/stm32f40xxx_alarm.h b/arch/arm/src/stm32f4/stm32f40xxx_alarm.h deleted file mode 100644 index 04e096a63cb..00000000000 --- a/arch/arm/src/stm32f4/stm32f40xxx_alarm.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** - * arch/arm/src/stm32f4/stm32f40xxx_alarm.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __ARCH_ARM_SRC_STM32_STM32F40XXX_ALARM_H -#define __ARCH_ARM_SRC_STM32_STM32F40XXX_ALARM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <time.h> - -#ifdef CONFIG_RTC_ALARM - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -typedef void (*alm_callback_t)(void *arg, unsigned int alarmid); - -/* These features are known to map to STM32 RTC from stm32F4xx and appear to - * map to beyond stm32F4xx and stm32L0xx there appears to be a small variant - * with stm32F3 but do not map to stm32F0, F1, F2 - */ - -enum alm_id_e -{ - RTC_ALARMA = 0, /* RTC ALARM A */ - RTC_ALARMB, /* RTC ALARM B */ - RTC_ALARM_LAST -}; - -/* Structure used to pass parameters to set an alarm */ - -struct alm_setalarm_s -{ - int as_id; /* enum alm_id_e */ - struct tm as_time; /* Alarm expiration time */ - alm_callback_t as_cb; /* Callback (if non-NULL) */ - void *as_arg; /* Argument for callback */ -}; - -/* Structure used to pass parameters to query an alarm */ - -struct alm_rdalarm_s -{ - int ar_id; /* enum alm_id_e */ - struct rtc_time *ar_time; /* Argument for storing ALARM RTC time */ -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: stm32_rtc_setalarm - * - * Description: - * Set an alarm to an absolute time using associated hardware. - * - * Input Parameters: - * alminfo - Information about the alarm configuration. - * - * Returned Value: - * Zero (OK) on success; a negated errno on failure - * - ****************************************************************************/ - -int stm32_rtc_setalarm(struct alm_setalarm_s *alminfo); - -/**************************************************************************** - * 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(struct alm_rdalarm_s *alminfo); - -/**************************************************************************** - * Name: stm32_rtc_cancelalarm - * - * Description: - * Cancel an alarm. - * - * 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 */ diff --git a/arch/arm/src/stm32l1/stm32l15xxx_alarm.h b/arch/arm/src/stm32l1/stm32l15xxx_alarm.h deleted file mode 100644 index 1d5e789cec9..00000000000 --- a/arch/arm/src/stm32l1/stm32l15xxx_alarm.h +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** - * arch/arm/src/stm32l1/stm32l15xxx_alarm.h - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __ARCH_ARM_SRC_STM32_STM32L15XXX_ALARM_H -#define __ARCH_ARM_SRC_STM32_STM32L15XXX_ALARM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <time.h> - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -#ifdef CONFIG_RTC_ALARM -typedef void (*alm_callback_t)(void *arg, unsigned int alarmid); - -/* These features are the same than in STM32F4 and STM32L4 */ - -enum alm_id_e -{ - RTC_ALARMA = 0, /* RTC ALARM A */ - RTC_ALARMB, /* RTC ALARM B */ - RTC_ALARM_LAST -}; - -/* Structure used to pass parameters to set an alarm */ - -struct alm_setalarm_s -{ - int as_id; /* enum alm_id_e */ - struct tm as_time; /* Alarm expiration time */ - alm_callback_t as_cb; /* Callback (if non-NULL) */ - void *as_arg; /* Argument for callback */ -}; - -/* Structure used to pass parameters to query an alarm */ - -struct alm_rdalarm_s -{ - int ar_id; /* enum alm_id_e */ - struct rtc_time *ar_time; /* Argument for storing ALARM RTC time */ -}; -#endif - -#ifdef CONFIG_RTC_PERIODIC -typedef int (*wakeupcb_t)(void); -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef CONFIG_RTC_ALARM -/**************************************************************************** - * Name: stm32_rtc_setalarm - * - * Description: - * Set an alarm to an absolute time using associated hardware. - * - * Input Parameters: - * alminfo - Information about the alarm configuration. - * - * Returned Value: - * Zero (OK) on success; a negated errno on failure - * - ****************************************************************************/ - -int stm32_rtc_setalarm(struct alm_setalarm_s *alminfo); - -/**************************************************************************** - * 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(struct alm_rdalarm_s *alminfo); - -/**************************************************************************** - * Name: stm32_rtc_cancelalarm - * - * Description: - * Cancel an alarm. - * - * 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 */ - -#ifdef CONFIG_RTC_PERIODIC -/**************************************************************************** - * Name: stm32_rtc_setperiodic - * - * Description: - * Set a periodic RTC wakeup - * - * Input Parameters: - * period - Time to sleep between wakeups - * callback - Function to call when the period expires. - * - * Returned Value: - * Zero (OK) on success; a negated errno on failure - * - ****************************************************************************/ - -int stm32_rtc_setperiodic(const struct timespec *period, - wakeupcb_t callback); - -/**************************************************************************** - * Name: stm32_rtc_cancelperiodic - * - * Description: - * Cancel a periodic wakeup - * - * Input Parameters: - * - * Returned Value: - * Zero (OK) on success; a negated errno on failure - * - ****************************************************************************/ - -int stm32_rtc_cancelperiodic(void); -#endif /* CONFIG_RTC_PERIODIC */ - -#endif /* __ARCH_ARM_SRC_STM32_STM32L15XXX_ALARM_H */
