Change in osmocom-bb[master]: trxcon: use libosmocore's TDMA frame number API

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/.

laforge gerrit-no-reply at lists.osmocom.org
Fri Jun 19 20:46:45 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/18872 )

Change subject: trxcon: use libosmocore's TDMA frame number API
......................................................................

trxcon: use libosmocore's TDMA frame number API

Depends: (libosmocore) Ic291fd3644f34964374227a191c7045d79d77e0d
Change-Id: I49a043d8483e116cf2d91820edb511846175173f
---
M src/host/trxcon/l1ctl.c
M src/host/trxcon/sched_clck.c
M src/host/trxcon/sched_lchan_tchh.c
M src/host/trxcon/sched_trx.c
M src/host/trxcon/scheduler.h
5 files changed, 22 insertions(+), 39 deletions(-)

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



diff --git a/src/host/trxcon/l1ctl.c b/src/host/trxcon/l1ctl.c
index 192cdd1..aec304f 100644
--- a/src/host/trxcon/l1ctl.c
+++ b/src/host/trxcon/l1ctl.c
@@ -370,9 +370,9 @@
 	/* Start FBSB expire timer */
 	l1l->fbsb_timer.data = l1l;
 	l1l->fbsb_timer.cb = fbsb_timer_cb;
-	LOGP(DL1C, LOGL_INFO, "Starting FBSB timer %u ms\n", timeout * FRAME_DURATION_uS / 1000);
+	LOGP(DL1C, LOGL_INFO, "Starting FBSB timer %u ms\n", timeout * GSM_TDMA_FN_DURATION_uS / 1000);
 	osmo_timer_schedule(&l1l->fbsb_timer, 0,
-		timeout * FRAME_DURATION_uS);
+		timeout * GSM_TDMA_FN_DURATION_uS);
 
 exit:
 	msgb_free(msg);
diff --git a/src/host/trxcon/sched_clck.c b/src/host/trxcon/sched_clck.c
index 7c814dc..9476ccd 100644
--- a/src/host/trxcon/sched_clck.c
+++ b/src/host/trxcon/sched_clck.c
@@ -50,7 +50,7 @@
 	struct trx_sched *sched = (struct trx_sched *) data;
 	struct timespec tv_now, *tv_clock, elapsed;
 	int64_t elapsed_us;
