view autocal/rxcommon.c @ 59:c87067884da7

autocal/l1tmops.c: do_rftr() added
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 27 May 2017 23:23:35 +0000
parents 1a0dbc746d57
children
line wrap: on
line source

/*
 * This module contains the common code for
 * fc-rfcal-gmagic and fc-rfcal-rxband.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <rvinterf/l1tm.h>
#include <rvinterf/exitcodes.h>
#include "l1stats.h"
#include "rxcaldefs.h"

l1tm_setup_for_rxcal()
{
	do_rxpw(RX_AGC_ENA_FLAG, 0);
	do_rxpw(RX_AGC_GAIN, RXCAL_AGC_DB);
	do_rfpw(AFC_ENA_FLAG, 0);
	do_scw(LOOPS, RXCAL_LOOP_COUNT);
	do_scw(AUTO_RESULT_LOOPS, RXCAL_LOOP_COUNT);
	do_scw(AUTO_RESET_LOOPS, RXCAL_LOOP_COUNT);
	do_scw(STAT_TYPE, ACCUMULATED_RX_STATS);
	do_scw(STAT_BITMASK, DSP_PM);
	return(0);
}

halfdb_to_string(halfdb, strbuf)
	int halfdb;
	char *strbuf;
{
	int sign;

	if (halfdb < 0) {
		sign = 1;
		halfdb = -halfdb;
	} else
		sign = 0;
	sprintf(strbuf, "%s%d.%c", sign ? "-" : "", halfdb >> 1,
		halfdb & 1 ? '5' : '0');
	return(0);
}

static unsigned
rx_single_offset_meas(arfcn, offset)
	unsigned arfcn;
	char *offset;
{
	char dbm[64], tsid_cmd[128];
	struct l1stats l1st;
	unsigned pm;

	halfdb_to_string(RXCAL_SIGGEN_LEVEL, dbm);
	printf("Rx meas at ARFCN %u offset %s kHz, TL=%s dBm, AGC=%d dB\n",
		arfcn, offset, dbm, RXCAL_AGC_DB);
	sprintf(tsid_cmd, "signal-gen-sine %u %s %s\n", arfcn, offset, dbm);
	tsid_command(tsid_cmd);
	usleep(20000);
	do_rfe(RX_TCH);
	collect_auto_stats(&l1st);
	collect_rfe_completion();
	if (!(l1st.bitmask & DSP_PM)) {
		fprintf(stderr, "DUT error: no DSP_PM in auto-stats msg\n");
		exit(ERROR_TARGET);
	}
	pm = l1st.dsp_pm;
	printf("DSP_PM=0x%04X, %u half-dBm\n", pm, (pm + 16) >> 5);
	return(pm);
}

unsigned
rx_measure(arfcn)
	unsigned arfcn;
{
	unsigned pm1, pm2;

	do_rfpw(TCH_ARFCN, arfcn);
	pm1 = rx_single_offset_meas(arfcn, "+67");
	pm2 = rx_single_offset_meas(arfcn, "-67");
	return (pm1 + pm2 + 32) >> 6;
}