FreeCalypso > hg > freecalypso-sw
annotate loadtools/tpinterf3.c @ 64:a481d648278a
fc-loadtool: "quick program" command implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 28 Jun 2013 04:49:09 +0000 |
parents | 6fb41cfa773d |
children |
rev | line source |
---|---|
62
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * The do_r16() and do_w16() functions implemented in this module |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * provide programmatic access to the r16 and w16 commands on the target. |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 * They will be used to implement some flash operations. |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 */ |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <sys/types.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdio.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdint.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <string.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <strings.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <stdlib.h> |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 extern char target_response_line[]; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 do_r16(addr, retptr) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 uint32_t addr; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 uint16_t *retptr; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 char addr_arg[10], *argv[3]; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 int stat; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 char *strtoul_endp; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 sprintf(addr_arg, "%lx", (u_long) addr); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 argv[0] = "r16"; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 argv[1] = addr_arg; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 argv[2] = 0; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 tpinterf_make_cmd(argv); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 if (tpinterf_send_cmd() < 0) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 stat = tpinterf_capture_output_oneline(1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 if (stat != 1) { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 errout: fprintf(stderr, "error: malformed response to r16 command\n"); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 if (strlen(target_response_line) != 4) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 goto errout; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 *retptr = strtoul(target_response_line, &strtoul_endp, 16); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 if (strtoul_endp != target_response_line + 4) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 goto errout; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 return(0); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 } |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 do_w16(addr, data) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 uint32_t addr; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 uint16_t data; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 { |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 char addr_arg[10], data_arg[10], *argv[4]; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 sprintf(addr_arg, "%lx", (u_long) addr); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 sprintf(data_arg, "%lx", (u_long) data); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 argv[0] = "w16"; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 argv[1] = addr_arg; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 argv[2] = data_arg; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 argv[3] = 0; |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 tpinterf_make_cmd(argv); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 if (tpinterf_send_cmd() < 0) |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 return(-1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 return tpinterf_pass_output(1); |
6fb41cfa773d
fc-loadtool: flash erase implemented, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 } |