]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Card detect over cs pin. (works mostly)
authorLeo C <erbl259-lmu@yahoo.de>
Thu, 4 Dec 2014 15:10:35 +0000 (16:10 +0100)
committerLeo C <erbl259-lmu@yahoo.de>
Thu, 4 Dec 2014 15:10:35 +0000 (16:10 +0100)
avr/cmd_sd.c
avr/mmc.c

index 5494a13fda6b4139c6b3368674523fe5011cc0d1..f43725af7ec590c437a267faaeaf1294810c2ef1 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;
 
-       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
@@ -283,14 +313,19 @@ 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(
@@ -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 */
index 8c30c9712aac9953271f75ea537c5d4cd4c756c3..afb1473627bcfab089788b47cd735456bbddec0c 100644 (file)
--- a/avr/mmc.c
+++ b/avr/mmc.c
@@ -29,9 +29,9 @@
 #define SD_CS_0_IN     SBIT(PINB,0)
 #define SD_CS_0_DDR    SBIT(DDRB,0)
 
-#define SD_CD_1                SBIT(PORTG,3)           /* Card detect switch */
-#define SD_CD_1_IN     SBIT(PING,3)
-#define SD_CD_1_DDR    SBIT(DDRG,3)
+//#define SD_CD_1              SBIT(PORTG,3)           /* Card detect switch */
+//#define SD_CD_1_IN   SBIT(PING,3)
+//#define SD_CD_1_DDR  SBIT(DDRG,3)
 
 //#define SD_WP_1      SBIT(PORTG,5)           /* Write protect switch */
 #define SD_WP_1_IN     SBIT(PING,5)
@@ -112,7 +112,7 @@ int wait_ready (void)       /* 1:OK, 0:Timeout */
 static
 void deselect(BYTE drv)
 {
-       debug("*** enter deselect()\n");
+       //debug("*** enter deselect()\n");
        if (drv == 0)
                SD_CS_0 = 1;
        else {
@@ -137,7 +137,7 @@ void deselect(BYTE drv)
                SD_CS_1 = 0;
 #endif
        }
-       debug("***  exit deselect()\n");
+       //debug("***  exit deselect()\n");
 }
 
 /*-----------------------------------------------------------------------*/
@@ -147,7 +147,7 @@ void deselect(BYTE drv)
 static
 int select(BYTE drv)   /* 1:Successful, 0:Timeout */
 {
-       debug("*** enter select()\n");
+       //debug("*** enter select()\n");
        if (drv == 0)
                SD_CS_0 = 0;
        else {
@@ -167,11 +167,11 @@ int select(BYTE drv)      /* 1:Successful, 0:Timeout */
        spi_rcvr();
 
        if (wait_ready()) {
-               debug("***  exit select() == 1\n");
+               //debug("***  exit select() == 1\n");
                return 1;       /* OK */
        }
        deselect(drv);
-       debug("***  exit select() == 0\n");
+       //debug("***  exit select() == 0\n");
 
        return 0;       /* Timeout */
 }
@@ -185,7 +185,7 @@ int select(BYTE drv)        /* 1:Successful, 0:Timeout */
 static
 void power_on(BYTE drv)
 {
-       debug("*** enter power_on()\n");
+       //debug("*** enter power_on()\n");
 
        if (drv == 0) {
 #ifdef SD_PWR_0
@@ -233,13 +233,13 @@ void power_on(BYTE drv)
 #endif
        }
 
-       debug("***  exit power_on()\n");
+       //debug("***  exit power_on()\n");
 }
 
 static
 void power_off(BYTE drv)
 {
-       debug("*** enter power_off()\n");
+       //debug("*** enter power_off()\n");
        select(drv);            /* Wait for card ready */
        deselect(drv);
 
@@ -253,7 +253,7 @@ void power_off(BYTE drv)
 #endif
        }
        socket[drv].stat |= STA_NOINIT;
-       debug("***  exit power_off()\n");
+       //debug("***  exit power_off()\n");
 }
 
 #if 0
@@ -362,7 +362,7 @@ BYTE send_cmd (             /* Returns R1 resp (bit7==1:Send failed) */
        } argtmp;
        BYTE n, res;
 
-       debug("*** send_cmd( %.2x )\n", cmd);
+       //debug("*** send_cmd( %.2x )\n", cmd);
 
        if (cmd & 0x80) { /* ACMD<n> is the command sequense of CMD55-CMD<n> */
                cmd &= 0x7F;
@@ -474,7 +474,8 @@ DSTATUS disk_initialize (
        deselect(drv);
 
        if (ty) { /* Initialization succeded */
-               socket[drv].stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
+               /* Clear STA_NOINIT */
+               socket[drv].stat = (socket[drv].stat & ~STA_NOINIT) | STA_FAST;
        } else { /* Initialization failed */
                power_off(drv);
        }
@@ -516,7 +517,6 @@ DRESULT disk_read (
        /* Convert to byte address if needed */
        if (!(socket[drv].CardType & CT_BLOCK))
                sector *= 512;
-       socket[drv].stat |= STA_FAST;
 
        /*  READ_MULTIPLE_BLOCK : READ_SINGLE_BLOCK */
        cmd = count > 1 ? CMD18 : CMD17;
@@ -556,7 +556,6 @@ DRESULT disk_write (
        /* Convert to byte address if needed */
        if (!(socket[drv].CardType & CT_BLOCK))
                sector *= 512;
-       socket[drv].stat |= STA_FAST;
 
        if (count == 1) {
                /* Single block write */