Andrew Boyson
/
iot
Backing up an unused program in case of future need
Diff: time.cpp
- Revision:
- 6:be97d38e0b01
- Parent:
- 2:06fa34661f19
- Child:
- 7:024ace6d943c
diff -r 6226f3c566ef -r be97d38e0b01 time.cpp --- a/time.cpp Wed May 11 16:42:35 2016 +0000 +++ b/time.cpp Tue May 31 07:35:28 2016 +0000 @@ -1,17 +1,12 @@ #include "mbed.h" #define ONE_MILLION 1000000 -Ticker ticker; -uint64_t unixTime16ths; +static Ticker ticker; +static volatile uint64_t unixTime16ths; static void tick(void) { unixTime16ths++; } -int TimeInit() -{ - ticker.attach_us(&tick, ONE_MILLION >> 4); - return 0; -} void TimeSet(uint32_t t) { unixTime16ths = (uint64_t)t << 4; @@ -27,4 +22,22 @@ uint64_t TimeGet16ths() { return unixTime16ths; -} \ No newline at end of file +} +static Timer timer; +int TimeScanUs = 0; +int TimeMain() +{ + int scanUs = timer.read_us(); + timer.reset(); + timer.start(); + if (scanUs > TimeScanUs) TimeScanUs++; + if (scanUs < TimeScanUs) TimeScanUs--; + return 0; +} +int TimeInit() +{ + ticker.attach_us(&tick, ONE_MILLION >> 4); + timer.stop(); + timer.reset(); + return 0; +}