aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/ta_control.c
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2020-01-15 11:01:24 +0100
committerlaforge <laforge@osmocom.org>2020-01-20 14:33:49 +0000
commita0403d3769d3027639e35874c09808ce5c0ba860 (patch)
tree2cce8edf58ad8fd11864475886b5028d4d0e1570 /src/common/ta_control.c
parente7d835ca8c704f7cd256702a31a15b79824e21a4 (diff)
ta_control: move timing advance code from osmo-bts-trx to common
The timing advance controller that is implemented in loops.c of osmo-bts-trx only works for osmo-bts-trx and not for any of the phy based bts. Lets move the timing advance controller into the common part and make it available for every bts. Also lets add a unit-test. Change-Id: If7ddf74db3abc9b9872abe620a0aeebe3327e70a Related: SYS#4567
Diffstat (limited to 'src/common/ta_control.c')
-rw-r--r--src/common/ta_control.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/common/ta_control.c b/src/common/ta_control.c
new file mode 100644
index 00000000..2ccc41a8
--- /dev/null
+++ b/src/common/ta_control.c
@@ -0,0 +1,55 @@
+/* Loop control for Timing Advance */
+
+/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/logging.h>
+
+/* 90% of one bit duration in 1/256 symbols: 256*0.9 */
+#define TOA256_9OPERCENT 230
+
+/* rqd_ta value range */
+#define TOA_MIN 0
+#define TOA_MAX 63
+
+void lchan_ms_ta_ctrl(struct gsm_lchan *lchan)
+{
+ int16_t toa256 = lchan->meas.ms_toa256;
+
+ /* Do not perform any computation when the amount of measurement
+ * results is too little. */
+ if (lchan->meas.num_ul_meas < 4)
+ return;
+
+ if (toa256 < -TOA256_9OPERCENT && lchan->rqd_ta > TOA_MIN) {
+ LOGPLCHAN(lchan, DLOOP, LOGL_INFO,
+ "TOA is too early (%d), now lowering TA from %d to %d\n",
+ toa256, lchan->rqd_ta, lchan->rqd_ta - 1);
+ lchan->rqd_ta--;
+ } else if (toa256 > TOA256_9OPERCENT && lchan->rqd_ta < TOA_MAX) {
+ LOGPLCHAN(lchan, DLOOP, LOGL_INFO,
+ "TOA is too late (%d), now raising TA from %d to %d\n",
+ toa256, lchan->rqd_ta, lchan->rqd_ta + 1);
+ lchan->rqd_ta++;
+ } else
+ LOGPLCHAN(lchan, DLOOP, LOGL_DEBUG,
+ "TOA is correct (%d), keeping current TA of %d\n",
+ toa256, lchan->rqd_ta);
+}