]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_sd.c
Card detect over cs pin: clean initialisation/power up
[z180-stamp.git] / avr / cmd_sd.c
index 5494a13fda6b4139c6b3368674523fe5011cc0d1..46dbcfdc3ff30619f80f1593338e9a2a5a59a839 100644 (file)
@@ -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;
+
+       (void) cmdtp; (void) flag;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       dev = (BYTE) strtoul(argv[1], 0, 10);
 
-       if ((res & STA_NODISK) == 0) {
-               res = disk_initialize(dev);
+       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
@@ -283,30 +313,35 @@ static
 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(
        dump,   CONFIG_SYS_MAXARGS,     1,      do_dump,
-       "Dump sector",
-       ""
+       "Dump sector(s)",
+       "<drive> [sector [count ]]"
 ),
 CMD_TBL_ITEM(
        read,   2,                      1,      do_read,
-       "read disk sector(s) into meomory",
-       "drive [sector [count [memaddr]]]"
+       "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",
-       "drive [sector [count [memaddr]]]"
+       "Write sector(s) from meomory to disk",
+       "<drive> [sector [count [memaddr]]]"
 ),
 CMD_TBL_ITEM(
        sync,   2,                      1,      do_ioctl_sync,
@@ -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 */