pespin has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/c/osmo-bts/+/15613 )

Change subject: struct gsm_bts: Add model_priv pointer handing bts_model 
specific data
......................................................................

struct gsm_bts: Add model_priv pointer handing bts_model specific data

Currently there's bts-virtual specific fields in gsm_bts which is not used
by other models and are always allocated.
An alternative would be having a union with different structs inside,
one per model, but since we already have the bts_model abstraction, in this
case it makes more sense to use that abstraction instead of filling code
with preprocessor ifdefs to guard against non-defined types, etc.

Existing model specific data is moved there.

This new infra will be user further in forthcoming commits.

Related: OS#4215
Change-Id: Ib17a752cdbaa7d5eb8c5dfa0b197f80a4f38b38e
---
M include/osmo-bts/gsm_data_shared.h
M src/osmo-bts-oc2g/l1_if.h
M src/osmo-bts-oc2g/main.c
M src/osmo-bts-virtual/l1_if.h
M src/osmo-bts-virtual/main.c
M src/osmo-bts-virtual/scheduler_virtbts.c
6 files changed, 33 insertions(+), 24 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  fixeria: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmo-bts/gsm_data_shared.h 
b/include/osmo-bts/gsm_data_shared.h
index cf7b715..5d8bc76 100644
--- a/include/osmo-bts/gsm_data_shared.h
+++ b/include/osmo-bts/gsm_data_shared.h
@@ -775,19 +775,7 @@
                char *sock_path;
        } pcu;

-       struct {
-               uint32_t last_fn;
-               struct timeval tv_clock;
-               struct osmo_timer_list fn_timer;
-       } vbts;
-#ifdef ENABLE_OC2GBTS
-        /* specific to Open Cellular 2G BTS */
-        struct {
-                uint8_t led_ctrl_mode;                                  /* 0: 
control by BTS, 1: not control by BTS */
-                struct llist_head ceased_alarm_list;    /* ceased alarm list*/
-                unsigned int rtp_drift_thres_ms;                /* RTP 
timestamp drift detection threshold */
-        } oc2g;
-#endif
+       void *model_priv; /* Allocated by bts_model, contains model specific 
data pointer */
 };


diff --git a/src/osmo-bts-oc2g/l1_if.h b/src/osmo-bts-oc2g/l1_if.h
index 38699e0..e4b8feb 100644
--- a/src/osmo-bts-oc2g/l1_if.h
+++ b/src/osmo-bts-oc2g/l1_if.h
@@ -30,6 +30,13 @@
        _NUM_MQ_WRITE
 };

+/* gsm_bts->model_priv, specific to Open Cellular 2G BTS */
+struct bts_oc2g_priv {
+       uint8_t led_ctrl_mode;                  /* 0: control by BTS, 1: not 
control by BTS */
+       struct llist_head ceased_alarm_list;    /* ceased alarm list*/
+       unsigned int rtp_drift_thres_ms;        /* RTP timestamp drift 
detection threshold */
+};
+
 struct calib_send_state {
        FILE *fp;
        const char *path;
diff --git a/src/osmo-bts-oc2g/main.c b/src/osmo-bts-oc2g/main.c
index 5b66c6f..abecba1 100644
--- a/src/osmo-bts-oc2g/main.c
+++ b/src/osmo-bts-oc2g/main.c
@@ -87,15 +87,17 @@
        static struct osmo_fd accept_fd, read_fd;
        int rc;

+       struct bts_oc2g_priv *bts_oc2g = talloc(bts, struct bts_oc2g_priv);
+       bts->model_priv = bts_oc2g;
        bts->variant = BTS_OSMO_OC2G;
        bts->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2) | CIPHER_A5(3);
        /* specific default values for OC2G platform */

        /* TODO(oramadan) MERGE
-       bts->oc2g.led_ctrl_mode = OC2G_BTS_LED_CTRL_MODE_DEFAULT;
+       bts_oc2g->led_ctrl_mode = OC2G_BTS_LED_CTRL_MODE_DEFAULT;
        */
        /* RTP drift threshold default */
