You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/02/16 13:57:23 UTC

[GitHub] [incubator-nuttx] patacongo commented on a change in pull request #274: Improve sim timer

patacongo commented on a change in pull request #274: Improve sim timer
URL: https://github.com/apache/incubator-nuttx/pull/274#discussion_r379905297
 
 

 ##########
 File path: arch/sim/src/sim/up_rtc.c
 ##########
 @@ -0,0 +1,127 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_rtc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/timers/rtc.h>
+#include <nuttx/timers/arch_rtc.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int sim_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
+                          FAR struct rtc_time *rtctime);
+static int sim_rtc_settime(FAR struct rtc_lowerhalf_s *lower,
+                           FAR const struct rtc_time *rtctime);
+static bool sim_rtc_havesettime(FAR struct rtc_lowerhalf_s *lower);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct rtc_ops_s g_sim_rtc_ops =
+{
+  .rdtime      = sim_rtc_rdtime,
+  .settime     = sim_rtc_settime,
+  .havesettime = sim_rtc_havesettime,
+};
+
+static struct rtc_lowerhalf_s g_sim_rtc =
+{
+  .ops         = &g_sim_rtc_ops,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int sim_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
+                          FAR struct rtc_time *rtctime)
+{
+  uint64_t nsec;
+  time_t sec;
+
+
+  nsec = host_gettime(true);
+  sec  = nsec / NSEC_PER_SEC;
+  nsec -= sec * NSEC_PER_SEC;
+
+  gmtime_r(&sec, (FAR struct tm *)rtctime);
+  rtctime->tm_nsec = nsec;
+
+  return OK;
+}
+
+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);
 
 Review comment:
   @yamt "I, as a user, would be very surprised if modifying nuttx time in the sim modifies host OS time."
   
   I think most people would be surprised at that.  I think this is a solution specific to Xiang's applications.  This PR has been merged.
   
   Why don't you consider submitting a new PR to make this behavior configurable?  If you want the behavior, then having to set a configuration operation would eliminate any surprises.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services