annotate autocal/txcalchan.c @ 116:4ce87a30383f

fc-rfcal-txband: channel calibration implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 13 Feb 2018 06:22:32 +0000
parents 3f63e71b6422
children 4c3f4231a021
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
77
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains the code for handling Tx calchan tables.
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdio.h>
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdlib.h>
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <endian.h>
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <rvinterf/l1tm.h>
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <rvinterf/exitcodes.h>
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "txband.h"
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "txcalchan.h"
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
116
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
14 extern double tx_power_meas();
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
15 extern vout_t dbm_to_vout();
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
16
77
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern struct txcal_band *txcal_band;
116
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
18 extern struct tx_level tx_levels[MAX_TX_LEVELS];
77
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 unsigned tx_calchan_values[TX_CALCHAN_TABLES][TX_CALCHAN_ENTRIES];
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 init_tx_calchan()
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 unsigned i, j;
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 for (i = 0; i < TX_CALCHAN_TABLES; i++)
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 for (j = 0; j < TX_CALCHAN_ENTRIES; j++)
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 tx_calchan_values[i][j] = 128;
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return(0);
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
116
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
32 tx_calchan_one_table(tblnum)
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
33 unsigned tblnum;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
34 {
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
35 vout_t vout[TX_CALCHAN_ENTRIES];
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
36 char cmd[80];
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
37 unsigned n, arfcn, plidx;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
38 double meas;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
39 int nanflag = 0;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
40 int apc_delta;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
41 unsigned apc_wanted;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
42
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
43 printf("Calibrating Tx channel correction table %u (PL #%u)\n", tblnum,
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
44 txcal_band->calchan_plnum[tblnum]);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
45 do_txpw(TX_PWR_LEVEL, txcal_band->calchan_plnum[tblnum]);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
46 plidx = txcal_band->calchan_plnum[tblnum] - txcal_band->start_plnum;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
47 printf("Starting RF Tx on the DUT\n");
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
48 do_rfe(RX_TX_TCH);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
49 for (n = 0; n < TX_CALCHAN_ENTRIES; n++) {
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
50 arfcn = txcal_band->calchan_ranges[n].test_arfcn;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
51 sprintf(cmd, "txpwr-cal-channel %u\n", arfcn);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
52 tsid_command(cmd);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
53 do_rfpw(TCH_ARFCN, arfcn);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
54 usleep(20000);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
55 meas = tx_power_meas();
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
56 printf("ARFCN=%u: %.2f dBm\n", arfcn, meas);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
57 if (isnan(meas))
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
58 nanflag = 1;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
59 vout[n] = dbm_to_vout(meas);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
60 }
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
61 printf("Stopping RF Tx on the DUT\n");
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
62 do_rfe(STOP_ALL);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
63 if (nanflag) {
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
64 printf("Error: got NaN power measurement, aborting\n");
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
65 exit(ERROR_RFFAIL);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
66 }
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
67
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
68 for (n = 0; n < TX_CALCHAN_ENTRIES; n++) {
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
69 apc_delta = (vout[txcal_band->ref_subband] - vout[n]) /
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
70 tx_levels[plidx].slope;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
71 apc_wanted = tx_levels[plidx].apc + apc_delta;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
72 tx_calchan_values[tblnum][n] = (apc_wanted * 128) /
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
73 tx_levels[plidx].apc;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
74 printf("ARFCN %u-%u: correction=%u\n",
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
75 txcal_band->calchan_ranges[n].lower_bound,
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
76 txcal_band->calchan_ranges[n].upper_bound,
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
77 tx_calchan_values[tblnum][n]);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
78 }
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
79 }
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
80
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
81 calibrate_tx_calchan()
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
82 {
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
83 unsigned tblnum;
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
84
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
85 for (tblnum = 0; tblnum < TX_CALCHAN_TABLES; tblnum++)
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
86 tx_calchan_one_table(tblnum);
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
87 }
4ce87a30383f fc-rfcal-txband: channel calibration implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 77
diff changeset
88
77
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 upload_tx_calchan()
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 {
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 unsigned i, j;
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 struct tx_calchan_entry l1_table[TX_CALCHAN_TABLES][TX_CALCHAN_ENTRIES];
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 for (i = 0; i < TX_CALCHAN_TABLES; i++) {
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 for (j = 0; j < TX_CALCHAN_ENTRIES; j++) {
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 l1_table[i][j].arfcn_limit =
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 htole16(txcal_band->calchan_ranges[j].upper_bound);
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 l1_table[i][j].chan_cal =
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 htole16(tx_calchan_values[i][j]);
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 do_rftw(TX_CAL_CHAN, l1_table, sizeof l1_table);
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 return(0);
3f63e71b6422 fc-rfcal-txband: implemented initial calchan clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 }