aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-03-03 22:02:27 -0500
committerKevin O'Connor <kevin@koconnor.net>2017-03-03 22:02:27 -0500
commitc19af4fb2b811dddaf314550307e7bd312aeca94 (patch)
treea73d2746bd23cc70aaeebef82e9ab3708f853cd0 /src
parentf53897758da58ac0201dcfaecbedc8409d828da2 (diff)
downloadkutter-c19af4fb2b811dddaf314550307e7bd312aeca94.tar.gz
kutter-c19af4fb2b811dddaf314550307e7bd312aeca94.tar.xz
kutter-c19af4fb2b811dddaf314550307e7bd312aeca94.zip
serialhdl: Load the mcu's 64bit clock at start of connection
Store a full 64bit uptime in the mcu and query it at the start of each connection. This ensures the host's 64bit clock is always in synch with the mcu's clock. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/basecmd.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/basecmd.c b/src/basecmd.c
index fd80abfd..4b4eca45 100644
--- a/src/basecmd.c
+++ b/src/basecmd.c
@@ -191,6 +191,17 @@ command_get_status(uint32_t *args)
}
DECL_COMMAND_FLAGS(command_get_status, HF_IN_SHUTDOWN, "get_status");
+static uint32_t stats_send_time, stats_send_time_high;
+
+void
+command_get_uptime(uint32_t *args)
+{
+ uint32_t cur = sched_read_time();
+ uint32_t high = stats_send_time_high + (cur < stats_send_time);
+ sendf("uptime high=%u clock=%u", high, cur);
+}
+DECL_COMMAND_FLAGS(command_get_uptime, HF_IN_SHUTDOWN, "get_uptime");
+
#define SUMSQ_BASE 256
DECL_CONSTANT(STATS_SUMSQ_BASE, SUMSQ_BASE);
@@ -215,11 +226,12 @@ stats_task(void)
nextsumsq = 0xffffffff;
sumsq = nextsumsq;
- static uint32_t prev;
- if (sched_is_before(cur, prev + sched_from_us(5000000)))
+ if (sched_is_before(cur, stats_send_time + sched_from_us(5000000)))
return;
- sendf("stats count=%u sum=%u sumsq=%u", count, cur - prev, sumsq);
- prev = cur;
+ sendf("stats count=%u sum=%u sumsq=%u", count, cur - stats_send_time, sumsq);
+ if (cur < stats_send_time)
+ stats_send_time_high++;
+ stats_send_time = cur;
count = sumsq = 0;
}
DECL_TASK(stats_task);