# HG changeset patch
# User Mychaela Falconia <falcon@freecalypso.org>
# Date 1500150331 0
# Node ID 3f63e71b6422be19cf3566cd2a4e57132ebb9729
# Parent  5c3574f8c8c1cba9ab47cff03a53ec8ce06c03e9
fc-rfcal-txband: implemented initial calchan clearing

diff -r 5c3574f8c8c1 -r 3f63e71b6422 autocal/Makefile
--- a/autocal/Makefile	Sat Jul 15 20:08:55 2017 +0000
+++ b/autocal/Makefile	Sat Jul 15 20:25:31 2017 +0000
@@ -11,7 +11,7 @@
 		rxupload.o sockopts.o tsidsock.o
 
 TXBAND_OBJS=	l1tmops.o rvinterf.o sockopts.o tsidsock.o txbandmain.o \
-		txcalconf.o txpwrmeas.o
+		txcalchan.o txcalconf.o txpwrmeas.o
 
 TXBASIS_OBJS=	l1tmops.o rvinterf.o tsidsock.o txpwrmeas.o txstandbas.o
 
diff -r 5c3574f8c8c1 -r 3f63e71b6422 autocal/txbandmain.c
--- a/autocal/txbandmain.c	Sat Jul 15 20:08:55 2017 +0000
+++ b/autocal/txbandmain.c	Sat Jul 15 20:25:31 2017 +0000
@@ -114,5 +114,9 @@
 	do_rfpw(TCH_ARFCN, txcal_band->main_arfcn);
 	do_rfpw(AFC_ENA_FLAG, 0);
 
+	/* any previous calchan needs to be cleared out first */
+	init_tx_calchan();
+	upload_tx_calchan();
+
 
 }
diff -r 5c3574f8c8c1 -r 3f63e71b6422 autocal/txcalchan.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autocal/txcalchan.c	Sat Jul 15 20:25:31 2017 +0000
@@ -0,0 +1,43 @@
+/*
+ * This module contains the code for handling Tx calchan tables.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <endian.h>
+#include <rvinterf/l1tm.h>
+#include <rvinterf/exitcodes.h>
+#include "txband.h"
+#include "txcalchan.h"
+
+extern struct txcal_band *txcal_band;
+
+unsigned tx_calchan_values[TX_CALCHAN_TABLES][TX_CALCHAN_ENTRIES];
+
+init_tx_calchan()
+{
+	unsigned i, j;
+
+	for (i = 0; i < TX_CALCHAN_TABLES; i++)
+		for (j = 0; j < TX_CALCHAN_ENTRIES; j++)
+			tx_calchan_values[i][j] = 128;
+	return(0);
+}
+
+upload_tx_calchan()
+{
+	unsigned i, j;
+	struct tx_calchan_entry l1_table[TX_CALCHAN_TABLES][TX_CALCHAN_ENTRIES];
+
+	for (i = 0; i < TX_CALCHAN_TABLES; i++) {
+		for (j = 0; j < TX_CALCHAN_ENTRIES; j++) {
+			l1_table[i][j].arfcn_limit =
+			    htole16(txcal_band->calchan_ranges[j].upper_bound);
+			l1_table[i][j].chan_cal =
+				htole16(tx_calchan_values[i][j]);
+		}
+	}
+	do_rftw(TX_CAL_CHAN, l1_table, sizeof l1_table);
+	return(0);
+}