annotate target-utils/simagent/tx.c @ 776:fac3176de18d

simagent: bare Tx implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Mar 2021 23:36:46 +0000
parents
children 3ba64341137b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
776
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements transmission of bytes toward the SIM.
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include "types.h"
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include "simregs.h"
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 extern u16 conf1_reg;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 send_to_sim(bytes, count)
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 u8 *bytes;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 unsigned count;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 unsigned n, timeout;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_TXRX;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 if (count == 1)
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 wait_ARM_cycles(372 * 4); /* wait 1 etu */
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 for (n = 0; ; ) {
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 SIMREGS.dtx = bytes[n++];
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (n == count) {
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 SIMREGS.conf1 = conf1_reg &= ~SIM_CONF1_TXRX;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(0);
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 for (timeout = 12000; timeout; timeout--)
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (SIMREGS.it & SIM_IT_ITTX)
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 break;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (!timeout) {
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 printf("ERROR: SIM interface Tx timeout\n");
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(-1);
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 cmd_tx(argstr)
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 char *argstr;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 u8 bytes[5];
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 int rc;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 rc = decode_hex_string_arg(argstr, bytes, sizeof bytes);
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (rc < 0)
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (rc == 0) {
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 printf("ERROR: empty hex string argument\n");
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return;
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 send_to_sim(bytes, rc);
fac3176de18d simagent: bare Tx implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }