view autocal/txbandmain.c @ 90:713749548df6

fc-rfcal-tri900 script and fc-rfcal-tee helper implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 17 Jul 2017 05:51:31 +0000
parents 2bed7b024f64
children 661d122ed8e7
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 "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}
};

struct txcal_band txcal_band_list[] = {
	{"850",  RFPW_STD_BAND_850,  190, 5, 19, tx_calchan_850,  4},
	{"900",  RFPW_STD_BAND_900,   40, 5, 19, tx_calchan_900,  1},
	{"1800", RFPW_STD_BAND_1800, 700, 0, 15, tx_calchan_1800, 4},
	{"1900", RFPW_STD_BAND_1900, 660, 0, 15, tx_calchan_1900, 3},
	{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();

	printf("Saving calibrated values in FFS\n");
	misc_enable(CFG_WRITE_TX_CAL);
	exit(0);
}