Skip to content

Commit 31a4d6e

Browse files
committed
Merge branch 'master' of github.com:apache/nuttx into dev_zero
2 parents 8f89248 + a4da079 commit 31a4d6e

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

arch/arm/src/lc823450/lc823450_rtc.c

+10-2
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

arch/risc-v/src/esp32c3-legacy/esp32c3_rtc.c

+14-13
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ static RTC_DATA_ATTR struct esp32c3_rtc_backup_s rtc_saved_data;
455455

456456
static struct esp32c3_rtc_backup_s *g_rtc_save;
457457
static bool g_rt_timer_enabled = false;
458+
static spinlock_t g_rtc_lock = SP_UNLOCKED;
458459

459460
#endif
460461

@@ -3076,7 +3077,7 @@ time_t up_rtc_time(void)
30763077
uint64_t time_us;
30773078
irqstate_t flags;
30783079

3079-
flags = spin_lock_irqsave(NULL);
3080+
flags = spin_lock_irqsave(&g_rtc_lock);
30803081

30813082
/* NOTE: RT-Timer starts to work after the board is initialized, and the
30823083
* RTC controller starts works after up_rtc_initialize is initialized.
@@ -3105,7 +3106,7 @@ time_t up_rtc_time(void)
31053106
esp32c3_rtc_get_boot_time();
31063107
}
31073108

3108-
spin_unlock_irqrestore(NULL, flags);
3109+
spin_unlock_irqrestore(&g_rtc_lock, flags);
31093110

31103111
return (time_t)(time_us / USEC_PER_SEC);
31113112
}
@@ -3133,7 +3134,7 @@ int up_rtc_settime(const struct timespec *ts)
31333134
uint64_t rtc_offset_us;
31343135

31353136
DEBUGASSERT(ts != NULL && ts->tv_nsec < NSEC_PER_SEC);
3136-
flags = spin_lock_irqsave(NULL);
3137+
flags = spin_lock_irqsave(&g_rtc_lock);
31373138

31383139
now_us = ((uint64_t) ts->tv_sec) * USEC_PER_SEC +
31393140
ts->tv_nsec / NSEC_PER_USEC;
@@ -3153,7 +3154,7 @@ int up_rtc_settime(const struct timespec *ts)
31533154
g_rtc_save->offset = 0;
31543155
esp32c3_rtc_set_boot_time(rtc_offset_us);
31553156

3156-
spin_unlock_irqrestore(NULL, flags);
3157+
spin_unlock_irqrestore(&g_rtc_lock, flags);
31573158

31583159
return OK;
31593160
}
@@ -3219,7 +3220,7 @@ int up_rtc_gettime(struct timespec *tp)
32193220
irqstate_t flags;
32203221
uint64_t time_us;
32213222

3222-
flags = spin_lock_irqsave(NULL);
3223+
flags = spin_lock_irqsave(&g_rtc_lock);
32233224

32243225
if (g_rt_timer_enabled == true)
32253226
{
@@ -3234,7 +3235,7 @@ int up_rtc_gettime(struct timespec *tp)
32343235
tp->tv_sec = time_us / USEC_PER_SEC;
32353236
tp->tv_nsec = (time_us % USEC_PER_SEC) * NSEC_PER_USEC;
32363237

3237-
spin_unlock_irqrestore(NULL, flags);
3238+
spin_unlock_irqrestore(&g_rtc_lock, flags);
32383239

32393240
return OK;
32403241
}
@@ -3277,7 +3278,7 @@ int up_rtc_setalarm(struct alm_setalarm_s *alminfo)
32773278
{
32783279
/* Create the RT-Timer alarm */
32793280

3280-
flags = spin_lock_irqsave(NULL);
3281+
flags = spin_lock_irqsave(&g_rtc_lock);
32813282

32823283
if (cbinfo->alarm_hdl == NULL)
32833284
{
@@ -3288,7 +3289,7 @@ int up_rtc_setalarm(struct alm_setalarm_s *alminfo)
32883289
if (ret < 0)
32893290
{
32903291
rtcerr("ERROR: Failed to create rt_timer error=%d\n", ret);
3291-
spin_unlock_irqrestore(NULL, flags);
3292+
spin_unlock_irqrestore(&g_rtc_lock, flags);
32923293
return ret;
32933294
}
32943295
}
@@ -3309,7 +3310,7 @@ int up_rtc_setalarm(struct alm_setalarm_s *alminfo)
33093310
ret = OK;
33103311
}
33113312

3312-
spin_unlock_irqrestore(NULL, flags);
3313+
spin_unlock_irqrestore(&g_rtc_lock, flags);
33133314
}
33143315

33153316
return ret;
@@ -3344,7 +3345,7 @@ int up_rtc_cancelalarm(enum alm_id_e alarmid)
33443345

33453346
if (cbinfo->ac_cb != NULL)
33463347
{
3347-
flags = spin_lock_irqsave(NULL);
3348+
flags = spin_lock_irqsave(&g_rtc_lock);
33483349

33493350
/* Stop and delete the alarm */
33503351

@@ -3355,7 +3356,7 @@ int up_rtc_cancelalarm(enum alm_id_e alarmid)
33553356
cbinfo->deadline_us = 0;
33563357
cbinfo->alarm_hdl = NULL;
33573358

3358-
spin_unlock_irqrestore(NULL, flags);
3359+
spin_unlock_irqrestore(&g_rtc_lock, flags);
33593360

33603361
ret = OK;
33613362
}
@@ -3386,7 +3387,7 @@ int up_rtc_rdalarm(struct timespec *tp, uint32_t alarmid)
33863387
DEBUGASSERT((RTC_ALARM0 <= alarmid) &&
33873388
(alarmid < RTC_ALARM_LAST));
33883389

3389-
flags = spin_lock_irqsave(NULL);
3390+
flags = spin_lock_irqsave(&g_rtc_lock);
33903391

33913392
/* Get the alarm according to the alarmid */
33923393

@@ -3397,7 +3398,7 @@ int up_rtc_rdalarm(struct timespec *tp, uint32_t alarmid)
33973398
tp->tv_nsec = ((rt_timer_time_us() + g_rtc_save->offset +
33983399
cbinfo->deadline_us) % USEC_PER_SEC) * NSEC_PER_USEC;
33993400

3400-
spin_unlock_irqrestore(NULL, flags);
3401+
spin_unlock_irqrestore(&g_rtc_lock, flags);
34013402

34023403
return OK;
34033404
}

boards/sim/sim/sim/scripts/Make.defs

+7-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,13 @@ ifeq ($(CONFIG_SIM_M32),y)
149149
ARCHCFLAGS += -m32
150150
ARCHCXXFLAGS += -m32
151151
else
152-
ARCHCFLAGS += -fno-pic -mcmodel=medium
153-
ARCHCXXFLAGS += -fno-pic -mcmodel=medium
152+
ifeq ($(CONFIG_HOST_MACOS),y)
153+
ARCHCFLAGS += -fno-pic
154+
ARCHCXXFLAGS += -fno-pic
155+
else
156+
ARCHCFLAGS += -fno-pic -mcmodel=medium
157+
ARCHCXXFLAGS += -fno-pic -mcmodel=medium
158+
endif
154159
endif
155160

156161
# LLVM style architecture flags

0 commit comments

Comments
 (0)