You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/16 15:42:35 UTC

[incubator-nuttx] branch pr288 updated: sim/rtc: Don't change the host wall clock in sim_rtc_settime

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr288
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/pr288 by this push:
     new 677939e  sim/rtc: Don't change the host wall clock in sim_rtc_settime
677939e is described below

commit 677939eaad87f6da9137762e2c6ac3c332b0de49
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Feb 16 23:31:59 2020 +0800

    sim/rtc: Don't change the host wall clock in sim_rtc_settime
    
    Change-Id: I5166735ea7efa0594979809a8905934cd8114688
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/sim/up_hosttime.c | 13 -------------
 arch/sim/src/sim/up_internal.h |  1 -
 arch/sim/src/sim/up_rtc.c      | 17 +++++++++--------
 3 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/arch/sim/src/sim/up_hosttime.c b/arch/sim/src/sim/up_hosttime.c
index 21b09bf..9544b39 100644
--- a/arch/sim/src/sim/up_hosttime.c
+++ b/arch/sim/src/sim/up_hosttime.c
@@ -59,19 +59,6 @@ uint64_t host_gettime(bool rtc)
 }
 
 /****************************************************************************
- * 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
  ****************************************************************************/
 
diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h
index 660d80f..e83214f 100644
--- a/arch/sim/src/sim/up_internal.h
+++ b/arch/sim/src/sim/up_internal.h
@@ -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 **************************************************************/
diff --git a/arch/sim/src/sim/up_rtc.c b/arch/sim/src/sim/up_rtc.c
index 726583f..a3b630d 100644
--- a/arch/sim/src/sim/up_rtc.c
+++ b/arch/sim/src/sim/up_rtc.c
@@ -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;
 }