shell: flash: use console_getc() instead of getc()

This commit is contained in:
S.J.R. van Schaik 2017-08-01 16:16:16 +02:00
parent e6c1197d07
commit f16cf26197

View file

@ -14,9 +14,7 @@
struct flash_dev *flash = NULL;
/* TODO: implement a parser for hex arrays that is more user-friendly.
* Also implement dry runs for programmers. */
static void parse_hex(FILE *fp, char *buf, size_t len)
static void parse_hex(struct console *con, char *buf, size_t len)
{
size_t i;
char s[3];
@ -24,8 +22,8 @@ static void parse_hex(FILE *fp, char *buf, size_t len)
for (i = 0; i < len; ++i) {
memset(s, '\0', 3);
while ((s[0] = getc(fp)) && !isxdigit(s[0]));
while ((s[1] = getc(fp)) && !isxdigit(s[1]));
while (console_getc(s + 0, con) && !isxdigit(s[0]));
while (console_getc(s + 1, con) && !isxdigit(s[1]));
*buf++ = strtoul(s, NULL, 16);
}
@ -192,7 +190,7 @@ static int do_flash_write(struct console *con, size_t argc, const char **argv)
while (len) {
nbytes = min(len, 256);
parse_hex(con->fp, buf, nbytes);
parse_hex(con, buf, nbytes);
printf("\n");
print_hex_ascii(con->fp, addr, buf, nbytes);