lc823450_rtc: use small lock in arch/arm/src/lc823450/lc823450_rtc.c

reason:
We would like to replace the big lock with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2024-12-17 11:35:26 +08:00 committed by Xiang Xiao
parent 6bcf698615
commit 9f449d2da4

View file

@ -28,6 +28,7 @@
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/timers/rtc.h>
#ifdef CONFIG_RTC_ALARM
@ -136,6 +137,7 @@ static void rtc_pmnotify(struct pm_callback_s *cb, enum pm_state_e pmstate);
#ifdef CONFIG_RTC_ALARM
static alarmcb_t g_alarmcb;
static spinlock_t g_alarmcb_lock = SP_UNLOCKED;
#endif
#ifdef CONFIG_RTC_SAVE_DEFAULT
@ -581,6 +583,7 @@ int up_rtc_settime(const struct timespec *ts)
#ifdef CONFIG_RTC_ALARM
int up_rtc_setalarm(const struct timespec *ts, alarmcb_t callback)
{
irqstate_t flags;
struct tm *tp;
if (g_alarmcb)
@ -589,9 +592,12 @@ int up_rtc_setalarm(const struct timespec *ts, alarmcb_t callback)
}
tp = gmtime(&ts->tv_sec);
#ifdef CONFIG_RTC_DIV
tm_divider(tp, CONFIG_RTC_DIV_M, CONFIG_RTC_DIV_N);
#endif /* CONFIG_RTC_DIV */
flags = spin_lock_irqsave(&g_alarmcb_lock);
g_alarmcb = callback;
#if 0
llinfo("SETALARM (%04d/%02d/%02d %02d:%02d:%02d)\n",
@ -623,6 +629,8 @@ int up_rtc_setalarm(const struct timespec *ts, alarmcb_t callback)
modifyreg8(RTC_RTCINT, 1 << RTC_RTCINT_SET, 1 << RTC_RTCINT_AIE);
spin_unlock_irqrestore(&g_alarmcb_lock, flags);
return OK;
}
@ -633,14 +641,14 @@ int up_rtc_setalarm(const struct timespec *ts, alarmcb_t callback)
int up_rtc_cancelalarm(void)
{
irqstate_t flags;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_alarmcb_lock);
g_alarmcb = NULL;
/* Disable IRQ */
putreg8(0, RTC_RTCINT);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_alarmcb_lock, flags);
return 0;
}