Skip to content

Commit

Permalink
up_rtc_gettime: add enter_critical_section
Browse files Browse the repository at this point in the history
reason:
We have removed the critical section protection
for the up_rtc_gettime function in common code.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
  • Loading branch information
hujun260 committed Dec 25, 2024
1 parent 7b9232d commit 76a7edc
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arch/arm/src/cxd56xx/cxd56_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,11 @@ time_t up_rtc_time(void)
#ifdef CONFIG_RTC_HIRES
int up_rtc_gettime(struct timespec *tp)
{
irqstate_t flags;
uint64_t count;

flags = enter_critical_section();

count = cxd56_rtc_count();
count += g_rtc_save->offset;

Expand All @@ -410,6 +413,8 @@ int up_rtc_gettime(struct timespec *tp)
tp->tv_nsec = (count % CONFIG_RTC_FREQUENCY) *
(NSEC_PER_SEC / CONFIG_RTC_FREQUENCY);

leave_critical_section(flags);

rtc_dumptime(tp, "Getting time");

return OK;
Expand Down
3 changes: 3 additions & 0 deletions arch/arm/src/efm32/efm32_rtc_burtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,10 @@ time_t up_rtc_time(void)
#ifdef CONFIG_RTC_HIRES
int up_rtc_gettime(struct timespec *tp)
{
irqstate_t flags;
uint64_t val;

flags = enter_critical_section();
val = efm32_get_burtc_tick();

/* Then we can save the time in seconds and fractional seconds. */
Expand All @@ -431,6 +433,7 @@ int up_rtc_gettime(struct timespec *tp)
tp->tv_nsec = (val % CONFIG_RTC_FREQUENCY) *
(NSEC_PER_SEC / CONFIG_RTC_FREQUENCY);

leave_critical_section(flags);
rtcinfo("Get RTC %u.%09u\n", tp->tv_sec, tp->tv_nsec);

return OK;
Expand Down
4 changes: 4 additions & 0 deletions arch/arm/src/max326xx/max32660/max32660_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ time_t up_rtc_time(void)
#ifdef CONFIG_RTC_HIRES
int up_rtc_gettime(struct timespec *tp)
{
irqstate_t flags;
uint64_t tmp;
uint32_t sec;
uint32_t ssec;
uint32_t verify;

flags = enter_critical_section();

/* Read the time handling rollover to full seconds */

do
Expand All @@ -424,6 +427,7 @@ int up_rtc_gettime(struct timespec *tp)

tp->tv_sec = sec;
tp->tv_nsec = (long)tmp;
leave_critical_section(flags);

return OK;
}
Expand Down
3 changes: 3 additions & 0 deletions arch/arm/src/sam34/sam_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,11 +759,13 @@ int up_rtc_gettime(struct timespec *tp)
{
/* This is a hack to emulate a high resolution rtc using the rtt */

irqstate_t flags;
uint32_t rtc_cal;
uint32_t rtc_tim;
uint32_t rtt_val;
struct tm t;

flags = enter_critical_section();
do
{
rtc_cal = getreg32(SAM_RTC_CALR);
Expand Down Expand Up @@ -794,6 +796,7 @@ int up_rtc_gettime(struct timespec *tp)
tp->tv_nsec = (((rtt_val - g_rtt_offset) & (CONFIG_RTC_FREQUENCY - 1)) *
1000000000ull) / CONFIG_RTC_FREQUENCY;

leave_critical_section(flags);
return OK;
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions arch/arm/src/stm32/stm32_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -4308,7 +4308,10 @@ int up_rtc_initialize(void)

int up_rtc_gettime(struct timespec *tp)
{
irqstate_t flags;
uint64_t timestamp;

flags = enter_critical_section();
timestamp = stm32_eth_ptp_gettime();

if (timestamp == 0)
Expand All @@ -4318,11 +4321,13 @@ int up_rtc_gettime(struct timespec *tp)
*/

DEBUGASSERT(!g_rtc_enabled);
leave_critical_section(flags);
return -EBUSY;
}

ptp_to_timespec(timestamp, tp);
clock_timespec_add(tp, &g_stm32_eth_ptp_basetime, tp);
leave_critical_section(flags);

return OK;
}
Expand Down
5 changes: 5 additions & 0 deletions arch/renesas/src/rx65n/rx65n_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ int up_rtc_initialize(void)
#if defined(CONFIG_RTC_HIRES)
int up_rtc_gettime(struct timespec *tp)
{
irqstate_t flags;
uint8_t weekcnt;
uint8_t daycnt;
uint8_t monthcnt;
Expand All @@ -476,6 +477,8 @@ int up_rtc_gettime(struct timespec *tp)
uint8_t regval;
struct tm t;

flags = enter_critical_section();

if (RTC.RCR2.BIT.START == 0)
{
RTC.RCR2.BIT.START = 1;
Expand Down Expand Up @@ -541,6 +544,8 @@ int up_rtc_gettime(struct timespec *tp)
UNUSED(hrcnt);
UNUSED(mincnt);
UNUSED(seccnt);

leave_critical_section(flags);
return OK;
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions arch/x86_64/src/intel64/intel64_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ int up_rtc_initialize(void)

int up_rtc_gettime(struct timespec *tp)
{
irqstate_t flags;
uint64_t tmp;

flags = enter_critical_section();
tmp = rtc_read();
tp->tv_sec = (tmp / NS_PER_SEC);
tp->tv_nsec = (tmp - (tp->tv_sec) * NS_PER_SEC);
leave_critical_section(flags);

return OK;
}
Expand Down

0 comments on commit 76a7edc

Please sign in to comment.