Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Diff: clock/clock.c
- Revision:
- 37:330b844f54b6
- Parent:
- 36:6a8a8e1951d4
- Child:
- 38:25b2a3c494aa
--- a/clock/clock.c Sat Dec 01 17:24:49 2018 +0000
+++ b/clock/clock.c Sat Dec 01 19:13:29 2018 +0000
@@ -5,7 +5,7 @@
#include "clktime.h"
#include "clkstate.h"
#include "clksync.h"
-#include "tm.h"
+#include "clktm.h"
#include "rtc.h"
#include "timer.h"
#include "tick.h"
@@ -13,21 +13,21 @@
#define ONE_BILLION 1000000000
-static int64_t nowTicks = 0;
-static time_t nowT = 0;
+static int64_t timeNow = 0;
static int64_t refTicks = 0;
+int64_t ClockTime () { return timeNow; }
int64_t ClockRefTicks() { return refTicks; }
-bool ClockIsSet() { return TimeIsSet(); }
+bool ClockIsSet () { return TimeIsSet(); }
bool ClockIsSynced() { return SyncedRate && SyncedTime; }
-void ClockTmLocal(struct tm* ptm) { TmLocalFromTimeT(nowT, ptm); }
-void ClockTmUtc (struct tm* ptm) { TmUtcFromTimeT(nowT, ptm); }
+void ClockTmLocal(struct tm* ptm) { TimeToTmLocal(timeNow, ptm); }
+void ClockTmUtc (struct tm* ptm) { TimeToTmUtc (timeNow, ptm); }
void ClockAscii(char* p)
{
struct tm tm;
- TmUtcFromTimeT(nowT, &tm);
+ TimeToTmUtc(timeNow, &tm);
sprintf(p, "%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}
void ClockInit()
@@ -51,19 +51,19 @@
if (hadSecond) TimeIncrementByOneSecond(secondsBaseCount);
//Calculate ns and time_t
- nowTicks = TimeNow();
- nowT = nowTicks >> TIME_ONE_SECOND_SHIFT;
+ timeNow = TimeNow();
//Establish the scan times
ScanMain();
//Record the time the clock started
- if (SyncedTime && SyncedRate) refTicks = nowTicks;
+ if (SyncedTime && SyncedRate) refTicks = timeNow;
//Set a one shot memory for having had a tick
- static time_t lastT = 0;
- ClockTicked = lastT > 0 && lastT != nowT;
- lastT = nowT;
+ static int lastT = 0;
+ int thisT = timeNow >> TIME_ONE_SECOND_SHIFT;
+ ClockTicked = lastT > 0 && lastT != thisT;
+ lastT = thisT;
if (TimeIsSet())
{
@@ -85,10 +85,8 @@
RtcGetTm(&tm);
if (lastRtcSecond > 0 && tm.tm_sec != lastRtcSecond)
{
- time_t t = TmUtcToTimeT(&tm);
- TimeSet((int64_t)t << TIME_ONE_SECOND_SHIFT);
- nowTicks = TimeNow();
- nowT = nowTicks >> TIME_ONE_SECOND_SHIFT;
+ timeNow = TimeFromTmUtc(&tm);
+ TimeSet(timeNow);
LogTimeF("Clock set from RTC\r\n");
}
lastRtcSecond = tm.tm_sec;