comparison 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
comparison
equal deleted inserted replaced
775:6ec781e61e68 776:fac3176de18d
1 /*
2 * This module implements transmission of bytes toward the SIM.
3 */
4
5 #include "types.h"
6 #include "simregs.h"
7
8 extern u16 conf1_reg;
9
10 send_to_sim(bytes, count)
11 u8 *bytes;
12 unsigned count;
13 {
14 unsigned n, timeout;
15
16 SIMREGS.conf1 = conf1_reg |= SIM_CONF1_TXRX;
17 if (count == 1)
18 wait_ARM_cycles(372 * 4); /* wait 1 etu */
19 for (n = 0; ; ) {
20 SIMREGS.dtx = bytes[n++];
21 if (n == count) {
22 SIMREGS.conf1 = conf1_reg &= ~SIM_CONF1_TXRX;
23 return(0);
24 }
25 for (timeout = 12000; timeout; timeout--)
26 if (SIMREGS.it & SIM_IT_ITTX)
27 break;
28 if (!timeout) {
29 printf("ERROR: SIM interface Tx timeout\n");
30 return(-1);
31 }
32 }
33 }
34
35 cmd_tx(argstr)
36 char *argstr;
37 {
38 u8 bytes[5];
39 int rc;
40
41 rc = decode_hex_string_arg(argstr, bytes, sizeof bytes);
42 if (rc < 0)
43 return;
44 if (rc == 0) {
45 printf("ERROR: empty hex string argument\n");
46 return;
47 }
48 send_to_sim(bytes, rc);
49 }