FreeCalypso > hg > freecalypso-tools
annotate loadtools/simup.c @ 790:0bbe0213812d
fc-simint put together, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 19 Mar 2021 04:40:05 +0000 |
parents | |
children | 44e034f21916 |
rev | line source |
---|---|
790
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the stage in fc-simint where the sim-up |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * command is fed to simagent and the ATR response is parsed. |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern int sim_voltage_mode_1v8; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #define MAX_ATR_BYTES 33 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_char sim_atr[MAX_ATR_BYTES]; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 unsigned sim_atr_len; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 static |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 sim_up_callback(line) |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char *line; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 char *cp; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 puts(line); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (strncmp(line, "ATR:", 4)) |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 sim_atr_len = 0; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 for (cp = line + 4; *cp; cp += 3) { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (cp[0] != ' ' || !isxdigit(cp[1]) || !isxdigit(cp[2])) { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 fprintf(stderr, |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 "error: invalid ATR line from simagent\n"); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (sim_atr_len >= MAX_ATR_BYTES) { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 fprintf(stderr, |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 "error: ATR from simagent is too long\n"); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 return(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 sim_atr[sim_atr_len++] = decode_hex_byte(cp + 1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return(0); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 void |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 do_sim_up() |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 char *targv[3]; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 targv[0] = "sim-up"; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (sim_voltage_mode_1v8) |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 targv[1] = "1.8"; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 else |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 targv[2] = "3"; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 targv[2] = 0; |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 tpinterf_make_cmd(targv); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (tpinterf_send_cmd() < 0) |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 exit(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (tpinterf_capture_output(20, sim_up_callback)) |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 exit(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (!sim_atr_len) { |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 fprintf(stderr, "error: no ATR returned from simagent\n"); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 exit(1); |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
0bbe0213812d
fc-simint put together, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |