mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 17:48:54 +08:00
arch/arm/stm32: fix stm32f1xx alarm support
Summary: stm32: support querying a previously set RTC alarm In the STM32F1xx series Impact: When using the stm32f1xx series MCU, the alarm function can be used, but when we enabled the CONFIG_RTC_ALARM configuration, an error was reported due to the inability to find the specific implementation of rdalarm. Testing: In our own projects, we have done alarm verification using the STM32F103RE..
This commit is contained in:
@@ -43,6 +43,14 @@
|
|||||||
|
|
||||||
typedef void (*alarmcb_t)(void);
|
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
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -90,6 +98,22 @@ int stm32_rtc_setalarm(const struct timespec *tp, alarmcb_t callback);
|
|||||||
|
|
||||||
int stm32_rtc_cancelalarm(void);
|
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
|
#undef EXTERN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -745,9 +745,16 @@ static int stm32_rdalarm(struct rtc_lowerhalf_s *lower,
|
|||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
|
|
||||||
DEBUGASSERT(lower != NULL && alarminfo != NULL && alarminfo->time != NULL);
|
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);
|
DEBUGASSERT(alarminfo->id == RTC_ALARMA || alarminfo->id == RTC_ALARMB);
|
||||||
|
|
||||||
if (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
|
/* Disable pre-emption while we do this so that we don't have to worry
|
||||||
* about being suspended and working on an old time.
|
* about being suspended and working on an old time.
|
||||||
|
|||||||
@@ -53,7 +53,10 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "arm_internal.h"
|
#include "arm_internal.h"
|
||||||
#include "stm32_pwr.h"
|
#include "stm32_pwr.h"
|
||||||
@@ -797,3 +800,49 @@ int stm32_rtc_cancelalarm(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
||||||
|
|||||||
Reference in New Issue
Block a user