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 73:286a739f7c05, committed 2020-02-27
- Comitter:
- andrewboyson
- Date:
- Thu Feb 27 13:02:18 2020 +0000
- Parent:
- 72:8f15a8b142ab
- Child:
- 74:9d336a47ab84
- Commit message:
- Added a method to allow the UTC offset to be changed with a corresponding adjustment to TAI so that the resulting UTC time was not changed. This was used in the clock web page.
Changed in this revision
--- a/clk/clktime.c Thu Feb 27 08:23:47 2020 +0000
+++ b/clk/clktime.c Thu Feb 27 13:02:18 2020 +0000
@@ -37,6 +37,12 @@
countIsSet = true;
}
+void ClkTimeAdjustSeconds(int seconds)
+{
+ __disable_irq();
+ tickCount += (clktime)seconds << CLK_TIME_ONE_SECOND_SHIFT;
+ __enable_irq();
+}
void ClkTimeIncrementByOneSecond(uint32_t startCount)
{
__disable_irq();
--- a/clk/clktime.h Thu Feb 27 08:23:47 2020 +0000 +++ b/clk/clktime.h Thu Feb 27 13:02:18 2020 +0000 @@ -12,6 +12,8 @@ extern void ClkTimeIncrementByOneSecond(uint32_t baseCount); +extern void ClkTimeAdjustSeconds(int seconds); + #define CLK_TIME_ONE_SECOND_SHIFT 30 #define CLK_TIME_ONE_MS_ISH_SHIFT 20 #define CLK_TIME_ONE_SECOND (1UL << CLK_TIME_ONE_SECOND_SHIFT)
--- a/clk/clkutc.c Thu Feb 27 08:23:47 2020 +0000
+++ b/clk/clkutc.c Thu Feb 27 13:02:18 2020 +0000
@@ -26,15 +26,20 @@
static int epochOffset = 0; //12 bits holds enough leap seconds for at least 300 years.
static clktime epochOffset64 = 0;
int ClkUtcGetEpochOffset() { return epochOffset; }
-void ClkUtcSetEpochOffset(int value)
+void ClkUtcSetEpochOffsetWithUtcChange(int value)
{
epochOffset = value;
epochOffset64 = (clktime)epochOffset << CLK_TIME_ONE_SECOND_SHIFT;
GPREG1 = (GPREG1 & 0xFFFF0000) | (value & 0x0000FFFF);
}
-void ClkUtcAddEpochOffset(int value)
+void ClkUtcAddEpochOffsetWithUtcChange(int value)
{
- ClkUtcSetEpochOffset(epochOffset + value);
+ ClkUtcSetEpochOffsetWithUtcChange(epochOffset + value);
+}
+void ClkUtcSetEpochOffsetWithoutUtcChange(int value)
+{
+ ClkTimeAdjustSeconds(value - epochOffset); //Adjust the tai time by the difference
+ ClkUtcSetEpochOffsetWithUtcChange(value);
}
//Next leap second
@@ -102,8 +107,8 @@
if (utc < epochEnd) return; //Do nothing until reached the end of the current epoch
- if (nextLeapForward) ClkUtcAddEpochOffset(+1); //repeat 59
- else ClkUtcAddEpochOffset(-1); //skip 59
+ if (nextLeapForward) ClkUtcAddEpochOffsetWithUtcChange(+1); //repeat 59
+ else ClkUtcAddEpochOffsetWithUtcChange(-1); //skip 59
ClkUtcSetNextLeapEnable(false);
--- a/clk/clkutc.h Thu Feb 27 08:23:47 2020 +0000 +++ b/clk/clkutc.h Thu Feb 27 13:02:18 2020 +0000 @@ -1,8 +1,9 @@ #include "clktime.h" extern int ClkUtcGetEpochOffset(void); -extern void ClkUtcSetEpochOffset(int value); -extern void ClkUtcAddEpochOffset(int value); +extern void ClkUtcSetEpochOffsetWithUtcChange(int value); +extern void ClkUtcAddEpochOffsetWithUtcChange(int value); +extern void ClkUtcSetEpochOffsetWithoutUtcChange(int value); extern int ClkUtcGetNextEpochMonth1970(void); //Months since 1970 extern clktime ClkUtcGetNextEpoch (void);