sim/rtc: Don't change the host wall clock in sim_rtc_settime

This commit is contained in:
Xiang Xiao 2020-02-16 23:31:59 +08:00 committed by Gregory Nutt
parent 5d850fb197
commit 866a531899
3 changed files with 9 additions and 22 deletions

View File

@ -58,19 +58,6 @@ uint64_t host_gettime(bool rtc)
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
****************************************************************************/

View File

@ -228,7 +228,6 @@ void up_longjmp(xcpt_reg_t *jb, int val) noreturn_function;
/* up_hosttime.c ************************************************************/
uint64_t host_gettime(bool rtc);
void host_settime(bool rtc, uint64_t nsec);
void host_sleepuntil(uint64_t nsec);
/* up_simsmp.c **************************************************************/

View File

@ -56,6 +56,8 @@ static struct rtc_lowerhalf_s g_sim_rtc =
.ops = &g_sim_rtc_ops,
};
static int64_t g_sim_delta;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -66,8 +68,9 @@ static int sim_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
uint64_t nsec;
time_t sec;
nsec = host_gettime(true);
sec = nsec / NSEC_PER_SEC;
nsec = host_gettime(true);
nsec += g_sim_delta;
sec = nsec / NSEC_PER_SEC;
nsec -= sec * NSEC_PER_SEC;
gmtime_r(&sec, (FAR struct tm *)rtctime);
@ -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,
FAR const struct rtc_time *rtctime)
{
uint64_t nsec;
nsec = mktime((FAR struct tm *)rtctime);
nsec *= NSEC_PER_SEC;
nsec += rtctime->tm_nsec;
host_settime(true, nsec);
g_sim_delta = mktime((FAR struct tm *)rtctime);
g_sim_delta *= NSEC_PER_SEC;
g_sim_delta += rtctime->tm_nsec;
g_sim_delta -= host_gettime(true);
return OK;
}