PCU: Fix TA adjustment

Promblem:
 TA provided from L1 PH-DATA-IND is a relative amount of TA adjustment to actual TA
 being used for given TBF. The current TA update algorithm in PCU simply applies the relative
 amount of TA to given TBF but does not take into account of current TA.
 As a result, the PCU will request wrong TA jump for given TBF if the MS is moving away from
 BTS more than 2 km.

 Related issue: http://osmocom.org/issues/2611

Fixes:
- The PCU needs increase or decrease current TA of given TBF on receiving of relative
  amount of TA adjustment provided by PH-DATA-IND from L1
- The PCU needs to set absolute TA of given TBF on receiving absolute TA provided by
  PH-RA-IND from L1.

Change-Id: I65212f8203f1a35278890f51db038d689b2493d5
diff --git a/src/pcu_l1_if.h b/src/pcu_l1_if.h
index 1618260..cb2a6df 100644
--- a/src/pcu_l1_if.h
+++ b/src/pcu_l1_if.h
@@ -43,6 +43,34 @@
 	return qta >> 2;
 }
 
+static inline int8_t sign_qta2ta(int16_t qta)
+{
+	int8_t ta_adj = 0;
+
+	if (qta < -252)
+		qta = -252;
+
+	if (qta > 252)
+		qta = 252;
+
+	/* 1-bit TA adjustment  if TA error reported by L1 is outside +/- 2 qbits */
+	if (qta > 2)
+		ta_adj = 1;
+	if (qta < -2)
+		ta_adj = -1;
+
+	return (qta >> 2) + ta_adj;
+}
+
+static inline uint8_t ta_limit(int16_t ta)
+{
+	if (ta < 0)
+		ta = 0;
+	if (ta > 63)
+		ta = 63;
+	return ta;
+}
+
 /*
  * L1 Measurement values
  */