/*
- * 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;
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 {
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);
/*
* Disk ioctl
- * dcs <pd#> - CTRL_SYNC
+ * sync <pd#> - CTRL_SYNC
*
*/
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(
),
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(
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"
/* 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 */
#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)
static
void deselect(BYTE drv)
{
- debug("*** enter deselect()\n");
+ //debug("*** enter deselect()\n");
if (drv == 0)
SD_CS_0 = 1;
else {
SD_CS_1 = 0;
#endif
}
- debug("*** exit deselect()\n");
+ //debug("*** exit deselect()\n");
}
/*-----------------------------------------------------------------------*/
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 {
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 */
}
static
void power_on(BYTE drv)
{
- debug("*** enter power_on()\n");
+ //debug("*** enter power_on()\n");
if (drv == 0) {
#ifdef SD_PWR_0
#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);
#endif
}
socket[drv].stat |= STA_NOINIT;
- debug("*** exit power_off()\n");
+ //debug("*** exit power_off()\n");
}
#if 0
} 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;
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);
}
/* 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;
/* 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 */