FreeCalypso > hg > freecalypso-tools
annotate loadtools/ltmisc.c @ 645:880c6d31e487
loadagent sertimeout calibration command simplified
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 01 Mar 2020 23:56:35 +0000 |
parents | 5385aca4d813 |
children | 0d199c6a6ea4 |
rev | line source |
---|---|
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module is a place to implement little miscellaneous fc-loadtool |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * commands which don't belong anywhere else. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
640
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
9 #include <stdlib.h> |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
10 |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
11 cmd_crc32(argc, argv) |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
12 char **argv; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
13 { |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
14 u_long area_base, area_len; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
15 char *strtoul_endp; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
16 u_long crc_result; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
17 int stat; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
18 |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
19 area_base = strtoul(argv[1], &strtoul_endp, 16); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
20 if (*strtoul_endp) { |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
21 inv: fprintf(stderr, "usage: crc32 hex-start hex-len\n"); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
22 return(-1); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
23 } |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
24 area_len = strtoul(argv[2], &strtoul_endp, 16); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
25 if (*strtoul_endp) |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
26 goto inv; |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
27 stat = crc32_on_target(area_base, area_len, &crc_result); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
28 if (stat == 0) |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
29 printf("%08lX\n", crc_result); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
30 return(stat); |
5385aca4d813
fc-loadtool module refactoring: CRC-32 functions split out
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
31 } |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 cmd_dieid(argc, argv) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 char **argv; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 static uint32_t addrs[4] = {0xFFFEF010, 0xFFFEF012, 0xFFFEF014, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 0xFFFEF016}; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 uint16_t data[4]; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 int i, stat; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 FILE *of; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 for (i = 0; i < 4; i++) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 stat = do_r16(addrs[i], data + i); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (stat) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(stat); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 printf("%08lX: %04X\n", (u_long)addrs[i], (int)data[i]); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (argc < 2) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 of = fopen(argv[1], "w"); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (!of) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 perror(argv[1]); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 return(-1); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 for (i = 0; i < 4; i++) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 fprintf(of, "%08lX: %04X\n", (u_long)addrs[i], (int)data[i]); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 fclose(of); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 printf("Saved to %s\n", argv[1]); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 return(0); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |