Change in ...osmo-bts[master]: bts-trx: Allocate struct osmo_trx_clock_state as part of bts-trx priv...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Fri Sep 27 15:22:36 UTC 2019


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/15614


Change subject: bts-trx: Allocate struct osmo_trx_clock_state as part of bts-trx private data
......................................................................

bts-trx: Allocate struct osmo_trx_clock_state as part of bts-trx private data

Change-Id: I9b7ffb51423ada74b8be347c57eade08f307f88f
---
M src/osmo-bts-trx/l1_if.h
M src/osmo-bts-trx/main.c
M src/osmo-bts-trx/scheduler_trx.c
3 files changed, 52 insertions(+), 44 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/14/15614/1

diff --git a/src/osmo-bts-trx/l1_if.h b/src/osmo-bts-trx/l1_if.h
index 87df951..29bd246 100644
--- a/src/osmo-bts-trx/l1_if.h
+++ b/src/osmo-bts-trx/l1_if.h
@@ -5,6 +5,50 @@
 #include <osmo-bts/phy_link.h>
 #include "trx_if.h"
 
+/*
+ * TRX frame clock handling
+ *
+ * In a "normal" synchronous PHY layer, we would be polled every time
+ * the PHY needs data for a given frame number.  However, the
+ * OpenBTS-inherited TRX protocol works differently:  We (L1) must
+ * autonomously send burst data based on our own clock, and every so
+ * often (currently every ~ 216 frames), we get a clock indication from
+ * the TRX.
+ *
+ * We're using a MONOTONIC timerfd interval timer for the 4.615ms frame
+ * intervals, and then compute + send the 8 bursts for that frame.
+ *
+ * Upon receiving a clock indication from the TRX, we compensate
+ * accordingly: If we were transmitting too fast, we're delaying the
+ * next interval timer accordingly.  If we were too slow, we immediately
+ * send burst data for the missing frame numbers.
+ */
+
+/*! clock state of a given TRX */
+struct osmo_trx_clock_state {
+	/*! number of FN periods without TRX clock indication */
+	uint32_t fn_without_clock_ind;
+	struct {
+		/*! last FN we processed based on FN period timer */
+		uint32_t fn;
+		/*! time at which we last processed FN */
+		struct timespec tv;
+	} last_fn_timer;
+	struct {
+		/*! last FN we received a clock indication for */
+		uint32_t fn;
+		/*! time at which we received the last clock indication */
+		struct timespec tv;
+	} last_clk_ind;
+	/*! Osmocom FD wrapper for timerfd */
+	struct osmo_fd fn_timer_ofd;
+};
+
+/* gsm_bts->model_priv, specific to osmo-bts-trx */
+struct bts_trx_priv {
+	struct osmo_trx_clock_state clk_s;
+};
+
 struct trx_config {
 	uint8_t			trxd_hdr_ver_req; /* requested TRXD header version */
 	uint8_t			trxd_hdr_ver_use; /* actual TRXD header version in use */
diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c
index b1fa207..cf40ea3 100644
--- a/src/osmo-bts-trx/main.c
+++ b/src/osmo-bts-trx/main.c
@@ -97,6 +97,10 @@
 
 int bts_model_init(struct gsm_bts *bts)
 {
+	struct bts_trx_priv *bts_trx = talloc_zero(bts, struct bts_trx_priv);
+	bts_trx->clk_s.fn_timer_ofd.fd = -1;
+
+	bts->model_priv = bts_trx;
 	bts->variant = BTS_OSMO_TRX;
 	bts->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2) | CIPHER_A5(3);
 
diff --git a/src/osmo-bts-trx/scheduler_trx.c b/src/osmo-bts-trx/scheduler_trx.c
index 8b0c761..6c3a8ff 100644
--- a/src/osmo-bts-trx/scheduler_trx.c
+++ b/src/osmo-bts-trx/scheduler_trx.c
@@ -1580,48 +1580,6 @@
 	return 0;
 }
 
-/*
- * TRX frame clock handling
- *
- * In a "normal" synchronous PHY layer, we would be polled every time
- * the PHY needs data for a given frame number.  However, the
- * OpenBTS-inherited TRX protocol works differently:  We (L1) must
- * autonomously send burst data based on our own clock, and every so
- * often (currently every ~ 216 frames), we get a clock indication from
- * the TRX.
- *
- * We're using a MONOTONIC timerfd interval timer for the 4.615ms frame
- * intervals, and then compute + send the 8 bursts for that frame.
- *
- * Upon receiving a clock indication from the TRX, we compensate
- * accordingly: If we were transmitting too fast, we're delaying the
- * next interval timer accordingly.  If we were too slow, we immediately
- * send burst data for the missing frame numbers.
- */
-
-/*! clock state of a given TRX */
-struct osmo_trx_clock_state {
-	/*! number of FN periods without TRX clock indication */
-	uint32_t fn_without_clock_ind;
-	struct {
-		/*! last FN we processed based on FN period timer */
-		uint32_t fn;
-		/*! time at which we last processed FN */
-		struct timespec tv;
-	} last_fn_timer;
-	struct {
-		/*! last FN we received a clock indication for */
-		uint32_t fn;
-		/*! time at which we received the last clock indication */
-		struct timespec tv;
-	} last_clk_ind;
-	/*! Osmocom FD wrapper for timerfd */
-	struct osmo_fd fn_timer_ofd;
-};
-
-/* TODO: This must go and become part of the phy_link */
-static struct osmo_trx_clock_state g_clk_s = { .fn_timer_ofd.fd = -1 };
-
 /*! duration of a GSM frame in nano-seconds. (120ms/26) */
 #define FRAME_DURATION_nS	4615384
 /*! duration of a GSM frame in micro-seconds (120s/26) */
@@ -1665,7 +1623,8 @@
 static int trx_fn_timer_cb(struct osmo_fd *ofd, unsigned int what)
 {
 	struct gsm_bts *bts = ofd->data;
-	struct osmo_trx_clock_state *tcs = &g_clk_s;
+	struct bts_trx_priv *bts_trx = (struct bts_trx_priv *)bts->model_priv;
+	struct osmo_trx_clock_state *tcs = &bts_trx->clk_s;
 	struct timespec tv_now;
 	uint64_t expire_count;
 	int64_t elapsed_us, error_us;
@@ -1748,7 +1707,8 @@
 /*! called every time we receive a clock indication from TRX */
 int trx_sched_clock(struct gsm_bts *bts, uint32_t fn)
 {
-	struct osmo_trx_clock_state *tcs = &g_clk_s;
+	struct bts_trx_priv *bts_trx = (struct bts_trx_priv *)bts->model_priv;
+	struct osmo_trx_clock_state *tcs = &bts_trx->clk_s;
 	struct timespec tv_now;
 	int elapsed_fn;
 	int64_t elapsed_us, elapsed_us_since_clk, elapsed_fn_since_clk, error_us_since_clk;

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/15614
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I9b7ffb51423ada74b8be347c57eade08f307f88f
Gerrit-Change-Number: 15614
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190927/1a2de668/attachment.htm>


More information about the gerrit-log mailing list