FreeCalypso > hg > freecalypso-sw
annotate target-utils/libload/hexstrings.c @ 823:d93ecff8544b
aci: psa_mms.c imported from TCS211 version
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 05 Apr 2015 20:45:18 +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 } |