comparison autocal/txlevels.c @ 101:b0618796d28d

fc-rfcal-txband: added safety checks for NaN power measurements and out-of-tolerance final Tx power levels
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 11 Aug 2017 03:20:43 +0000
parents a2d4cab0a592
children 80281b67511f
comparison
equal deleted inserted replaced
100:7ad5836d3b87 101:b0618796d28d
1 /* 1 /*
2 * The calibration of Tx power levels is implemented here. 2 * The calibration of Tx power levels is implemented here.
3 */ 3 */
4 4
5 #include <math.h>
5 #include <stdio.h> 6 #include <stdio.h>
6 #include <stdlib.h> 7 #include <stdlib.h>
7 #include <rvinterf/l1tm.h> 8 #include <rvinterf/l1tm.h>
8 #include <rvinterf/exitcodes.h> 9 #include <rvinterf/exitcodes.h>
9 #include "txband.h" 10 #include "txband.h"
36 } 37 }
37 38
38 calibrate_tx_levels() 39 calibrate_tx_levels()
39 { 40 {
40 unsigned plnum, plidx, apc; 41 unsigned plnum, plidx, apc;
41 double target, meas; 42 double target, meas, error;
43 int nanflag = 0, errflag = 0;
42 44
43 printf("Calibrating Tx power levels\n"); 45 printf("Calibrating Tx power levels\n");
44 printf("Starting RF Tx on the DUT\n"); 46 printf("Starting RF Tx on the DUT\n");
45 do_rfe(RX_TX_TCH); 47 do_rfe(RX_TX_TCH);
46 48
52 apc = find_apc_for_target(target, &tx_levels[plidx].slope); 54 apc = find_apc_for_target(target, &tx_levels[plidx].slope);
53 tx_levels[plidx].apc = apc; 55 tx_levels[plidx].apc = apc;
54 do_txpw(TX_APC_DAC, apc); 56 do_txpw(TX_APC_DAC, apc);
55 usleep(20000); 57 usleep(20000);
56 meas = tx_power_meas(); 58 meas = tx_power_meas();
59 if (isnan(meas))
60 nanflag = 1;
61 error = meas - target;
62 if (error < -2.0 || error > 2.0)
63 errflag = 1;
57 printf( 64 printf(
58 "Tx power level #%u: target %.1f dBm, APC=%u, meas %.2f dBm (%+.2f)\n", 65 "Tx power level #%u: target %.1f dBm, APC=%u, meas %.2f dBm (%+.2f)\n",
59 plnum, target, apc, meas, meas - target); 66 plnum, target, apc, meas, error);
60 } 67 }
61 68
62 printf("Stopping RF Tx on the DUT\n"); 69 printf("Stopping RF Tx on the DUT\n");
63 do_rfe(STOP_ALL); 70 do_rfe(STOP_ALL);
71 if (nanflag) {
72 printf("Error: got NaN power measurement, aborting\n");
73 exit(ERROR_TARGET);
74 }
75 if (errflag) {
76 printf("Error: Tx power off by more than 2 dBm, aborting\n");
77 exit(ERROR_TARGET);
78 }
64 return(0); 79 return(0);
65 } 80 }