This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 25d5dcf7ef lc823450_rtc: use small lock in
arch/arm/src/lc823450/lc823450_rtc.c
25d5dcf7ef is described below
commit 25d5dcf7ef12d85c65ec05250a880b0f7a4bef0d
Author: hujun5 <[email protected]>
AuthorDate: Tue Dec 17 11:35:26 2024 +0800
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 <[email protected]>
---
arch/arm/src/lc823450/lc823450_rtc.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/arm/src/lc823450/lc823450_rtc.c
b/arch/arm/src/lc823450/lc823450_rtc.c
index f1cf931ff0..4e0a50b869 100644
--- a/arch/arm/src/lc823450/lc823450_rtc.c
+++ b/arch/arm/src/lc823450/lc823450_rtc.c
@@ -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;
}