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: sync.c
- Revision:
- 32:f915ccb1ece3
- Parent:
- 28:b4aa41fdeb68
- Child:
- 33:b9e3c06e7dab
--- a/sync.c Thu Nov 29 16:51:19 2018 +0000
+++ b/sync.c Thu Nov 29 18:43:27 2018 +0000
@@ -2,7 +2,6 @@
#include <stdbool.h>
#include "log.h"
-#include "tick.h"
#include "time.h"
#include "clock.h"
@@ -38,9 +37,9 @@
if (slew > slewMaxTicks) slew = slewMaxTicks;
if (slew < -slewMaxTicks) slew = -slewMaxTicks;
- TickSetSlew(slew);
+ TimeSetSlew(slew);
- if (SyncTrace) LogTimeF("Sync setSlew diff %lld gives slew %lld gives TickSlew %ld\r\n", diff, slew, TickGetSlew());
+ if (SyncTrace) LogTimeF("Sync setSlew diff %lld gives slew %lld gives TickSlew %ld\r\n", diff, slew, TimeGetSlew());
}
static void adjustPpb(int64_t diff)
{
@@ -50,17 +49,17 @@
if (toAdd > maxAdd) toAdd = maxAdd;
if (toAdd < -maxAdd) toAdd = -maxAdd;
- TickAddPpb(-toAdd);
+ TimeAddPpb(-toAdd);
- if (SyncTrace) LogTimeF("Sync setPpb diff %lld gives toAdd %lld gives TickPpb %ld\r\n", diff, toAdd, TickGetPpb());
+ if (SyncTrace) LogTimeF("Sync setPpb diff %lld gives toAdd %lld gives TickPpb %ld\r\n", diff, toAdd, TimeGetPpb());
}
static int64_t lastIntClock = -1; //-1 indicates invalid value. 0 is a valid value.
static int64_t lastExtClock = -1;
static void reset(int64_t thisExtClock)
{
- TickSet(thisExtClock);
- TickSetPpb(0);
+ TimeSet(thisExtClock);
+ TimeSetPpb(0);
lastIntClock = 0;
lastExtClock = 0;
}
@@ -68,7 +67,7 @@
static void sync(int64_t thisExtClock)
{
- if (!TickIsSet()) //Cold start - only ever true if the RTC was not set.
+ if (!TimeIsSet()) //Cold start - only ever true if the RTC was not set.
{
LogTimeF("Sync - cold start of clock so resetting\r\n");
reset(thisExtClock);
@@ -78,11 +77,11 @@
//Get the time at the time of the interrupt
int64_t thisIntClock;
int64_t thisAbsClock;
- TickGetTimesFromSnapshot(&thisIntClock, &thisAbsClock);
+ TimesGetFromSnapshot(&thisIntClock, &thisAbsClock);
//Calulate the time error
int64_t absDiff = thisAbsClock - thisExtClock;
- if (llabs(absDiff) > ((int64_t)ClockMaxOffsetSecs << TICK_ONE_SECOND_SHIFT))
+ if (llabs(absDiff) > ((int64_t)ClockMaxOffsetSecs << TIME_ONE_SECOND_SHIFT))
{
LogTimeF("Sync - offset is greater than %d seconds so resetting\r\n", ClockMaxOffsetSecs);
reset(thisExtClock);
@@ -100,8 +99,8 @@
int64_t periodDiff = intPeriod - extPeriod;
int64_t ppb;
- if (extPeriod == TICK_ONE_SECOND) ppb = periodDiff; //This saves a 64bit shift and division for PPS
- else ppb = (periodDiff << TICK_ONE_SECOND_SHIFT) / extPeriod;
+ if (extPeriod == TIME_ONE_SECOND) ppb = periodDiff; //This saves a 64bit shift and division for PPS
+ else ppb = (periodDiff << TIME_ONE_SECOND_SHIFT) / extPeriod;
adjustPpb(ppb);
setSyncedRate(ppb);
@@ -111,6 +110,6 @@
lastIntClock = thisIntClock;
lastExtClock = thisExtClock;
}
-void SyncPpsI ( ) { TickSaveSnapshot(); }
-void SyncPpsN (time_t t ) { int64_t ticks = (int64_t)t << TICK_ONE_SECOND_SHIFT; sync(ticks); }
-void SyncTicks(int64_t ticks) { TickSaveSnapshot(); sync(ticks); }
+void SyncPpsI ( ) { TimeSaveSnapshot(); }
+void SyncPpsN (time_t t ) { int64_t ticks = (int64_t)t << TIME_ONE_SECOND_SHIFT; sync(ticks); }
+void SyncTicks(int64_t ticks) { TimeSaveSnapshot(); sync(ticks); }