@@ -455,6 +455,7 @@ static RTC_DATA_ATTR struct esp32c3_rtc_backup_s rtc_saved_data;
455
455
456
456
static struct esp32c3_rtc_backup_s * g_rtc_save ;
457
457
static bool g_rt_timer_enabled = false;
458
+ static spinlock_t g_rtc_lock = SP_UNLOCKED ;
458
459
459
460
#endif
460
461
@@ -3076,7 +3077,7 @@ time_t up_rtc_time(void)
3076
3077
uint64_t time_us ;
3077
3078
irqstate_t flags ;
3078
3079
3079
- flags = spin_lock_irqsave (NULL );
3080
+ flags = spin_lock_irqsave (& g_rtc_lock );
3080
3081
3081
3082
/* NOTE: RT-Timer starts to work after the board is initialized, and the
3082
3083
* RTC controller starts works after up_rtc_initialize is initialized.
@@ -3105,7 +3106,7 @@ time_t up_rtc_time(void)
3105
3106
esp32c3_rtc_get_boot_time ();
3106
3107
}
3107
3108
3108
- spin_unlock_irqrestore (NULL , flags );
3109
+ spin_unlock_irqrestore (& g_rtc_lock , flags );
3109
3110
3110
3111
return (time_t )(time_us / USEC_PER_SEC );
3111
3112
}
@@ -3133,7 +3134,7 @@ int up_rtc_settime(const struct timespec *ts)
3133
3134
uint64_t rtc_offset_us ;
3134
3135
3135
3136
DEBUGASSERT (ts != NULL && ts -> tv_nsec < NSEC_PER_SEC );
3136
- flags = spin_lock_irqsave (NULL );
3137
+ flags = spin_lock_irqsave (& g_rtc_lock );
3137
3138
3138
3139
now_us = ((uint64_t ) ts -> tv_sec ) * USEC_PER_SEC +
3139
3140
ts -> tv_nsec / NSEC_PER_USEC ;
@@ -3153,7 +3154,7 @@ int up_rtc_settime(const struct timespec *ts)
3153
3154
g_rtc_save -> offset = 0 ;
3154
3155
esp32c3_rtc_set_boot_time (rtc_offset_us );
3155
3156
3156
- spin_unlock_irqrestore (NULL , flags );
3157
+ spin_unlock_irqrestore (& g_rtc_lock , flags );
3157
3158
3158
3159
return OK ;
3159
3160
}
@@ -3219,7 +3220,7 @@ int up_rtc_gettime(struct timespec *tp)
3219
3220
irqstate_t flags ;
3220
3221
uint64_t time_us ;
3221
3222
3222
- flags = spin_lock_irqsave (NULL );
3223
+ flags = spin_lock_irqsave (& g_rtc_lock );
3223
3224
3224
3225
if (g_rt_timer_enabled == true)
3225
3226
{
@@ -3234,7 +3235,7 @@ int up_rtc_gettime(struct timespec *tp)
3234
3235
tp -> tv_sec = time_us / USEC_PER_SEC ;
3235
3236
tp -> tv_nsec = (time_us % USEC_PER_SEC ) * NSEC_PER_USEC ;
3236
3237
3237
- spin_unlock_irqrestore (NULL , flags );
3238
+ spin_unlock_irqrestore (& g_rtc_lock , flags );
3238
3239
3239
3240
return OK ;
3240
3241
}
@@ -3277,7 +3278,7 @@ int up_rtc_setalarm(struct alm_setalarm_s *alminfo)
3277
3278
{
3278
3279
/* Create the RT-Timer alarm */
3279
3280
3280
- flags = spin_lock_irqsave (NULL );
3281
+ flags = spin_lock_irqsave (& g_rtc_lock );
3281
3282
3282
3283
if (cbinfo -> alarm_hdl == NULL )
3283
3284
{
@@ -3288,7 +3289,7 @@ int up_rtc_setalarm(struct alm_setalarm_s *alminfo)
3288
3289
if (ret < 0 )
3289
3290
{
3290
3291
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 );
3292
3293
return ret ;
3293
3294
}
3294
3295
}
@@ -3309,7 +3310,7 @@ int up_rtc_setalarm(struct alm_setalarm_s *alminfo)
3309
3310
ret = OK ;
3310
3311
}
3311
3312
3312
- spin_unlock_irqrestore (NULL , flags );
3313
+ spin_unlock_irqrestore (& g_rtc_lock , flags );
3313
3314
}
3314
3315
3315
3316
return ret ;
@@ -3344,7 +3345,7 @@ int up_rtc_cancelalarm(enum alm_id_e alarmid)
3344
3345
3345
3346
if (cbinfo -> ac_cb != NULL )
3346
3347
{
3347
- flags = spin_lock_irqsave (NULL );
3348
+ flags = spin_lock_irqsave (& g_rtc_lock );
3348
3349
3349
3350
/* Stop and delete the alarm */
3350
3351
@@ -3355,7 +3356,7 @@ int up_rtc_cancelalarm(enum alm_id_e alarmid)
3355
3356
cbinfo -> deadline_us = 0 ;
3356
3357
cbinfo -> alarm_hdl = NULL ;
3357
3358
3358
- spin_unlock_irqrestore (NULL , flags );
3359
+ spin_unlock_irqrestore (& g_rtc_lock , flags );
3359
3360
3360
3361
ret = OK ;
3361
3362
}
@@ -3386,7 +3387,7 @@ int up_rtc_rdalarm(struct timespec *tp, uint32_t alarmid)
3386
3387
DEBUGASSERT ((RTC_ALARM0 <= alarmid ) &&
3387
3388
(alarmid < RTC_ALARM_LAST ));
3388
3389
3389
- flags = spin_lock_irqsave (NULL );
3390
+ flags = spin_lock_irqsave (& g_rtc_lock );
3390
3391
3391
3392
/* Get the alarm according to the alarmid */
3392
3393
@@ -3397,7 +3398,7 @@ int up_rtc_rdalarm(struct timespec *tp, uint32_t alarmid)
3397
3398
tp -> tv_nsec = ((rt_timer_time_us () + g_rtc_save -> offset +
3398
3399
cbinfo -> deadline_us ) % USEC_PER_SEC ) * NSEC_PER_USEC ;
3399
3400
3400
- spin_unlock_irqrestore (NULL , flags );
3401
+ spin_unlock_irqrestore (& g_rtc_lock , flags );
3401
3402
3402
3403
return OK ;
3403
3404
}
0 commit comments