view autocal/txbandmain.c @ 117:4c3f4231a021

autocal: vout_t definition factored out of txband.h into txvout.h
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 13 Feb 2018 07:02:17 +0000
parents 4ce87a30383f
children
line wrap: on
line source

/*
 * This module contains the main() function for fc-rfcal-txband.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <rvinterf/l1tm.h>
#include <rvinterf/exitcodes.h>
#include "txvout.h"
#include "txband.h"
#include "stdband.h"

struct tx_calchan_range tx_calchan_850[] = {
	{128, 134, 131},
	{135, 150, 143},
	{151, 166, 159},
	{167, 182, 175},
	{183, 197, 190},
	{198, 213, 206},
	{214, 229, 222},
	{230, 251, 241}
};

struct tx_calchan_range tx_calchan_900[] = {
	{  0,   27,   14},
	{ 28,   47,   40},
	{ 48,   66,   57},
	{ 67,   85,   76},
	{ 86,  104,   95},
	{105,  124,  114},
	{975,  994,  985},
	{995, 1023, 1009}
};

struct tx_calchan_range tx_calchan_1800[] = {
	{512, 553, 533},
	{554, 594, 574},
	{595, 636, 615},
	{637, 677, 657},
	{678, 720, 700},
	{721, 760, 740},
	{761, 802, 781},
	{803, 885, 844}
};

struct tx_calchan_range tx_calchan_1900[] = {
	{512, 549, 531},
	{550, 586, 568},
	{587, 623, 605},
	{624, 697, 660},
	{698, 726, 712},
	{727, 754, 740},
	{755, 782, 768},
	{783, 810, 796}
};

unsigned tx_calchan_low_selections[] = {0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3};

unsigned tx_calchan_low_plnum[] = {5, 8, 12, 16};

unsigned tx_calchan_high_selections[] = {0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3};

unsigned tx_calchan_high_plnum[] = {0, 4, 8, 12};

struct txcal_band txcal_band_list[] = {
	{"850",  RFPW_STD_BAND_850,  190, 5, 19, tx_calchan_850,  4,
		tx_calchan_low_selections, tx_calchan_low_plnum},
	{"900",  RFPW_STD_BAND_900,   40, 5, 19, tx_calchan_900,  1,
		tx_calchan_low_selections, tx_calchan_low_plnum},
	{"1800", RFPW_STD_BAND_1800, 700, 0, 15, tx_calchan_1800, 4,
		tx_calchan_high_selections, tx_calchan_high_plnum},
	{"1900", RFPW_STD_BAND_1900, 660, 0, 15, tx_calchan_1900, 3,
		tx_calchan_high_selections, tx_calchan_high_plnum},
	{0,	 0,		     0,   0, 0,  0,               0, 0, 0}
};

struct txcal_band *txcal_band;
char *txlevels_profile;

struct tx_basis_point tx_basis[MAX_BASIS_POINTS];
unsigned num_basis_points;

struct tx_level tx_levels[MAX_TX_LEVELS];

finish_cmdline(argc, argv)
	char **argv;
{
	extern int optind;
	struct txcal_band *band;

	if (argc - optind != 2) {
		fprintf(stderr, "usage: %s band txlevels-profile\n", argv[0]);
		exit(ERROR_USAGE);
	}
	for (band = txcal_band_list; band->name; band++)
		if (!strcmp(band->name, argv[optind]))
			break;
	if (!band->name) {
		fprintf(stderr, "error: \"%s\" is not a known band\n",
			argv[optind]);
		exit(ERROR_USAGE);
	}
	txcal_band = band;
	txlevels_profile = argv[optind+1];
	return(0);
}

main(argc, argv)
	char **argv;
{
	socket_pathname_options(argc, argv);
	finish_cmdline(argc, argv);
	read_tx_cal_profile();
	connect_rvinterf_socket();
	connect_tsid_socket();
	setlinebuf(stdout);	/* to allow logging with tee */
	printf("Preparing RF test system for %s MHz Tx calibration\n",
		txcal_band->name);
	do_txpwr_cal_setup(txcal_band->name, txcal_band->main_arfcn);

	printf("Putting the DUT into Test Mode\n");
	do_tms(1);
	do_rfpw(STD_BAND_FLAG, txcal_band->rfpw_std_band);
	do_rfpw(TCH_ARFCN, txcal_band->main_arfcn);
	do_rfpw(AFC_ENA_FLAG, 0);

	/* any previous calchan needs to be cleared out first */
	printf("Initializing calchan table\n");
	init_tx_calchan();
	upload_tx_calchan();
	/* run the basis measurements */
	txcal_basis_run();
	/* analytical follow-up */
	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);
	exit(0);
}