Andrew Boyson / clock

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Tue Dec 04 12:26:27 2018 +0000
Revision:
40:53666b1a5848
Child:
46:d3d56cb47940
Renamed timer to hrtimer; added clktimer to handle utc based times.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 40:53666b1a5848 1 #include <stdint.h>
andrewboyson 40:53666b1a5848 2 #include <stdbool.h>
andrewboyson 40:53666b1a5848 3
andrewboyson 40:53666b1a5848 4 #include "clock.h"
andrewboyson 40:53666b1a5848 5
andrewboyson 40:53666b1a5848 6 int64_t ClkTimerSinceRepetitive(int64_t* pLastCount)
andrewboyson 40:53666b1a5848 7 {
andrewboyson 40:53666b1a5848 8 int64_t thisCount = ClockTime();
andrewboyson 40:53666b1a5848 9 int64_t period = thisCount - *pLastCount;
andrewboyson 40:53666b1a5848 10 *pLastCount = thisCount;
andrewboyson 40:53666b1a5848 11 return period;
andrewboyson 40:53666b1a5848 12 }
andrewboyson 40:53666b1a5848 13 int64_t ClkTimerSince(int64_t lastCount)
andrewboyson 40:53666b1a5848 14 {
andrewboyson 40:53666b1a5848 15 return ClockTime() - lastCount;
andrewboyson 40:53666b1a5848 16 }
andrewboyson 40:53666b1a5848 17
andrewboyson 40:53666b1a5848 18 bool ClkTimerRepetitiveTick(int64_t* pLastCount, int64_t interval)
andrewboyson 40:53666b1a5848 19 {
andrewboyson 40:53666b1a5848 20 if (ClockTime() - *pLastCount >= interval)
andrewboyson 40:53666b1a5848 21 {
andrewboyson 40:53666b1a5848 22 *pLastCount += interval;
andrewboyson 40:53666b1a5848 23 return true;
andrewboyson 40:53666b1a5848 24 }
andrewboyson 40:53666b1a5848 25 return false;
andrewboyson 40:53666b1a5848 26 }