summaryrefslogtreecommitdiff
path: root/avr/cmd_sd.c
diff options
context:
space:
mode:
Diffstat (limited to 'avr/cmd_sd.c')
-rw-r--r--avr/cmd_sd.c67
1 files changed, 51 insertions, 16 deletions
diff --git a/avr/cmd_sd.c b/avr/cmd_sd.c
index 5494a13..f43725a 100644
--- a/avr/cmd_sd.c
+++ b/avr/cmd_sd.c
@@ -9,11 +9,11 @@
/*
- * di <pd#> - Initialize disk
+ * status <pd#> - Show socket status
*
*/
static
-command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
DSTATUS res;
BYTE dev;
@@ -25,26 +25,50 @@ command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
dev = (BYTE) strtoul(argv[1], 0, 10);
res = disk_status(dev);
- printf_P(PSTR("disk_status=%.2x\n"), res);
+ printf_P(PSTR("Socket status: %02x\n"), res);
+
+ return CMD_RET_SUCCESS;
+}
+
+/*
+ * init <pd#> - Initialize disk
+ *
+ */
+static
+command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ DSTATUS res;
+ BYTE dev;
- if ((res & STA_NODISK) == 0) {
- res = disk_initialize(dev);
+ (void) cmdtp; (void) flag;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ dev = (BYTE) strtoul(argv[1], 0, 10);
+
+ if (disk_status(dev) & STA_NODISK) {
+ printf_P(PSTR("No Disk\n"));
+ return CMD_RET_FAILURE;
}
+
+ res = disk_initialize(dev);
printf_P(PSTR("rc=%.2x\n"), res);
- if (res) {
+
+ if (res & (STA_NODISK | STA_NOINIT))
return CMD_RET_FAILURE;
- }
return CMD_RET_SUCCESS;
}
/*
- * ds <pd#> - Show disk status
+ * info <pd#> - Show disk info
*
*/
static
-command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
+ DSTATUS res;
BYTE dev;
union {
@@ -60,6 +84,12 @@ command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
dev = (BYTE) strtoul(argv[1], 0, 10);
+ res = disk_status(dev);
+ if (res & (STA_NODISK | STA_NOINIT)) {
+ printf_P(res & STA_NODISK ?
+ PSTR("No disk\n") : PSTR("Not initialized\n"));
+ return CMD_RET_FAILURE;
+ }
if (disk_ioctl(dev, GET_SECTOR_COUNT, &dat.ul) == RES_OK)
printf_P(PSTR("Drive size: %lu sectors\n"), dat.ul);
@@ -259,7 +289,7 @@ command_ret_t do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
/*
* Disk ioctl
- * dcs <pd#> - CTRL_SYNC
+ * sync <pd#> - CTRL_SYNC
*
*/
static
@@ -284,13 +314,18 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
cmd_tbl_t cmd_sd_sub[] = {
CMD_TBL_ITEM(
+ status, 2, 1, do_status,
+ "Socket staus",
+ ""
+),
+CMD_TBL_ITEM(
init, 2, 1, do_init,
"Initialize disk",
""
),
CMD_TBL_ITEM(
- status, 2, 1, do_status,
- "Disk status",
+ info, 2, 1, do_info,
+ "Disk info",
""
),
CMD_TBL_ITEM(
@@ -300,12 +335,12 @@ CMD_TBL_ITEM(
),
CMD_TBL_ITEM(
read, 2, 1, do_read,
- "read disk sector(s) into meomory",
+ "Read disk sector(s) into meomory",
"drive [sector [count [memaddr]]]"
),
CMD_TBL_ITEM(
write, 2, 1, do_write,
- "write sector(s) from meomory to disk",
+ "Write sector(s) from meomory to disk",
"drive [sector [count [memaddr]]]"
),
CMD_TBL_ITEM(
@@ -316,7 +351,7 @@ CMD_TBL_ITEM(
CMD_TBL_ITEM(
help, CONFIG_SYS_MAXARGS, 1, do_help,
- "print sub command description/usage",
+ "Print sub command description/usage",
"\n"
" - print brief description of all sub commands\n"
"sd help command ...\n"
@@ -325,7 +360,7 @@ CMD_TBL_ITEM(
/* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
{FSTR("?"), CONFIG_SYS_MAXARGS, 1, do_help,
- FSTR("alias for 'help'"),
+ FSTR("Alias for 'help'"),
#ifdef CONFIG_SYS_LONGHELP
FSTR(""),
#endif /* CONFIG_SYS_LONGHELP */