FreeCalypso > hg > freecalypso-sw
annotate target-utils/libload/hexstrings.c @ 386:90af6744d256
make install in target-utils: do mkdir -p before the install command
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 10 Jun 2014 18:48:21 +0000 |
parents | 9b4c5ce3db8b |
children |
rev | line source |
---|---|
40
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * The decode_hex_digits() function contained in this module |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * will be used by the XRAM and flash loading commands |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 * which take SREC-like long hex string arguments. |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 */ |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <ctype.h> |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include "types.h" |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 decode_hex_digits(str, ndigits, valp) |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 char *str; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 int ndigits; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 u32 *valp; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 { |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 u32 accum; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 int i, c; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 accum = 0; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 for (i = 0; i < ndigits; i++) { |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 c = *str++; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 if (!isxdigit(c)) |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 return(-1); |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 accum <<= 4; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 if (isdigit(c)) |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 accum += c - '0'; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 else if (islower(c)) |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 accum += c - 'a' + 10; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 else |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 accum += c - 'A' + 10; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 } |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 *valp = accum; |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 return(0); |
9b4c5ce3db8b
loadagent: ML command (support for fc-chainload) implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 } |