annotate sw/sniff-rx/byteproc.c @ 58:95ed46b5f8f1 default tip

doc/Sniffing-hw-setup: mv-sniffer is here
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 04 Oct 2023 05:55:09 +0000
parents 43f678895a3a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement byte-level processing of the serial stream
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * coming from the sniffer FPGA.
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/time.h>
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <time.h>
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern FILE *main_outf;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern int logfile_flag;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern struct timeval curtime;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern struct tm *cur_tm;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static int byte_pending_flag, byte_pending_val;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
46
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
18 static void
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
19 annotate(new_byte)
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
20 {
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
21 if (new_byte & 0x80) {
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
22 fprintf(main_outf, " RST %s", new_byte & 0x40 ? "high" : "low");
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
23 return;
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
24 }
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
25 switch (new_byte & 0x18) {
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
26 case 0x08:
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
27 fputs(" PPS1", main_outf);
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
28 return;
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
29 case 0x10:
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
30 fputs(" PPS spenh trigger", main_outf);
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
31 return;
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
32 case 0x18:
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
33 fputs(" Bad PPS catcher bits!", main_outf);
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
34 return;
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
35 }
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
36 }
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
37
22
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 void
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 rx_byte_in(new_byte)
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (!byte_pending_flag) {
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 byte_pending_flag = 1;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 byte_pending_val = new_byte;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 /* received complete 2-byte message from the FPGA */
46
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
47 fprintf(main_outf, "[%02d:%02d:%02d.%06u] %02X%02X", cur_tm->tm_hour,
22
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 cur_tm->tm_min, cur_tm->tm_sec, (unsigned) curtime.tv_usec,
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 new_byte, byte_pending_val);
46
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
50 annotate(new_byte);
43f678895a3a simtrace3-sniff-rx: add some annotations to output
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
51 putc('\n', main_outf);
22
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 byte_pending_flag = 0;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (logfile_flag && (new_byte & 0x80))
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 printf("SIM RST is %s\n", new_byte & 0x40 ? "high" : "low");
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 void
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 flush_pending_byte()
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 {
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (!byte_pending_flag)
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 printf("BAD BAD BAD: loss of byte sync with FPGA source!\n");
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 byte_pending_flag = 0;
b112c2df6c43 sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }