FreeCalypso > hg > freecalypso-tools
annotate target-utils/simagent/byterx.c @ 907:3de3b34189be
doc/TCH-bit-access: update for newly resurrected version
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 29 Dec 2022 09:32:31 +0000 |
parents | c136a1a2474b |
children |
rev | line source |
---|---|
771
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <stdlib.h> |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include "types.h" |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include "simregs.h" |
783
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
4 #include "timeout.h" |
771
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 rx_sim_byte(count) |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 unsigned count; |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 { |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 for (; count; count--) { |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 if (!(SIMREGS.stat & SIM_STAT_FEMPTY)) |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 return SIMREGS.drx; |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 } |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 return(-1); |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 } |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
783
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
16 rx_sim_byte_hl() |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
17 { |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
18 int rc; |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
19 unsigned parcnt; |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
20 |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
21 for (parcnt = 0; parcnt < 3; parcnt++) { |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
22 rc = rx_sim_byte(SIM_WAIT_TIMEOUT); |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
23 if (rc < 0) { |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
24 printf("ERROR: timeout waiting for SIM response\n"); |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
25 return(-1); |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
26 } |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
27 if (rc & 0x100) |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
28 return rc & 0xFF; |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
29 } |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
30 printf("ERROR: received bad parity 3 times in a row\n"); |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
31 return(-1); |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
32 } |
c136a1a2474b
simagent: initial implementation of APDU exchange
Mychaela Falconia <falcon@freecalypso.org>
parents:
782
diff
changeset
|
33 |
782
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
34 flush_rx_fifo() |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
35 { |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
36 unsigned count; |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
37 |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
38 for (count = 0; ; ) { |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
39 if (SIMREGS.stat & SIM_STAT_FEMPTY) |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
40 break; |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
41 (void) SIMREGS.drx; |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
42 if (++count >= 32) { |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
43 printf("ERROR: Rx FIFO flush does not end\n"); |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
44 return(-1); |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
45 } |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
46 } |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
47 return(0); |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
48 } |
badc5399d641
simagent: flush_rx_fifo() factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
771
diff
changeset
|
49 |
771
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 void |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 cmd_sertimeout(argbulk) |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 char *argbulk; |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 { |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 char *argv[2]; |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 int count; |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (parse_args(argbulk, 1, 1, argv, 0) < 0) |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 return; |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 count = atoi(argv[0]); |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 rx_sim_byte(count); |
9c1d580b50fb
simagent: Rx byte timeout test implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |