shell: use flash driver model instead

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 094c600283
commit 19bd043ac3
  1. 36
      source/shell.c

@ -10,10 +10,9 @@
#include <limits.h>
#include <sys/types.h>
#include "macros.h"
#include "shell.h"
#include "spi_flash.h"
#include "usart.h"
#include <flash.h>
#include <macros.h>
#include <shell.h>
static void do_probe(const char *s);
static void do_read(const char *s);
@ -28,6 +27,8 @@ struct cmd cmds[] = {
{ NULL, NULL },
};
static 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)
@ -117,13 +118,9 @@ err_free_line:
static void do_probe(const char *s)
{
char cmd[1] = { CMD_READ_ID };
char buf[6];
(void)s;
spi_send_cmd(SPI1, cmd, 1, buf, 6);
printf("JEDEC ID: %02x%02x%02x\n", buf[0], buf[1], buf[2]);
flash = flash_probe();
}
static void do_read(const char *s)
@ -131,6 +128,11 @@ static void do_read(const char *s)
char buf[256], *end = NULL;
size_t addr, len, nbytes;
if (!flash) {
fprintf(stderr, "error: no flash device probed.\n");
return;
}
if (strncmp(s, "0x", 2) == 0)
s += 2;
@ -156,7 +158,7 @@ static void do_read(const char *s)
while (len) {
nbytes = min(len, 256);
spi_flash_read(SPI1, addr, buf, nbytes);
flash_read(flash, addr, buf, nbytes);
print_hex_ascii(buf, nbytes);
addr += nbytes;
@ -169,6 +171,11 @@ static void do_write(const char *s)
char buf[256], *end = NULL;
size_t addr, len, nbytes;
if (!flash) {
fprintf(stderr, "error: no flash device probed.\n");
return;
}
if (strncmp(s, "0x", 2) == 0)
s += 2;
@ -197,7 +204,7 @@ static void do_write(const char *s)
parse_hex(stdin, buf, nbytes);
printf("\n");
print_hex_ascii(buf, nbytes);
spi_flash_write(SPI1, addr, buf, nbytes);
flash_write(flash, addr, buf, nbytes);
addr += nbytes;
len -= nbytes;
@ -209,6 +216,11 @@ static void do_erase(const char *s)
char *end = NULL;
size_t addr, len;
if (!flash) {
fprintf(stderr, "error: no flash device probed.\n");
return;
}
if (strncmp(s, "0x", 2) == 0)
s += 2;
@ -232,7 +244,7 @@ static void do_erase(const char *s)
if (!len)
return;
spi_flash_erase(SPI1, addr, len);
flash_erase(flash, addr, len);
}
static void parse_cmd(const char *s)

Loading…
Cancel
Save