aboutsummaryrefslogtreecommitdiffstats
path: root/Transceiver52M/radioClock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Transceiver52M/radioClock.cpp')
-rw-r--r--Transceiver52M/radioClock.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/Transceiver52M/radioClock.cpp b/Transceiver52M/radioClock.cpp
index 710018a..d9d5229 100644
--- a/Transceiver52M/radioClock.cpp
+++ b/Transceiver52M/radioClock.cpp
@@ -29,6 +29,35 @@ void RadioClock::set(const GSM::Time& wTime)
mLock.unlock();
}
+void RadioClock::adjust(GSM::Time& wOffset)
+{
+ int tn_diff, fn_diff = 0;
+
+ mLock.lock();
+
+ /* Modulo TN adustment */
+ tn_diff = mClock.TN() + wOffset.TN();
+ if (tn_diff < 0) {
+ tn_diff += 8;
+ fn_diff--;
+ } else if (tn_diff >= 8) {
+ tn_diff -= 8;
+ fn_diff++;
+ }
+
+ /* Modulo FN adjustment */
+ fn_diff += mClock.FN() + wOffset.FN();
+ if (fn_diff < 0)
+ fn_diff += GSM::gHyperframe;
+ else if ((unsigned) fn_diff >= GSM::gHyperframe)
+ fn_diff = fn_diff - GSM::gHyperframe;
+
+ mClock = GSM::Time(fn_diff, tn_diff);
+ updateSignal.signal();
+
+ mLock.unlock();
+}
+
void RadioClock::incTN()
{
mLock.lock();