diff sw/sniff-rx/byteproc.c @ 22:b112c2df6c43

sw: simtrace3-sniff-rx program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 22 Aug 2023 06:16:44 +0000
parents
children 43f678895a3a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sw/sniff-rx/byteproc.c	Tue Aug 22 06:16:44 2023 +0000
@@ -0,0 +1,42 @@
+/*
+ * In this module we implement byte-level processing of the serial stream
+ * coming from the sniffer FPGA.
+ */
+
+#include <sys/time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+extern FILE *main_outf;
+extern int logfile_flag;
+extern struct timeval curtime;
+extern struct tm *cur_tm;
+
+static int byte_pending_flag, byte_pending_val;
+
+void
+rx_byte_in(new_byte)
+{
+	if (!byte_pending_flag) {
+		byte_pending_flag = 1;
+		byte_pending_val = new_byte;
+		return;
+	}
+	/* received complete 2-byte message from the FPGA */
+	fprintf(main_outf, "[%02d:%02d:%02d.%06u] %02X%02X\n", cur_tm->tm_hour,
+		cur_tm->tm_min, cur_tm->tm_sec, (unsigned) curtime.tv_usec,
+		new_byte, byte_pending_val);
+	byte_pending_flag = 0;
+	if (logfile_flag && (new_byte & 0x80))
+		printf("SIM RST is %s\n", new_byte & 0x40 ? "high" : "low");
+}
+
+void
+flush_pending_byte()
+{
+	if (!byte_pending_flag)
+		return;
+	printf("BAD BAD BAD: loss of byte sync with FPGA source!\n");
+	byte_pending_flag = 0;
+}