changeset 116:4ce87a30383f

fc-rfcal-txband: channel calibration implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 13 Feb 2018 06:22:32 +0000
parents 1e49bb52b07e
children 4c3f4231a021
files autocal/txbandmain.c autocal/txcalchan.c
diffstat 2 files changed, 71 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/autocal/txbandmain.c	Tue Feb 13 05:17:13 2018 +0000
+++ b/autocal/txbandmain.c	Tue Feb 13 06:22:32 2018 +0000
@@ -136,13 +136,23 @@
 	txcal_basis_compute();
 	/* actual Tx levels calibration */
 	calibrate_tx_levels();
+	/* channel calibration */
+	calibrate_tx_calchan();
+	printf("Uploading calchan table\n");
+	upload_tx_calchan();
 
+#if 0
 	/*
 	 * We need to insert a delay between stopping Tx
 	 * and doing the FFS write in order to avoid
 	 * an intermittent fw crash on the DUT.
+	 *
+	 * This delay may no longer be needed after
+	 * the addition of calchan table upload above,
+	 * so commenting it out to test.
 	 */
 	usleep(100000);
+#endif
 
 	printf("Saving calibrated values in FFS\n");
 	misc_enable(CFG_WRITE_TX_CAL);
--- a/autocal/txcalchan.c	Tue Feb 13 05:17:13 2018 +0000
+++ b/autocal/txcalchan.c	Tue Feb 13 06:22:32 2018 +0000
@@ -11,7 +11,11 @@
 #include "txband.h"
 #include "txcalchan.h"
 
+extern double tx_power_meas();
+extern vout_t dbm_to_vout();
+
 extern struct txcal_band *txcal_band;
+extern struct tx_level tx_levels[MAX_TX_LEVELS];
 
 unsigned tx_calchan_values[TX_CALCHAN_TABLES][TX_CALCHAN_ENTRIES];
 
@@ -25,6 +29,63 @@
 	return(0);
 }
 
+tx_calchan_one_table(tblnum)
+	unsigned tblnum;
+{
+	vout_t vout[TX_CALCHAN_ENTRIES];
+	char cmd[80];
+	unsigned n, arfcn, plidx;
+	double meas;
+	int nanflag = 0;
+	int apc_delta;
+	unsigned apc_wanted;
+
+	printf("Calibrating Tx channel correction table %u (PL #%u)\n", tblnum,
+		txcal_band->calchan_plnum[tblnum]);
+	do_txpw(TX_PWR_LEVEL, txcal_band->calchan_plnum[tblnum]);
+	plidx = txcal_band->calchan_plnum[tblnum] - txcal_band->start_plnum;
+	printf("Starting RF Tx on the DUT\n");
+	do_rfe(RX_TX_TCH);
+	for (n = 0; n < TX_CALCHAN_ENTRIES; n++) {
+		arfcn = txcal_band->calchan_ranges[n].test_arfcn;
+		sprintf(cmd, "txpwr-cal-channel %u\n", arfcn);
+		tsid_command(cmd);
+		do_rfpw(TCH_ARFCN, arfcn);
+		usleep(20000);
+		meas = tx_power_meas();
+		printf("ARFCN=%u: %.2f dBm\n", arfcn, meas);
+		if (isnan(meas))
+			nanflag = 1;
+		vout[n] = dbm_to_vout(meas);
+	}
+	printf("Stopping RF Tx on the DUT\n");
+	do_rfe(STOP_ALL);
+	if (nanflag) {
+		printf("Error: got NaN power measurement, aborting\n");
+		exit(ERROR_RFFAIL);
+	}
+
+	for (n = 0; n < TX_CALCHAN_ENTRIES; n++) {
+		apc_delta = (vout[txcal_band->ref_subband] - vout[n]) /
+				tx_levels[plidx].slope;
+		apc_wanted = tx_levels[plidx].apc + apc_delta;
+		tx_calchan_values[tblnum][n] = (apc_wanted * 128) /
+				tx_levels[plidx].apc;
+		printf("ARFCN %u-%u: correction=%u\n",
+			txcal_band->calchan_ranges[n].lower_bound,
+			txcal_band->calchan_ranges[n].upper_bound,
+			tx_calchan_values[tblnum][n]);
+	}
+}
+
+calibrate_tx_calchan()
+{
+	unsigned tblnum;
+
+	for (tblnum = 0; tblnum < TX_CALCHAN_TABLES; tblnum++)
+		tx_calchan_one_table(tblnum);
+}
+
 upload_tx_calchan()
 {
 	unsigned i, j;