comparison loadtools/tpinterf3.c @ 62:6fb41cfa773d

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