comparison target-utils/libload/hexstrings.c @ 40:9b4c5ce3db8b

loadagent: ML command (support for fc-chainload) implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 13 May 2013 22:59:08 +0000
parents
children
comparison
equal deleted inserted replaced
39:d67bfcb9e351 40:9b4c5ce3db8b
1 /*
2 * The decode_hex_digits() function contained in this module
3 * will be used by the XRAM and flash loading commands
4 * which take SREC-like long hex string arguments.
5 */
6
7 #include <ctype.h>
8 #include "types.h"
9
10 decode_hex_digits(str, ndigits, valp)
11 char *str;
12 int ndigits;
13 u32 *valp;
14 {
15 u32 accum;
16 int i, c;
17
18 accum = 0;
19 for (i = 0; i < ndigits; i++) {
20 c = *str++;
21 if (!isxdigit(c))
22 return(-1);
23 accum <<= 4;
24 if (isdigit(c))
25 accum += c - '0';
26 else if (islower(c))
27 accum += c - 'a' + 10;
28 else
29 accum += c - 'A' + 10;
30 }
31 *valp = accum;
32 return(0);
33 }