-       /* bts->oc2g.rtp_drift_thres_ms = OC2G_BTS_RTP_DRIFT_THRES_DEFAULT; */
+       /* bts_oc2g->rtp_drift_thres_ms = OC2G_BTS_RTP_DRIFT_THRES_DEFAULT; */

        rc = oml_router_init(bts, OML_ROUTER_PATH, &accept_fd, &read_fd);
        if (rc < 0) {
diff --git a/src/osmo-bts-virtual/l1_if.h b/src/osmo-bts-virtual/l1_if.h
index 6a843b3..075856f 100644
--- a/src/osmo-bts-virtual/l1_if.h
+++ b/src/osmo-bts-virtual/l1_if.h
@@ -5,6 +5,13 @@

 #include "virtual_um.h"

+/* gsm_bts->model_priv, specific to osmo-bts-virtual */
+struct bts_virt_priv {
+       uint32_t last_fn;
+       struct timeval tv_clock;
+       struct osmo_timer_list fn_timer;
+};
+
 struct vbts_l1h {
        struct gsm_bts_trx      *trx;
        struct l1sched_trx      l1s;
diff --git a/src/osmo-bts-virtual/main.c b/src/osmo-bts-virtual/main.c
index aa1c608..c329f3a 100644
--- a/src/osmo-bts-virtual/main.c
+++ b/src/osmo-bts-virtual/main.c
@@ -47,6 +47,7 @@
 #include <osmo-bts/l1sap.h>
 #include <osmo-bts/phy_link.h>
 #include "virtual_um.h"
+#include "l1_if.h"

 /* dummy, since no direct dsp support */
 uint32_t trx_get_hlayer1(struct gsm_bts_trx *trx)
@@ -56,6 +57,8 @@

 int bts_model_init(struct gsm_bts *bts)
 {
+       struct bts_virt_priv *bts_virt = talloc_zero(bts, struct bts_virt_priv);
+       bts->model_priv = bts_virt;
        bts->variant = BTS_OSMO_VIRTUAL;
        bts->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2) | CIPHER_A5(3);

diff --git a/src/osmo-bts-virtual/scheduler_virtbts.c 
b/src/osmo-bts-virtual/scheduler_virtbts.c
index 259a573..83c37f3 100644
--- a/src/osmo-bts-virtual/scheduler_virtbts.c
+++ b/src/osmo-bts-virtual/scheduler_virtbts.c
@@ -562,8 +562,9 @@
 static void vbts_fn_timer_cb(void *data)
 {
        struct gsm_bts *bts = data;
+       struct bts_virt_priv *bts_virt = (struct bts_virt_priv 
*)bts->model_priv;
        struct timeval tv_now;
-       struct timeval *tv_clock = &bts->vbts.tv_clock;
+       struct timeval *tv_clock = &bts_virt->tv_clock;
        int32_t elapsed_us;

        gettimeofday(&tv_now, NULL);
@@ -587,28 +588,29 @@
                };
                timeradd(tv_clock, &tv_frame, tv_clock);
                /* increment the frame number in the BTS model instance */
-               bts->vbts.last_fn = (bts->vbts.last_fn + 1) % GSM_HYPERFRAME;
-               vbts_sched_fn(bts, bts->vbts.last_fn);
+               bts_virt->last_fn = (bts_virt->last_fn + 1) % GSM_HYPERFRAME;
+               vbts_sched_fn(bts, bts_virt->last_fn);
                elapsed_us -= FRAME_DURATION_uS;
        }

        /* re-schedule the timer */
        /* timer is set to frame duration - elapsed time to guarantee that this 
cb method will be
         * periodically executed every 4.615ms */
-       osmo_timer_schedule(&bts->vbts.fn_timer, 0, FRAME_DURATION_uS - 
elapsed_us);
+       osmo_timer_schedule(&bts_virt->fn_timer, 0, FRAME_DURATION_uS - 
elapsed_us);
 }

 int vbts_sched_start(struct gsm_bts *bts)
 {
+       struct bts_virt_priv *bts_virt = (struct bts_virt_priv 
*)bts->model_priv;
        LOGP(DL1P, LOGL_NOTICE, "starting VBTS scheduler\n");

-       memset(&bts->vbts.fn_timer, 0, sizeof(bts->vbts.fn_timer));
-       bts->vbts.fn_timer.cb = vbts_fn_timer_cb;
-       bts->vbts.fn_timer.data = bts;
+       memset(&bts_virt->fn_timer, 0, sizeof(bts_virt->fn_timer));
+       bts_virt->fn_timer.cb = vbts_fn_timer_cb;
+       bts_virt->fn_timer.data = bts;

-       gettimeofday(&bts->vbts.tv_clock, NULL);
+       gettimeofday(&bts_virt->tv_clock, NULL);
        /* trigger the first timer after 4615us (a frame duration) */
-       osmo_timer_schedule(&bts->vbts.fn_timer, 0, FRAME_DURATION_uS);
+       osmo_timer_schedule(&bts_virt->fn_timer, 0, FRAME_DURATION_uS);

        return 0;
 }

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

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: Ib17a752cdbaa7d5eb8c5dfa0b197f80a4f38b38e
Gerrit-Change-Number: 15613
Gerrit-PatchSet: 5
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to