-	const struct timespec frame_duration = { .tv_sec = 0, .tv_nsec = FRAME_DURATION_uS * 1000 };
+	const struct timespec frame_duration = { .tv_sec = 0, .tv_nsec = GSM_TDMA_FN_DURATION_nS };
 
 	/* Check if transceiver is still alive */
 	if (sched->fn_counter_lost++ == TRX_LOSS_FRAMES) {
@@ -68,7 +68,7 @@
 	elapsed_us = (elapsed.tv_sec * 1000000) + (elapsed.tv_nsec / 1000);
 
 	/* If someone played with clock, or if the process stalled */
-	if (elapsed_us > FRAME_DURATION_uS * MAX_FN_SKEW || elapsed_us < 0) {
+	if (elapsed_us > GSM_TDMA_FN_DURATION_uS * MAX_FN_SKEW || elapsed_us < 0) {
 		LOGP(DSCH, LOGL_NOTICE, "PC clock skew: "
 			"elapsed uS %" PRId64 "\n", elapsed_us);
 
@@ -78,11 +78,11 @@
 	}
 
 	/* Schedule next FN clock */
-	while (elapsed_us > FRAME_DURATION_uS / 2) {
+	while (elapsed_us > GSM_TDMA_FN_DURATION_uS / 2) {
 		timespecadd(tv_clock, &frame_duration, tv_clock);
-		elapsed_us -= FRAME_DURATION_uS;
+		elapsed_us -= GSM_TDMA_FN_DURATION_uS;
 
-		TDMA_FN_INC(&sched->fn_counter_proc);
+		GSM_TDMA_FN_INC(sched->fn_counter_proc);
 
 		/* Call frame callback */
 		if (sched->clock_cb)
@@ -90,7 +90,7 @@
 	}
 
 	osmo_timer_schedule(&sched->clock_timer, 0,
-		FRAME_DURATION_uS - elapsed_us);
+		GSM_TDMA_FN_DURATION_uS - elapsed_us);
 }
 
 static void sched_clck_correct(struct trx_sched *sched,
@@ -108,7 +108,7 @@
 
 	sched->clock_timer.cb = sched_clck_tick;
 	sched->clock_timer.data = sched;
-	osmo_timer_schedule(&sched->clock_timer, 0, FRAME_DURATION_uS);
+	osmo_timer_schedule(&sched->clock_timer, 0, GSM_TDMA_FN_DURATION_uS);
 }
 
 int sched_clck_handle(struct trx_sched *sched, uint32_t fn)
@@ -140,10 +140,10 @@
 	/* Calculate elapsed time / frames since last processed fn */
 	timespecsub(&tv_now, tv_clock, &elapsed);
 	elapsed_us = (elapsed.tv_sec * 1000000) + (elapsed.tv_nsec / 1000);
-	elapsed_fn = TDMA_FN_SUB(fn, sched->fn_counter_proc);
+	elapsed_fn = GSM_TDMA_FN_SUB(fn, sched->fn_counter_proc);
 
 	if (elapsed_fn >= 135774)
-		elapsed_fn -= GSM_HYPERFRAME;
+		elapsed_fn -= GSM_TDMA_HYPERFRAME;
 
 	/* Check for max clock skew */
 	if (elapsed_fn > MAX_FN_SKEW || elapsed_fn < -MAX_FN_SKEW) {
@@ -155,7 +155,7 @@
 	}
 
 	LOGP(DSCH, LOGL_INFO, "GSM clock jitter: %" PRId64 "\n",
-		elapsed_fn * FRAME_DURATION_uS - elapsed_us);
+		elapsed_fn * GSM_TDMA_FN_DURATION_uS - elapsed_us);
 
 	/* Too many frames have been processed already */
 	if (elapsed_fn < 0) {
@@ -164,21 +164,21 @@
 		 * Set clock to the time or last FN should
 		 * have been transmitted
 		 */
-		duration.tv_nsec = (0 - elapsed_fn) * FRAME_DURATION_uS * 1000;
+		duration.tv_nsec = (0 - elapsed_fn) * GSM_TDMA_FN_DURATION_nS;
 		duration.tv_sec = duration.tv_nsec / 1000000000;
 		duration.tv_nsec = duration.tv_nsec % 1000000000;
 		timespecadd(&tv_now, &duration, tv_clock);
 
 		/* Set time to the time our next FN has to be transmitted */
 		osmo_timer_schedule(&sched->clock_timer, 0,
-			FRAME_DURATION_uS * (1 - elapsed_fn));
+			GSM_TDMA_FN_DURATION_uS * (1 - elapsed_fn));
 
 		return 0;
 	}
 
 	/* Transmit what we still need to transmit */
 	while (fn != sched->fn_counter_proc) {
-		TDMA_FN_INC(&sched->fn_counter_proc);
+		GSM_TDMA_FN_INC(sched->fn_counter_proc);
 
 		/* Call frame callback */
 		if (sched->clock_cb)
@@ -187,7 +187,7 @@
 
 	/* Schedule next FN to be transmitted */
 	*tv_clock = tv_now;
-	osmo_timer_schedule(&sched->clock_timer, 0, FRAME_DURATION_uS);
+	osmo_timer_schedule(&sched->clock_timer, 0, GSM_TDMA_FN_DURATION_uS);
 
 	return 0;
 }
