Skip to content

Commit

Permalink
rtc: There is no need to use sched_[un]lock
Browse files Browse the repository at this point in the history
Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Oct 11, 2024
1 parent edbf007 commit dd19500
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 56 deletions.
19 changes: 11 additions & 8 deletions arch/arm/src/at32/at32_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ static int at32_setrelative(struct rtc_lowerhalf_s *lower,
struct tm time;
time_t seconds;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL);
DEBUGASSERT(alarminfo->id == RTC_ALARMA || alarminfo->id == RTC_ALARMB);
Expand All @@ -522,7 +523,7 @@ static int at32_setrelative(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

/* Get the current time in broken out format */

Expand Down Expand Up @@ -552,7 +553,7 @@ static int at32_setrelative(struct rtc_lowerhalf_s *lower,
ret = at32_setalarm(lower, &setalarm);
}

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand All @@ -565,6 +566,7 @@ static int at32_setrelative(struct rtc_lowerhalf_s *lower,
#endif
struct timespec ts;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL && alarminfo->id == 0);
priv = (struct at32_lowerhalf_s *)lower;
Expand All @@ -575,7 +577,7 @@ static int at32_setrelative(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

/* Get the current time in seconds */

Expand All @@ -585,7 +587,7 @@ static int at32_setrelative(struct rtc_lowerhalf_s *lower,
ret = up_rtc_getdatetime(&time);
if (ret < 0)
{
sched_unlock();
leave_critical_section(flags);
return ret;
}

Expand All @@ -598,7 +600,7 @@ static int at32_setrelative(struct rtc_lowerhalf_s *lower,
ret = up_rtc_gettime(&ts);
if (ret < 0)
{
sched_unlock();
leave_critical_section(flags);
return ret;
}
#else
Expand Down Expand Up @@ -629,7 +631,7 @@ static int at32_setrelative(struct rtc_lowerhalf_s *lower,
cbinfo->priv = NULL;
}

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand Down Expand Up @@ -734,6 +736,7 @@ static int at32_rdalarm(struct rtc_lowerhalf_s *lower,
{
struct alm_rdalarm_s lowerinfo;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL && alarminfo->time != NULL);
DEBUGASSERT(alarminfo->id == RTC_ALARMA || alarminfo->id == RTC_ALARMB);
Expand All @@ -744,14 +747,14 @@ static int at32_rdalarm(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

lowerinfo.ar_id = alarminfo->id;
lowerinfo.ar_time = alarminfo->time;

ret = at32_rtc_rdalarm(&lowerinfo);

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand Down
7 changes: 4 additions & 3 deletions arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ static int cxd56_setrelative(struct rtc_lowerhalf_s *lower,
struct timespec ts;
time_t seconds;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL);
DEBUGASSERT((RTC_ALARM0 <= alarminfo->id) &&
Expand All @@ -372,15 +373,15 @@ static int cxd56_setrelative(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

#if defined(CONFIG_RTC_HIRES)
/* Get the higher resolution time */

ret = up_rtc_gettime(&ts);
if (ret < 0)
{
sched_unlock();
leave_critical_section(flags);
return ret;
}
#else
Expand All @@ -406,7 +407,7 @@ static int cxd56_setrelative(struct rtc_lowerhalf_s *lower,

ret = cxd56_setalarm(lower, &setalarm);

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand Down
14 changes: 8 additions & 6 deletions arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ kinetis_setrelative(struct rtc_lowerhalf_s *lower,
time_t seconds;
struct timespec ts;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL);
DEBUGASSERT(alarminfo->id == RTC_ALARMA);
Expand All @@ -374,15 +375,15 @@ kinetis_setrelative(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

#if defined(CONFIG_RTC_DATETIME)
/* Get the broken out time and convert to seconds */

ret = up_rtc_getdatetime(&time);
if (ret < 0)
{
sched_unlock();
leave_critical_section(flags);
return ret;
}

Expand All @@ -394,7 +395,7 @@ kinetis_setrelative(struct rtc_lowerhalf_s *lower,
ret = up_rtc_gettime(&ts);
if (ret < 0)
{
sched_unlock();
leave_critical_section(flags);
return ret;
}
#endif
Expand All @@ -421,7 +422,7 @@ kinetis_setrelative(struct rtc_lowerhalf_s *lower,

ret = kinetis_setalarm(lower, &setalarm);

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand Down Expand Up @@ -498,6 +499,7 @@ static int kinetis_rdalarm(struct rtc_lowerhalf_s *lower,
{
struct timespec ts;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL && alarminfo->time != NULL);
DEBUGASSERT(alarminfo->id == RTC_ALARMA);
Expand All @@ -508,12 +510,12 @@ static int kinetis_rdalarm(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();
ret = kinetis_rtc_rdalarm(&ts);

localtime_r((const time_t *)&ts.tv_sec,
(struct tm *)alarminfo->time);
sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand Down
5 changes: 3 additions & 2 deletions arch/arm/src/lpc54xx/lpc54_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ static int lpc54_setrelative(struct rtc_lowerhalf_s *lower,
struct lpc54_cbinfo_s *cbinfo;
struct timespec ts;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL && alarminfo->id == 0);
priv = (struct lpc54_lowerhalf_s *)lower;
Expand All @@ -375,7 +376,7 @@ static int lpc54_setrelative(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

/* Get the current time in seconds */

Expand Down Expand Up @@ -403,7 +404,7 @@ static int lpc54_setrelative(struct rtc_lowerhalf_s *lower,
cbinfo->priv = NULL;
}

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand Down
9 changes: 5 additions & 4 deletions arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ static int max326_setrelative(struct rtc_lowerhalf_s *lower,
#endif
struct timespec ts;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL && alarminfo->id == 0);
priv = (struct max326_lowerhalf_s *)lower;
Expand All @@ -440,7 +441,7 @@ static int max326_setrelative(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

/* Get the current time in seconds */

Expand All @@ -450,7 +451,7 @@ static int max326_setrelative(struct rtc_lowerhalf_s *lower,
ret = up_rtc_getdatetime(&time);
if (ret < 0)
{
sched_unlock();
leave_critical_section(flags);
return ret;
}

Expand All @@ -463,7 +464,7 @@ static int max326_setrelative(struct rtc_lowerhalf_s *lower,
ret = up_rtc_gettime(&ts);
if (ret < 0)
{
sched_unlock();
leave_critical_section(flags);
return ret;
}
#else
Expand Down Expand Up @@ -494,7 +495,7 @@ static int max326_setrelative(struct rtc_lowerhalf_s *lower,
cbinfo->priv = NULL;
}

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand Down
19 changes: 11 additions & 8 deletions arch/arm/src/stm32/stm32_rtc_lowerhalf.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ static int stm32_setrelative(struct rtc_lowerhalf_s *lower,
struct tm time;
time_t seconds;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL);
DEBUGASSERT(alarminfo->id == RTC_ALARMA || alarminfo->id == RTC_ALARMB);
Expand All @@ -526,7 +527,7 @@ static int stm32_setrelative(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

/* Get the current time in broken out format */

Expand Down Expand Up @@ -556,7 +557,7 @@ static int stm32_setrelative(struct rtc_lowerhalf_s *lower,
ret = stm32_setalarm(lower, &setalarm);
}

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand All @@ -569,6 +570,7 @@ static int stm32_setrelative(struct rtc_lowerhalf_s *lower,
#endif
struct timespec ts;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL && alarminfo->id == 0);
priv = (struct stm32_lowerhalf_s *)lower;
Expand All @@ -579,7 +581,7 @@ static int stm32_setrelative(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

/* Get the current time in seconds */

Expand All @@ -589,7 +591,7 @@ static int stm32_setrelative(struct rtc_lowerhalf_s *lower,
ret = up_rtc_getdatetime(&time);
if (ret < 0)
{
sched_unlock();
leave_critical_section(flags);
return ret;
}

Expand All @@ -602,7 +604,7 @@ static int stm32_setrelative(struct rtc_lowerhalf_s *lower,
ret = up_rtc_gettime(&ts);
if (ret < 0)
{
sched_unlock();
leave_critical_section(flags);
return ret;
}
#else
Expand Down Expand Up @@ -633,7 +635,7 @@ static int stm32_setrelative(struct rtc_lowerhalf_s *lower,
cbinfo->priv = NULL;
}

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand Down Expand Up @@ -738,6 +740,7 @@ static int stm32_rdalarm(struct rtc_lowerhalf_s *lower,
{
struct alm_rdalarm_s lowerinfo;
int ret = -EINVAL;
irqstate_t flags;

DEBUGASSERT(lower != NULL && alarminfo != NULL && alarminfo->time != NULL);
DEBUGASSERT(alarminfo->id == RTC_ALARMA || alarminfo->id == RTC_ALARMB);
Expand All @@ -748,14 +751,14 @@ static int stm32_rdalarm(struct rtc_lowerhalf_s *lower,
* about being suspended and working on an old time.
*/

sched_lock();
flags = enter_critical_section();

lowerinfo.ar_id = alarminfo->id;
lowerinfo.ar_time = alarminfo->time;

ret = stm32_rtc_rdalarm(&lowerinfo);

sched_unlock();
leave_critical_section(flags);
}

return ret;
Expand Down
Loading

0 comments on commit dd19500

Please sign in to comment.