mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
sim/rtc: Don't change the host wall clock in sim_rtc_settime
This commit is contained in:
@@ -58,19 +58,6 @@ uint64_t host_gettime(bool rtc)
|
|||||||
return 1000000000ull * tp.tv_sec + tp.tv_nsec;
|
return 1000000000ull * tp.tv_sec + tp.tv_nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: host_settime
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
void host_settime(bool rtc, uint64_t nsec)
|
|
||||||
{
|
|
||||||
struct timespec tp;
|
|
||||||
|
|
||||||
tp.tv_sec = nsec / 1000000000;
|
|
||||||
tp.tv_nsec = nsec - 1000000000 * tp.tv_sec;
|
|
||||||
clock_settime(rtc ? CLOCK_REALTIME : CLOCK_MONOTONIC, &tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: host_sleepuntil
|
* Name: host_sleepuntil
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|||||||
@@ -228,7 +228,6 @@ void up_longjmp(xcpt_reg_t *jb, int val) noreturn_function;
|
|||||||
/* up_hosttime.c ************************************************************/
|
/* up_hosttime.c ************************************************************/
|
||||||
|
|
||||||
uint64_t host_gettime(bool rtc);
|
uint64_t host_gettime(bool rtc);
|
||||||
void host_settime(bool rtc, uint64_t nsec);
|
|
||||||
void host_sleepuntil(uint64_t nsec);
|
void host_sleepuntil(uint64_t nsec);
|
||||||
|
|
||||||
/* up_simsmp.c **************************************************************/
|
/* up_simsmp.c **************************************************************/
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ static struct rtc_lowerhalf_s g_sim_rtc =
|
|||||||
.ops = &g_sim_rtc_ops,
|
.ops = &g_sim_rtc_ops,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int64_t g_sim_delta;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -67,6 +69,7 @@ static int sim_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
|
|||||||
time_t sec;
|
time_t sec;
|
||||||
|
|
||||||
nsec = host_gettime(true);
|
nsec = host_gettime(true);
|
||||||
|
nsec += g_sim_delta;
|
||||||
sec = nsec / NSEC_PER_SEC;
|
sec = nsec / NSEC_PER_SEC;
|
||||||
nsec -= sec * NSEC_PER_SEC;
|
nsec -= sec * NSEC_PER_SEC;
|
||||||
|
|
||||||
@@ -79,12 +82,10 @@ static int sim_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
|
|||||||
static int sim_rtc_settime(FAR struct rtc_lowerhalf_s *lower,
|
static int sim_rtc_settime(FAR struct rtc_lowerhalf_s *lower,
|
||||||
FAR const struct rtc_time *rtctime)
|
FAR const struct rtc_time *rtctime)
|
||||||
{
|
{
|
||||||
uint64_t nsec;
|
g_sim_delta = mktime((FAR struct tm *)rtctime);
|
||||||
|
g_sim_delta *= NSEC_PER_SEC;
|
||||||
nsec = mktime((FAR struct tm *)rtctime);
|
g_sim_delta += rtctime->tm_nsec;
|
||||||
nsec *= NSEC_PER_SEC;
|
g_sim_delta -= host_gettime(true);
|
||||||
nsec += rtctime->tm_nsec;
|
|
||||||
host_settime(true, nsec);
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user