Skip to content

Commit 25d5dcf

Browse files
hujun260xiaoxiang781216
authored andcommitted
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]>
1 parent 7b0aa11 commit 25d5dcf

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

arch/arm/src/lc823450/lc823450_rtc.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <nuttx/arch.h>
3030
#include <nuttx/irq.h>
31+
#include <nuttx/spinlock.h>
3132
#include <nuttx/timers/rtc.h>
3233

3334
#ifdef CONFIG_RTC_ALARM
@@ -136,6 +137,7 @@ static void rtc_pmnotify(struct pm_callback_s *cb, enum pm_state_e pmstate);
136137

137138
#ifdef CONFIG_RTC_ALARM
138139
static alarmcb_t g_alarmcb;
140+
static spinlock_t g_alarmcb_lock = SP_UNLOCKED;
139141
#endif
140142

141143
#ifdef CONFIG_RTC_SAVE_DEFAULT
@@ -581,6 +583,7 @@ int up_rtc_settime(const struct timespec *ts)
581583
#ifdef CONFIG_RTC_ALARM
582584
int up_rtc_setalarm(const struct timespec *ts, alarmcb_t callback)
583585
{
586+
irqstate_t flags;
584587
struct tm *tp;
585588

586589
if (g_alarmcb)
@@ -589,9 +592,12 @@ int up_rtc_setalarm(const struct timespec *ts, alarmcb_t callback)
589592
}
590593

591594
tp = gmtime(&ts->tv_sec);
595+
592596
#ifdef CONFIG_RTC_DIV
593597
tm_divider(tp, CONFIG_RTC_DIV_M, CONFIG_RTC_DIV_N);
594598
#endif /* CONFIG_RTC_DIV */
599+
600+
flags = spin_lock_irqsave(&g_alarmcb_lock);
595601
g_alarmcb = callback;
596602
#if 0
597603
llinfo("SETALARM (%04d/%02d/%02d %02d:%02d:%02d)\n",
@@ -623,6 +629,8 @@ int up_rtc_setalarm(const struct timespec *ts, alarmcb_t callback)
623629

624630
modifyreg8(RTC_RTCINT, 1 << RTC_RTCINT_SET, 1 << RTC_RTCINT_AIE);
625631

632+
spin_unlock_irqrestore(&g_alarmcb_lock, flags);
633+
626634
return OK;
627635
}
628636

@@ -633,14 +641,14 @@ int up_rtc_setalarm(const struct timespec *ts, alarmcb_t callback)
633641
int up_rtc_cancelalarm(void)
634642
{
635643
irqstate_t flags;
636-
flags = enter_critical_section();
644+
flags = spin_lock_irqsave(&g_alarmcb_lock);
637645
g_alarmcb = NULL;
638646

639647
/* Disable IRQ */
640648

641649
putreg8(0, RTC_RTCINT);
642650

643-
leave_critical_section(flags);
651+
spin_unlock_irqrestore(&g_alarmcb_lock, flags);
644652
return 0;
645653
}
646654

0 commit comments

Comments
 (0)