X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/2f53dd651e4bc075376ade16897272b41fd08a14..5f7f3586b0444116d5c1340465ecae8d6daa2461:/avr/cmd_sd.c diff --git a/avr/cmd_sd.c b/avr/cmd_sd.c index 5494a13..6b75d6e 100644 --- a/avr/cmd_sd.c +++ b/avr/cmd_sd.c @@ -1,3 +1,9 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include @@ -9,11 +15,11 @@ /* - * di - Initialize disk + * status - 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 +31,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 - 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 ((res & STA_NODISK) == 0) { - res = disk_initialize(dev); + 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 - Show disk status + * info - 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 +90,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 +295,7 @@ command_ret_t do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] /* * Disk ioctl - * dcs - CTRL_SYNC + * sync - CTRL_SYNC * */ static @@ -283,30 +319,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)", + " [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", + " [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", + " [sector [count [memaddr]]]" ), CMD_TBL_ITEM( sync, 2, 1, do_ioctl_sync, @@ -316,7 +357,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 +366,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 */