aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-trx
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2019-09-27 16:44:14 +0200
committerpespin <pespin@sysmocom.de>2019-10-05 20:50:13 +0000
commitaccbf5bc732462a1564371dcbbde2f0dc5c23544 (patch)
treefe1d3e66e27d653996a39b4f4b79a31e19eeff71 /src/osmo-bts-trx
parent972c24314694396c9b66fd8175cdcd40f01bdd39 (diff)
bts-trx: Allocate struct osmo_trx_clock_state as part of bts-trx private data
Diffstat (limited to 'src/osmo-bts-trx')
-rw-r--r--src/osmo-bts-trx/l1_if.h44
-rw-r--r--src/osmo-bts-trx/main.c4
-rw-r--r--src/osmo-bts-trx/scheduler_trx.c48
3 files changed, 52 insertions, 44 deletions
diff --git a/src/osmo-bts-trx/l1_if.h b/src/osmo-bts-trx/l1_if.h
index 87df951b..29bd2468 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 b1fa2079..cf40ea3f 100644
--- a/src/osmo-bts-trx/main.c
+++ b/src/osmo-bts-trx/main.c
@@ -97,6 +97,10 @@ int bts_model_handle_options(int argc, char **argv)
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 421cf16d..ac34a112 100644
--- a/src/osmo-bts-trx/scheduler_trx.c
+++ b/src/osmo-bts-trx/scheduler_trx.c
@@ -1581,48 +1581,6 @@ static int trx_sched_fn(struct gsm_bts *bts, uint32_t fn)
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) */
@@ -1666,7 +1624,8 @@ extern int quit;
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;
@@ -1749,7 +1708,8 @@ static int trx_setup_clock(struct gsm_bts *bts, struct osmo_trx_clock_state *tcs
/*! 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;