[PATCH] sysmobts: Use status flags instead of direct LED access

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/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Mon Nov 4 17:13:52 UTC 2013


Currently the LEDs are being accessed directly from within the
l1_if.c file. So the handling of rf mute and activate/deactivate both
access LED_RF_ACTIVE directly. This may lead to an inconsistent LED
status.

This patch replaces these calls to sysmobts_led_set() by an abstract
equivalent bts_update_status(), that uses a set of independant status
ids. The associated values can than be combined into a visible LED
status. Currently LED_RF_ACTIVE is on iff BTS_STATUS_RF_ACTIVE is set
and BTS_STATUS_RF_MUTE is not set.

Sponsored-by: On-Waves ehf
---
 include/osmo-bts/bts.h     |    7 +++++++
 src/osmo-bts-sysmo/l1_if.c |    6 +++---
 src/osmo-bts-sysmo/main.c  |   25 +++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index 583c1eb..503dcb0 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -3,6 +3,11 @@
 
 #include <osmo-bts/gsm_data.h>
 
+enum bts_global_status {
+	BTS_STATUS_RF_ACTIVE,
+	BTS_STATUS_RF_MUTE,
+};
+
 extern void *tall_bts_ctx;
 
 int bts_init(struct gsm_bts *bts);
@@ -27,5 +32,7 @@ int lchan_init_lapdm(struct gsm_lchan *lchan);
 
 void load_timer_start(struct gsm_bts *bts);
 
+void bts_update_status(enum bts_global_status which, int on);
+
 #endif /* _BTS_H */
 
diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c
index 36df462..71920ac 100644
--- a/src/osmo-bts-sysmo/l1_if.c
+++ b/src/osmo-bts-sysmo/l1_if.c
@@ -1021,7 +1021,7 @@ static int activate_rf_compl_cb(struct gsm_bts_trx *trx, struct msgb *resp)
 				get_value_string(femtobts_l1status_names, status));
 			bts_shutdown(trx->bts, "RF-ACT failure");
 		} else
-			sysmobts_led_set(LED_RF_ACTIVE, 1);
+			bts_update_status(BTS_STATUS_RF_ACTIVE, 1);
 
 		/* signal availability */
 		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OK);
@@ -1032,7 +1032,7 @@ static int activate_rf_compl_cb(struct gsm_bts_trx *trx, struct msgb *resp)
 		for (i = 0; i < ARRAY_SIZE(trx->ts); i++)
 			oml_mo_state_chg(&trx->ts[i].mo, NM_OPSTATE_DISABLED, NM_AVSTATE_DEPENDENCY);
 	} else {
-		sysmobts_led_set(LED_RF_ACTIVE, 0);
+		bts_update_status(BTS_STATUS_RF_ACTIVE, 0);
 		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OFF_LINE);
 		oml_mo_state_chg(&trx->bb_transc.mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OFF_LINE);
 	}
@@ -1118,7 +1118,7 @@ static int mute_rf_compl_cb(struct gsm_bts_trx *trx, struct msgb *resp)
 	} else {
 		LOGP(DL1C, LOGL_INFO, "Rx RF-MUTE.conf with status=%s\n",
 		     get_value_string(femtobts_l1status_names, status));
-		sysmobts_led_set(LED_RF_ACTIVE, !fl1h->last_rf_mute[0]);
+		bts_update_status(BTS_STATUS_RF_MUTE, fl1h->last_rf_mute[0]);
 		oml_mo_rf_lock_chg(&trx->mo, fl1h->last_rf_mute, 1);
 	}
 
diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c
index 5a7c812..046326b 100644
--- a/src/osmo-bts-sysmo/main.c
+++ b/src/osmo-bts-sysmo/main.c
@@ -51,6 +51,7 @@
 #include "utils.h"
 #include "eeprom.h"
 #include "l1_if.h"
+#include "hw_misc.h"
 
 /* FIXME: read from real hardware */
 const uint8_t abis_mac[6] = { 0,1,2,3,4,5 };
@@ -122,6 +123,30 @@ void clk_cal_use_eeprom(struct gsm_bts *bts)
 		"Read clock calibration(%d) from EEPROM.\n", hdl->clk_cal);
 }
 
+void bts_update_status(enum bts_global_status which, int on)
+{
+	static uint64_t states = 0;
+	uint64_t old_states = states;
+	int led_rf_active_on;
+
+	if (on)
+		states |= (1ULL << which);
+	else
+		states &= ~(1ULL << which);
+
+	led_rf_active_on =
+		(states & (1ULL << BTS_STATUS_RF_ACTIVE)) &&
+		!(states & (1ULL << BTS_STATUS_RF_MUTE));
+
+	LOGP(DL1C, LOGL_INFO,
+	     "Set global status #%d to %d (%04llx -> %04llx), LEDs: ACT %d\n",
+	     which, on,
+	     (long long)old_states, (long long)states,
+	     led_rf_active_on);
+
+	sysmobts_led_set(LED_RF_ACTIVE, led_rf_active_on);
+}
+
 static void print_help()
 {
 	printf( "Some useful options:\n"
-- 
1.7.9.5





More information about the OpenBSC mailing list