annotate autocal/txlevels.c @ 131:8e26cb57c7f8

doc/Test-system-interface: additions for Tx ramp testing
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 20 Dec 2021 03:29:23 +0000
parents 9f09a7c3607a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The calibration of Tx power levels is implemented here.
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
5 #include <math.h>
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <rvinterf/l1tm.h>
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <rvinterf/exitcodes.h>
117
4c3f4231a021 autocal: vout_t definition factored out of txband.h into txvout.h
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
10 #include "txvout.h"
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "txband.h"
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern double tx_power_meas();
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern vout_t dbm_to_vout();
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern struct txcal_band *txcal_band;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern struct tx_basis_point tx_basis[MAX_BASIS_POINTS];
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern unsigned num_basis_points;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern struct tx_level tx_levels[MAX_TX_LEVELS];
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 unsigned
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
22 find_apc_for_target(target_dbm, pslope)
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 double target_dbm;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
24 vout_t *pslope;
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
102
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
26 vout_t target_vout, slope;
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 unsigned n;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 int apc_delta;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 target_vout = dbm_to_vout(target_dbm);
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 for (n = 0; n < num_basis_points - 1; n++)
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (target_vout < tx_basis[n+1].vout)
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 break;
102
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
34 if (n == num_basis_points - 1)
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
35 slope = tx_basis[n-1].slope;
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
36 else
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
37 slope = tx_basis[n].slope;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
38 if (pslope)
102
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
39 *pslope = slope;
80281b67511f fc-rfcal-txband: fixed bug in the corner case when
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
40 apc_delta = (target_vout - tx_basis[n].vout) / slope;
82
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return tx_basis[n].apc + apc_delta;
a094db1453b1 fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
43
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
44 calibrate_tx_levels()
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
45 {
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
46 unsigned plnum, plidx, apc;
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
47 double target, meas, error;
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
48 int nanflag = 0, errflag = 0;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
49
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
50 printf("Calibrating Tx power levels\n");
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
51 printf("Starting RF Tx on the DUT\n");
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
52 do_rfe(RX_TX_TCH);
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
53
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
54 for (plnum = txcal_band->start_plnum; plnum <= txcal_band->end_plnum;
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
55 plnum++) {
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
56 do_txpw(TX_PWR_LEVEL, plnum);
84
a2d4cab0a592 fc-rfcal-txband: works after a couple of bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 83
diff changeset
57 plidx = plnum - txcal_band->start_plnum;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
58 target = tx_levels[plidx].target;
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
59 apc = find_apc_for_target(target, &tx_levels[plidx].slope);
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
60 tx_levels[plidx].apc = apc;
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
61 do_txpw(TX_APC_DAC, apc);
115
1e49bb52b07e fc-rfcal-txband: set calchan indices in the levels table
Mychaela Falconia <falcon@freecalypso.org>
parents: 104
diff changeset
62 do_txpw(TX_CHAN_CAL_TABLE,
1e49bb52b07e fc-rfcal-txband: set calchan indices in the levels table
Mychaela Falconia <falcon@freecalypso.org>
parents: 104
diff changeset
63 txcal_band->calchan_selections[plidx]);
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
64 usleep(20000);
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
65 meas = tx_power_meas();
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
66 if (isnan(meas))
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
67 nanflag = 1;
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
68 error = meas - target;
124
9f09a7c3607a fc-rfcal-txband: level error tolerance tightened to 0.75 dB
Mychaela Falconia <falcon@freecalypso.org>
parents: 117
diff changeset
69 if (error < -0.75 || error > 0.75)
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
70 errflag = 1;
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
71 printf(
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
72 "Tx power level #%u: target %.1f dBm, APC=%u, meas %.2f dBm (%+.2f)\n",
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
73 plnum, target, apc, meas, error);
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
74 }
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
75
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
76 printf("Stopping RF Tx on the DUT\n");
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
77 do_rfe(STOP_ALL);
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
78 if (nanflag) {
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
79 printf("Error: got NaN power measurement, aborting\n");
104
7ad0495991ed autocal: use the new ERROR_RFFAIL exit code
Mychaela Falconia <falcon@freecalypso.org>
parents: 102
diff changeset
80 exit(ERROR_RFFAIL);
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
81 }
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
82 if (errflag) {
124
9f09a7c3607a fc-rfcal-txband: level error tolerance tightened to 0.75 dB
Mychaela Falconia <falcon@freecalypso.org>
parents: 117
diff changeset
83 printf("Error: Tx power off by more than 0.75 dB, aborting\n");
104
7ad0495991ed autocal: use the new ERROR_RFFAIL exit code
Mychaela Falconia <falcon@freecalypso.org>
parents: 102
diff changeset
84 exit(ERROR_RFFAIL);
101
b0618796d28d fc-rfcal-txband: added safety checks for NaN power measurements and
Mychaela Falconia <falcon@freecalypso.org>
parents: 84
diff changeset
85 }
83
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
86 return(0);
45ef4a06edfc fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents: 82
diff changeset
87 }