diff --git a/src/host/trxcon/sched_lchan_tchh.c b/src/host/trxcon/sched_lchan_tchh.c
index 5edbfcd..b6f0708 100644
--- a/src/host/trxcon/sched_lchan_tchh.c
+++ b/src/host/trxcon/sched_lchan_tchh.c
@@ -171,8 +171,8 @@
 #define BLOCK_FIRST_FN(map) \
 	do { \
 		if (map[i][ARRAY_SIZE(map[i]) - 1] == fn_mf) { \
-			fn_diff = TDMA_FN_DIFF(fn_mf, map[i][0]); \
-			return TDMA_FN_SUB(last_fn, fn_diff); \
+			fn_diff = GSM_TDMA_FN_DIFF(fn_mf, map[i][0]); \
+			return GSM_TDMA_FN_SUB(last_fn, fn_diff); \
 		} \
 	} while (++i < ARRAY_SIZE(map))
 
diff --git a/src/host/trxcon/sched_trx.c b/src/host/trxcon/sched_trx.c
index e172610..b6087ef 100644
--- a/src/host/trxcon/sched_trx.c
+++ b/src/host/trxcon/sched_trx.c
@@ -68,8 +68,7 @@
 		 * Advance frame number, giving the transceiver more
 		 * time until a burst must be transmitted...
 		 */
-		fn = TDMA_FN_SUM(sched->fn_counter_proc,
-			sched->fn_counter_advance);
+		fn = GSM_TDMA_FN_SUM(sched->fn_counter_proc, sched->fn_counter_advance);
 
 		/* Get frame from multiframe */
 		offset = fn % ts->mf_layout->period;
@@ -636,7 +635,7 @@
 	mf = lchan->ts->mf_layout;
 
 	/* How many frames elapsed since the last one? */
-	elapsed = TDMA_FN_SUB(fn, lchan->tdma.last_proc);
+	elapsed = GSM_TDMA_FN_SUB(fn, lchan->tdma.last_proc);
 	if (elapsed > mf->period) {
 		LOGP(DSCHD, LOGL_NOTICE, "Too many (>%u) contiguous TDMA frames elapsed (%u) "
 					 "since the last processed fn=%u\n", mf->period,
@@ -656,7 +655,7 @@
 
 	/* Traverse from fp till the current frame */
 	for (i = 0; i < elapsed - 1; i++) {
-		fp = &mf->frames[TDMA_FN_INC(&fake_meas.fn) % mf->period];
+		fp = &mf->frames[GSM_TDMA_FN_INC(fake_meas.fn) % mf->period];
 		if (fp->dl_chan != lchan->type)
 			continue;
 
diff --git a/src/host/trxcon/scheduler.h b/src/host/trxcon/scheduler.h
index e3c0cb0..43127cc 100644
--- a/src/host/trxcon/scheduler.h
+++ b/src/host/trxcon/scheduler.h
@@ -4,23 +4,7 @@
 #include <time.h>
 
 #include <osmocom/core/timer.h>
-
-#define FRAME_DURATION_uS	4615
-
-#define GSM_SUPERFRAME		(26 * 51)
-#define GSM_HYPERFRAME		(2048 * GSM_SUPERFRAME)
-
-/* TDMA frame number arithmetics */
-#define TDMA_FN_SUM(a, b) \
-	((a + b) % GSM_HYPERFRAME)
-#define TDMA_FN_SUB(a, b) \
-	((a + GSM_HYPERFRAME - b) % GSM_HYPERFRAME)
-#define TDMA_FN_INC(fn) \
-	(*fn = TDMA_FN_SUM(*fn, 1))
-#define TDMA_FN_MIN(a, b) \
-	(a < b ? a : b)
-#define TDMA_FN_DIFF(a, b) \
-	TDMA_FN_MIN(TDMA_FN_SUB(a, b), TDMA_FN_SUB(b, a))
+#include <osmocom/gsm/gsm0502.h>
 
 enum tdma_sched_clck_state {
 	SCH_CLCK_STATE_WAIT,

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

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I49a043d8483e116cf2d91820edb511846175173f
Gerrit-Change-Number: 18872
Gerrit-PatchSet: 2
Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200619/3b83b509/attachment.htm>


More information about the gerrit-log mailing list