FreeCalypso > hg > fc-rfcal-tools
annotate autocal/txlevels.c @ 98:615df2fb1ec3
doc/Tx-cal-theory: update with both theory and practice
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 17 Jul 2017 22:49:35 +0000 |
parents | a2d4cab0a592 |
children | b0618796d28d |
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 |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <rvinterf/l1tm.h> |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <rvinterf/exitcodes.h> |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "txband.h" |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern double tx_power_meas(); |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern vout_t dbm_to_vout(); |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern struct txcal_band *txcal_band; |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 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
|
16 extern unsigned num_basis_points; |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 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
|
18 |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 unsigned |
83
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
20 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
|
21 double target_dbm; |
83
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
22 vout_t *pslope; |
82
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 vout_t target_vout; |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 unsigned n; |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 int apc_delta; |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 break; |
83
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
32 if (pslope) |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
33 *pslope = tx_basis[n].slope; |
82
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 apc_delta = (target_vout - tx_basis[n].vout) / tx_basis[n].slope; |
a094db1453b1
fc-rfcal-txband: implemented computation of APC from basis
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 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
|
36 } |
83
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
37 |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
38 calibrate_tx_levels() |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
39 { |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
40 unsigned plnum, plidx, apc; |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
41 double target, meas; |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
42 |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
43 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
|
44 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
|
45 do_rfe(RX_TX_TCH); |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
46 |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
47 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
|
48 plnum++) { |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
49 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
|
50 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
|
51 target = tx_levels[plidx].target; |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
52 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
|
53 tx_levels[plidx].apc = apc; |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
54 do_txpw(TX_APC_DAC, apc); |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
55 usleep(20000); |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
56 meas = tx_power_meas(); |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
57 printf( |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
58 "Tx power level #%u: target %.1f dBm, APC=%u, meas %.2f dBm (%+.2f)\n", |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
59 plnum, target, apc, meas, meas - target); |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
60 } |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
61 |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
62 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
|
63 do_rfe(STOP_ALL); |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
64 return(0); |
45ef4a06edfc
fc-rfcal-txband: initial implementation complete, ready to test
Mychaela Falconia <falcon@freecalypso.org>
parents:
82
diff
changeset
|
65 } |