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
Revision 55:e18983651004, committed 2019-02-21
- Comitter:
- andrewboyson
- Date:
- Thu Feb 21 15:42:49 2019 +0000
- Parent:
- 54:a3c018ceca77
- Child:
- 56:3e4fe2d3db4e
- Commit message:
- Optimised conversion between utc and tai.
Changed in this revision
| clk/clkutc.c | Show annotated file Show diff for this revision Revisions of this file |
--- a/clk/clkutc.c Thu Feb 21 12:47:15 2019 +0000
+++ b/clk/clkutc.c Thu Feb 21 15:42:49 2019 +0000
@@ -22,11 +22,13 @@
*/
//Leap seconds
-static int epochOffset = 0; //12 bits holds enough leap seconds for at least 300 years.
+static int epochOffset = 0; //12 bits holds enough leap seconds for at least 300 years.
+static int64_t epochOffset64 = 0;
int ClkUtcGetEpochOffset() { return epochOffset; }
void ClkUtcSetEpochOffset(int value)
{
- epochOffset = value;
+ epochOffset = value;
+ epochOffset64 = (int64_t)epochOffset << CLK_TIME_ONE_SECOND_SHIFT;
GPREG1 = GPREG1 & 0xFFFF0000 | value & 0x0000FFFF;
}
void ClkUtcAddEpochOffset(int value)
@@ -76,16 +78,17 @@
void ClkUtcInit(void)
{
- epochOffset = GPREG1 & 0x0000FFFF;
- nextEpochMonth1970 = (GPREG1 & 0x0FFF0000) >> 16;
+ epochOffset = GPREG1 & 0x0000FFFF;
+ epochOffset64 = (int64_t)epochOffset << CLK_TIME_ONE_SECOND_SHIFT;
+ nextEpochMonth1970 = (GPREG1 & 0x0FFF0000) >> 16;
makeNextEpochUtc();
- nextLeapEnable = GPREG1 & 0x10000000;
- nextLeapForward = GPREG1 & 0x20000000;
+ nextLeapEnable = GPREG1 & 0x10000000;
+ nextLeapForward = GPREG1 & 0x20000000;
}
-int64_t ClkUtcFromTai(int64_t tai) { return tai - ((int64_t)epochOffset << CLK_TIME_ONE_SECOND_SHIFT); }
-int64_t ClkUtcToTai (int64_t utc) { return utc + ((int64_t)epochOffset << CLK_TIME_ONE_SECOND_SHIFT); }
+int64_t ClkUtcFromTai(int64_t tai) { return tai - epochOffset64; }
+int64_t ClkUtcToTai (int64_t utc) { return utc + epochOffset64; }
void ClkUtcCheckAdjustLeapSecondCount(int64_t tai)
{