comparison 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
comparison
equal deleted inserted replaced
21:c4346cdc9641 22:b112c2df6c43
1 /*
2 * In this module we implement byte-level processing of the serial stream
3 * coming from the sniffer FPGA.
4 */
5
6 #include <sys/time.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <time.h>
10
11 extern FILE *main_outf;
12 extern int logfile_flag;
13 extern struct timeval curtime;
14 extern struct tm *cur_tm;
15
16 static int byte_pending_flag, byte_pending_val;
17
18 void
19 rx_byte_in(new_byte)
20 {
21 if (!byte_pending_flag) {
22 byte_pending_flag = 1;
23 byte_pending_val = new_byte;
24 return;
25 }
26 /* received complete 2-byte message from the FPGA */
27 fprintf(main_outf, "[%02d:%02d:%02d.%06u] %02X%02X\n", cur_tm->tm_hour,
28 cur_tm->tm_min, cur_tm->tm_sec, (unsigned) curtime.tv_usec,
29 new_byte, byte_pending_val);
30 byte_pending_flag = 0;
31 if (logfile_flag && (new_byte & 0x80))
32 printf("SIM RST is %s\n", new_byte & 0x40 ? "high" : "low");
33 }
34
35 void
36 flush_pending_byte()
37 {
38 if (!byte_pending_flag)
39 return;
40 printf("BAD BAD BAD: loss of byte sync with FPGA source!\n");
41 byte_pending_flag = 0;
42 }