changeset 138:3803f838e1f3

RF table writing code implemented, linked into fc-tmsh
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 26 Feb 2017 22:37:47 +0000
parents 79e71354ba7b
children b5e3899b1265
files rvinterf/tmsh/Makefile rvinterf/tmsh/rftablewr.c
diffstat 2 files changed, 192 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/tmsh/Makefile	Mon Feb 20 02:38:06 2017 +0000
+++ b/rvinterf/tmsh/Makefile	Sun Feb 26 22:37:47 2017 +0000
@@ -3,7 +3,7 @@
 PROG=	fc-tmsh
 OBJS=	abb.o audiocmd.o etmbasic.o ffs2.o ffs2resp.o init.o l1cmd.o l1resp.o \
 	main.o misc.o omr.o oneshot.o pktsort.o rftablechk.o rftablerd.o \
-	tmcore.o usercmd.o
+	rftablewr.o tmcore.o usercmd.o
 LIBS=	../libasync/libasync.a
 INSTBIN=/opt/freecalypso/bin
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/rftablewr.c	Sun Feb 26 22:37:47 2017 +0000
@@ -0,0 +1,191 @@
+/*
+ * Here we implement the writing of RF tables into ASCII text files
+ * in our defined format.  This module will also be linked by the
+ * standalone fc-cal2text utility, hence our code here needs to be
+ * independent of rvinterf and fc-tmsh specifics.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <endian.h>
+
+static unsigned
+get_u32(bin)
+	u_char *bin;
+{
+	return le32toh(*(uint32_t *)bin);
+}
+
+static unsigned
+get_u16(bin)
+	u_char *bin;
+{
+	return le16toh(*(uint16_t *)bin);
+}
+
+static int
+get_s16(bin)
+	u_char *bin;
+{
+	int i;
+
+	i = le16toh(*(uint16_t *)bin);
+	if (i >= 32768)
+		i -= 65536;
+	return(i);
+}
+
+void
+write_afcparams_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	fputs("rf_table afcparams\n\n", outf);
+	/* 32-bit parameters */
+	fprintf(outf, "%10u\t# psi_sta_inv\n", get_u32(bin));
+	fprintf(outf, "%10u\t# psi_st\n", get_u32(bin + 4));
+	fprintf(outf, "%10u\t# psi_st_32\n", get_u32(bin + 8));
+	fprintf(outf, "%10u\t# psi_st_inv\n\n", get_u32(bin + 12));
+	/* 16-bit parameters */
+	fprintf(outf, "%10d\t# dac_center\n", get_s16(bin + 16));
+	fprintf(outf, "%10d\t# dac_min\n", get_s16(bin + 18));
+	fprintf(outf, "%10d\t# dac_max\n", get_s16(bin + 20));
+	fprintf(outf, "%10d\t# snr_thr\n", get_s16(bin + 22));
+}
+
+void
+write_agcwords_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	int i, j;
+	u_char *p = bin;
+
+	fputs("rf_table agc-table\n\n", outf);
+	for (i = 0; i < 4; i++) {
+		for (j = 0; j < 5; j++) {
+			fprintf(outf, " 0x%04X", get_u16(p));
+			p += 2;
+		}
+		putc('\n', outf);
+	}
+}
+
+void
+write_agcglobals_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	fputs("rf_table agc-global-params\n\n", outf);
+	fprintf(outf, "%5u\t# low_agc_noise_thr\n", get_u16(bin));
+	fprintf(outf, "%5u\t# high_agc_sat_thr\n", get_u16(bin + 2));
+	fprintf(outf, "%5u\t# low_agc\n", get_u16(bin + 4));
+	fprintf(outf, "%5u\t# high_agc\n", get_u16(bin + 6));
+}
+
+void
+write_il2agc_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	int idx;
+
+	fputs("rf_table il2agc\n\n", outf);
+	for (idx = 0; idx < 121; idx++)
+		fprintf(outf, "%3u\t# IL=%d\n", get_u16(bin + idx), -idx);
+}
+
+void
+write_tx_levels_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	int i;
+	u_char *p = bin;
+
+	fputs("rf_table tx-levels\n\n", outf);
+	fputs("# Fields in each entry: apc, ramp_index, chan_cal_index\n\n",
+		outf);
+	for (i = 0; i < 32; i++) {
+		fprintf(outf, "%5u %3u %3u\t# entry %d\n",
+			get_u16(p), p[2], p[3], i);
+		p += 4;
+	}
+}
+
+void
+write_tx_calchan_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	int i, j;
+	u_char *p = bin;
+
+	fputs("rf_table tx-calchan\n\n", outf);
+	for (i = 0; i < 4; i++) {
+		fprintf(outf, "# Channel calibration table %d:\n\n", i);
+		for (j = 0; j < 8; j++) {
+			fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2));
+			p += 4;
+		}
+	}
+}
+
+void
+write_tx_caltemp_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	int i;
+	u_char *p = bin;
+
+	fputs("rf_table tx-caltemp\n\n", outf);
+	for (i = 0; i < 5; i++) {
+		fprintf(outf, "%6d %6d %6d %6d\n", get_s16(p), get_s16(p + 2),
+			get_s16(p + 4), get_s16(p + 6));
+		p += 8;
+	}
+}
+
+void
+write_rx_calchan_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	int i;
+	u_char *p = bin;
+
+	fputs("rf_table rx-calchan\n\n", outf);
+	for (i = 0; i < 10; i++) {
+		fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2));
+		p += 4;
+	}
+}
+
+void
+write_rx_caltemp_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	int i;
+	u_char *p = bin;
+
+	fputs("rf_table rx-caltemp\n\n", outf);
+	for (i = 0; i < 11; i++) {
+		fprintf(outf, "%6d %6d\n", get_s16(p), get_s16(p + 2));
+		p += 4;
+	}
+}
+
+void
+write_rx_agcparams_table(bin, outf)
+	u_char *bin;
+	FILE *outf;
+{
+	fputs("rf_table rx-agc-params\n\n", outf);
+	fprintf(outf, "%5u\t# g_magic\n", get_u16(bin));
+	fprintf(outf, "%5u\t# lna_att\n", get_u16(bin + 2));
+	fprintf(outf, "%5u\t# lna_switch_thr_low\n", get_u16(bin + 4));
+	fprintf(outf, "%5u\t# lna_switch_thr_high\n", get_u16(bin + 6));
+}