Skip to content

Commit a4da079

Browse files
hujun260xiaoxiang781216
authored andcommitted
esp32c3_rtc: use small lock in arch/risc-v/src/esp32c3-legacy/esp32c3_rtc.c
reason: We would like to replace the big lock with a small lock. Signed-off-by: hujun5 <[email protected]>
1 parent 25d5dcf commit a4da079

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

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

Lines changed: 14 additions & 13 deletions
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
}

0 commit comments

Comments
 (0)