FreeCalypso > hg > fc-sim-sniff
annotate 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 |
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 |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 void |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 rx_byte_in(new_byte) |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (!byte_pending_flag) { |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 byte_pending_flag = 1; |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 byte_pending_val = new_byte; |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return; |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 /* received complete 2-byte message from the FPGA */ |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 fprintf(main_outf, "[%02d:%02d:%02d.%06u] %02X%02X\n", cur_tm->tm_hour, |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 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
|
29 new_byte, byte_pending_val); |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 byte_pending_flag = 0; |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (logfile_flag && (new_byte & 0x80)) |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 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
|
33 } |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 void |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 flush_pending_byte() |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 { |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (!byte_pending_flag) |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 return; |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 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
|
41 byte_pending_flag = 0; |
b112c2df6c43
sw: simtrace3-sniff-rx program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |