Andrew Boyson / clock

Dependents:   oldheating gps motorhome heating

Files at this revision

API Documentation at this revision

Comitter:
andrewboyson
Date:
Thu Jan 25 19:23:30 2018 +0000
Parent:
27:3d191d41e867
Child:
29:9332cf906aad
Commit message:
Corrected PPS problem

Changed in this revision

sync.c Show annotated file Show diff for this revision Revisions of this file
tick.c Show annotated file Show diff for this revision Revisions of this file
--- a/sync.c	Thu Jan 25 11:17:27 2018 +0000
+++ b/sync.c	Thu Jan 25 19:23:30 2018 +0000
@@ -112,5 +112,5 @@
     lastExtClock = thisExtClock;
 }
 void SyncPpsI (             ) { TickSaveSnapshot(); }
-void SyncPpsN (time_t  t    ) { int64_t ticks = t << TICK_ONE_SECOND_SHIFT; sync(ticks); }
-void SyncTicks(int64_t ticks) { TickSaveSnapshot();                         sync(ticks); }
+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); }
--- a/tick.c	Thu Jan 25 11:17:27 2018 +0000
+++ b/tick.c	Thu Jan 25 19:23:30 2018 +0000
@@ -13,13 +13,13 @@
 static int64_t     slewCount = 0;
 static bool       countIsSet = false;
 static bool           ticked = false;
-static int64_t         ticks = 0;
+static int64_t ticksThisScan = 0;
 static volatile int32_t slew = 0; //ns     - up to +/- 2.147s of slew
 static volatile int32_t ppb  = 0; //This gets set to the last recorded ppb in TickInit
 
 bool    TickIsSet() { return countIsSet; }
 bool    Ticked()    { return ticked; }
-int64_t Ticks()     { return ticks; } //30th bit is one second
+int64_t Ticks()     { return ticksThisScan; } //30th bit is one second
 
 int32_t TickGetSlew() { return slew; }
 void    TickSetSlew(int32_t value) { slew = value; }
@@ -55,7 +55,7 @@
 */
 
 void TickSet(int64_t extClock)
-{
+{    
      int64_t timerCountSinceLastSecond = TimerCountSinceLastSecond();
      int64_t fraction = (timerCountSinceLastSecond << TICK_ONE_SECOND_SHIFT) / TIMER_COUNT_PER_SECOND;
      int64_t    ticks = extClock - fraction;
@@ -65,7 +65,7 @@
         slewCount = 0;
     __enable_irq();
     
-    ticks = extClock;
+    ticksThisScan = extClock;
     
     countIsSet = true;
 }
@@ -82,11 +82,11 @@
     }
     
     //Update TickTime
-    ticks = tickCount + slewCount + TimerMultiplyFractionalPart(TICK_ONE_SECOND + ppb + slew, TimerCountSinceLastSecond());
+    ticksThisScan = tickCount + slewCount + TimerMultiplyFractionalPart(TICK_ONE_SECOND + ppb + slew, TimerCountSinceLastSecond());
     
     //Update the ticked flag
     static bool lastTick = false;
-    bool thisTick = ticks & TICK_ONE_SECOND;
+    bool thisTick = ticksThisScan & TICK_ONE_SECOND;
     ticked = thisTick != lastTick;
     lastTick = thisTick;