changeset 229:84a4f6ef2d28

pirchgdbg: complete enough for first test
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 19 Dec 2017 04:02:32 +0000
parents fec90990f613
children f5ad21985e20
files pircharge/Makefile pircharge/abb.c pircharge/pktsort.c
diffstat 3 files changed, 118 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pircharge/Makefile	Tue Dec 19 02:58:38 2017 +0000
+++ b/pircharge/Makefile	Tue Dec 19 04:02:32 2017 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2 -I/opt/freecalypso/include
 PROG=	pirchgdbg
-OBJS=	init.o interf.o main.o pktsort.o
+OBJS=	abb.o init.o interf.o main.o pktsort.o
 
 all:	${PROG}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pircharge/abb.c	Tue Dec 19 04:02:32 2017 +0000
@@ -0,0 +1,115 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <rvinterf/pktmux.h>
+#include <rvinterf/limits.h>
+#include <rvinterf/localsock.h>
+#include <rvinterf/localtypes.h>
+#include <rvinterf/etm.h>
+#include <rvinterf/exitcodes.h>
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+extern int adccal_a, adccal_b;
+
+struct abbtab {
+	char	*name;
+	int	regno;
+	int	special;
+} abbtab[] = {
+	{"VBAT",    15,    2},
+	{"ICHG",    17,    1},
+	{"CHGREG",  25,    0},
+	{"BCICTL1", 28,    0},
+	{"BCICTL2", 29,    0},
+	{"BCICONF", 32+13, 0},
+	{0,         0,     0}
+};
+
+int abbr_in_progress, abbr_index;
+
+void
+issue_abbr()
+{
+	u_char cmdpkt[5];
+	int i, c;
+
+	cmdpkt[0] = RVT_TM_HEADER;
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_CODEC_RD;
+	cmdpkt[3] = abbtab[abbr_index].regno;
+	c = 0;
+	for (i = 1; i <= 3; i++)
+		c ^= cmdpkt[i];
+	cmdpkt[i] = c;
+	send_pkt_to_target(cmdpkt, 5);
+}
+
+void
+adc_end_process()
+{
+	if (abbr_in_progress)
+		return;
+	abbr_in_progress = 1;
+	abbr_index = 0;
+	issue_abbr();
+}
+
+void
+etm_packet_rx()
+{
+	int i, c;
+	unsigned val;
+
+	if (rvi_msg_len != 9) {
+		printf("Received TM packet of wrong length\n");
+		return;
+	}
+	c = 0;
+	for (i = 2; i < rvi_msg_len; i++)
+		c ^= rvi_msg[i];
+	if (c) {
+		printf("Received TM packet with bad checksum\n");
+		return;
+	}
+	if (rvi_msg[2] != ETM_CORE) {
+		printf("Received TM packet that isn't ETM_CORE\n");
+		return;
+	}
+	if (rvi_msg[4] != TMCORE_OPC_CODEC_RD) {
+		printf("Received ETM_CORE packet that isn't abbr response\n");
+		return;
+	}
+	if (rvi_msg[3]) {
+		printf("abbr response has error code %02X\n", rvi_msg[3]);
+		return;
+	}
+	if (!abbr_in_progress) {
+		printf("abbr response with no abbr in progress\n");
+		return;
+	}
+	if (rvi_msg[5] != abbtab[abbr_index].regno) {
+		printf("abbr response for the wrong register\n");
+		abbr_in_progress = 0;
+		return;
+	}
+	val = rvi_msg[6] | rvi_msg[7] << 8;
+	printf("%s=%03X", abbtab[abbr_index].name, val);
+	switch (abbtab[abbr_index].special) {
+	case 2:
+		val = (val * adccal_a) >> 10;
+		val += adccal_b;
+		/* FALL THRU */
+	case 1:
+		printf(" (%u)", val);
+	}
+	putchar('\n');
+	abbr_index++;
+	if (abbtab[abbr_index].name)
+		issue_abbr();
+	else
+		abbr_in_progress = 0;
+}
--- a/pircharge/pktsort.c	Tue Dec 19 02:58:38 2017 +0000
+++ b/pircharge/pktsort.c	Tue Dec 19 04:02:32 2017 +0000
@@ -73,7 +73,7 @@
 		return;
 	if (strncmp(rvi_msg + 7, "IQ EXT: ADC End", 15))
 		return;
-	/* ADC End handling will go here */
+	adc_end_process();
 }
 
 void
@@ -84,7 +84,7 @@
 		rvt_packet_rx();
 		return;
 	case RVT_TM_HEADER:
-		/* etm_packet_rx(); */
+		etm_packet_rx();
 		return;
 	default:
 		fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",