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

marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new fb1e286  timepersist; don't restore time from config if coming out of 
POR.
     new 432a006  Merge pull request #1725 from 
mkiiskila/timepersist_clear_cfg_on_por
fb1e286 is described below

commit fb1e28690526955568d40b4aacc82f0701ef19c7
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Tue Mar 26 11:18:02 2019 +0200

    timepersist; don't restore time from config if coming out of POR.
---
 time/timepersist/src/time_persist_config.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/time/timepersist/src/time_persist_config.c 
b/time/timepersist/src/time_persist_config.c
index 2ad5587..cda6b6d 100644
--- a/time/timepersist/src/time_persist_config.c
+++ b/time/timepersist/src/time_persist_config.c
@@ -21,6 +21,7 @@
 
 #if MYNEWT_VAL(TIMEPERSIST_SYS_CONFIG)
 
+#include <hal/hal_system.h>
 #include <config/config.h>
 #include <datetime/datetime.h>
 
@@ -51,8 +52,21 @@ timepersist_conf_set(int argc, char **argv, char *val)
         return OS_ERR_PRIV;
     }
     if (!strcmp(argv[0], "s")) {
-        if (!datetime_parse(val, &tv, &tz)) {
+        if (!val) {
+            memset(&tv, 0, sizeof(tv));
+            memset(&tz, 0, sizeof(tz));
             os_settimeofday(&tv, &tz);
+        } else if (!datetime_parse(val, &tv, &tz)) {
+            if (hal_reset_cause() == HAL_RESET_POR) {
+                /*
+                 * In this case the stored time could be off considerably.
+                 * Schedule an immediate callout which will clear out the
+                 * stored time.
+                 */
+                os_callout_reset(&timepersist_timer, 0);
+            } else {
+                os_settimeofday(&tv, &tz);
+            }
         }
         return OS_OK;
     }
@@ -71,6 +85,8 @@ timepersist(void)
         if (!datetime_format(&tv, &tz, str, DATETIME_BUFSIZE)) {
             conf_save_one("time/s", str);
         }
+    } else if (hal_reset_cause() == HAL_RESET_POR) {
+        conf_save_one("time/s", NULL);
     }
 }
 

Reply via email to