usart: use \n instead of \r\n
This commit is contained in:
parent
c28ddec92b
commit
b0dd5a9abc
3 changed files with 28 additions and 21 deletions
|
@ -75,7 +75,7 @@ static void print_hex_ascii(FILE *fp, const char *buf, size_t len)
|
|||
fprintf(fp, "%c", isalnum(c) ? c : '.');
|
||||
}
|
||||
|
||||
fprintf(fp, "\r\n");
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ static char *prompt(FILE *fp, const char *prefix)
|
|||
|
||||
s = line;
|
||||
|
||||
while ((c = fgetc(fp)) && c != '\r') {
|
||||
while ((c = fgetc(fp)) && c != '\n') {
|
||||
fputc(c, fp);
|
||||
|
||||
if (nbytes + 1 >= nalloc_bytes) {
|
||||
|
@ -108,7 +108,7 @@ static char *prompt(FILE *fp, const char *prefix)
|
|||
nbytes++;
|
||||
}
|
||||
|
||||
fprintf(fp, "\r\n");
|
||||
fprintf(fp, "\n");
|
||||
*s = '\0';
|
||||
|
||||
return line;
|
||||
|
@ -126,7 +126,7 @@ static void do_probe(FILE *fp, const char *s)
|
|||
(void)s;
|
||||
|
||||
spi_send_cmd(SPI1, cmd, 1, buf, 6);
|
||||
fprintf(fp, "JEDEC ID: %02x%02x%02x\r\n", buf[0], buf[1], buf[2]);
|
||||
fprintf(fp, "JEDEC ID: %02x%02x%02x\n", buf[0], buf[1], buf[2]);
|
||||
}
|
||||
|
||||
static void do_read(FILE *fp, const char *s)
|
||||
|
@ -143,7 +143,7 @@ static void do_read(FILE *fp, const char *s)
|
|||
if (errno == EINVAL || errno == ERANGE)
|
||||
return;
|
||||
|
||||
s += strspn(s, " \r\n");
|
||||
s += strspn(s, " \n");
|
||||
|
||||
if (strncmp(s, "0x", 2) == 0)
|
||||
s += 2;
|
||||
|
@ -181,7 +181,7 @@ static void do_write(FILE *fp, const char *s)
|
|||
if (errno == EINVAL || errno == ERANGE)
|
||||
return;
|
||||
|
||||
s += strspn(s, " \r\n");
|
||||
s += strspn(s, " \n");
|
||||
|
||||
if (strncmp(s, "0x", 2) == 0)
|
||||
s += 2;
|
||||
|
@ -198,7 +198,7 @@ static void do_write(FILE *fp, const char *s)
|
|||
while (len) {
|
||||
nbytes = (len > 256) ? 256 : len;
|
||||
parse_hex(fp, buf, nbytes);
|
||||
fprintf(fp, "\r\n");
|
||||
fprintf(fp, "\n");
|
||||
print_hex_ascii(fp, buf, nbytes);
|
||||
spi_flash_write(SPI1, addr, buf, nbytes);
|
||||
|
||||
|
@ -223,7 +223,7 @@ static void do_erase(FILE *fp, const char *s)
|
|||
if (errno == EINVAL || errno == ERANGE)
|
||||
return;
|
||||
|
||||
s += strspn(s, " \r\n");
|
||||
s += strspn(s, " \n");
|
||||
|
||||
if (strncmp(s, "0x", 2) == 0)
|
||||
s += 2;
|
||||
|
@ -247,11 +247,11 @@ static void parse_cmd(FILE *fp, const char *s)
|
|||
char *key;
|
||||
size_t n;
|
||||
|
||||
n = strcspn(s, " \r\n");
|
||||
n = strcspn(s, " \n");
|
||||
key = strndup(s, n);
|
||||
|
||||
args = s + n;
|
||||
args += strspn(args, " \r\n");
|
||||
args += strspn(args, " \n");
|
||||
|
||||
for (cmd = cmds; cmd->key; cmd++) {
|
||||
if (strcmp(cmd->key, key) == 0)
|
||||
|
|
|
@ -144,7 +144,7 @@ void spi_flash_erase(FILE *fp, uint32_t dev, uint32_t addr, size_t len)
|
|||
default: goto err_disable_write;
|
||||
};
|
||||
|
||||
fprintf(fp, "addr: %lx; size: %u\r\n", addr, size);
|
||||
fprintf(fp, "addr: %lx; size: %u\n", addr, size);
|
||||
spi_flash_addr(cmd, addr);
|
||||
spi_send_cmd(dev, cmd, 4, NULL, 0);
|
||||
}
|
||||
|
|
|
@ -17,27 +17,34 @@
|
|||
static ssize_t usart_read(void *cookie, char *buf, size_t n)
|
||||
{
|
||||
uint32_t dev = (uint32_t)cookie;
|
||||
size_t nbytes = 0;
|
||||
size_t i;
|
||||
|
||||
while (n-- > 0) {
|
||||
*buf++ = (char)usart_recv_blocking(dev);
|
||||
nbytes++;
|
||||
for (i = 0; i < n; ++i) {
|
||||
buf[i] = (char)usart_recv_blocking(dev);
|
||||
|
||||
if (buf[i] == '\r') {
|
||||
buf[i] = '\n';
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return nbytes;
|
||||
return i;
|
||||
}
|
||||
|
||||
static ssize_t usart_write(void *cookie, const char *buf, size_t n)
|
||||
{
|
||||
uint32_t dev = (uint32_t)cookie;
|
||||
size_t nbytes = 0;
|
||||
size_t i;
|
||||
|
||||
while (n-- > 0) {
|
||||
usart_send_blocking(dev, *buf++);
|
||||
nbytes++;
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (buf[i] == '\n')
|
||||
usart_send_blocking(dev, '\r');
|
||||
|
||||
usart_send_blocking(dev, buf[i]);
|
||||
};
|
||||
|
||||
return nbytes;
|
||||
return i;
|
||||
}
|
||||
|
||||
FILE *init_usart(uint32_t dev)
|
||||
|
|
Loading…
Add table
Reference in a new issue