]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_sd.c
rewrite of cmd_cpu/do_cpu_freq
[z180-stamp.git] / avr / cmd_sd.c
index b84c4be758ec94b0d6797479c92ad56062dd7fc6..344a19793e4d7ee9ecc22d3367f55e1d82785cae 100644 (file)
@@ -1,13 +1,11 @@
 /*
 /*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014, 2018 Leo C. <erbl259-lmu@yahoo.de>
  *
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
  */
 
-#include "common.h"
-//#include <stdlib.h>
+#include "cmd_sd.h"
 
 
-#include "command.h"
 #include "diskio.h"
 #include "ff.h"
 #include "eval_arg.h"
 #include "diskio.h"
 #include "ff.h"
 #include "eval_arg.h"
@@ -20,7 +18,7 @@
  *
  */
 static
  *
  */
 static
-command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_status(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
 {
        DSTATUS res;
        BYTE dev;
 {
        DSTATUS res;
        BYTE dev;
@@ -42,7 +40,7 @@ command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
  *
  */
 static
  *
  */
 static
-command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_init(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
 {
        DSTATUS res;
        BYTE dev;
 {
        DSTATUS res;
        BYTE dev;
@@ -54,10 +52,8 @@ command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        dev = (BYTE) eval_arg(argv[1], NULL);
 
 
        dev = (BYTE) eval_arg(argv[1], NULL);
 
-       if (disk_status(dev) & STA_NODISK) {
-               printf_P(PSTR("No Disk\n"));
-               return CMD_RET_FAILURE;
-       }
+       if (disk_status(dev) & STA_NODISK)
+               cmd_error(CMD_RET_FAILURE, 0, PSTR("No disk"));
 
        res = disk_initialize(dev);
        printf_P(PSTR("rc=%.2x\n"), res);
 
        res = disk_initialize(dev);
        printf_P(PSTR("rc=%.2x\n"), res);
@@ -73,7 +69,7 @@ command_ret_t do_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  *
  */
 static
  *
  */
 static
-command_ret_t do_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_info(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
 {
        DSTATUS res;
        BYTE dev;
 {
        DSTATUS res;
        BYTE dev;
@@ -122,11 +118,11 @@ command_ret_t do_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  *
  */
 static
  *
  */
 static
-command_ret_t do_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_dump(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
 {
        static BYTE dev_last;
        static  DWORD sec_last;
 {
        static BYTE dev_last;
        static  DWORD sec_last;
-       BYTE buffer[_MAX_SS];
+       BYTE buffer[FF_MAX_SS];
        char header[20];
 
        DRESULT res;
        char header[20];
 
        DRESULT res;
@@ -156,13 +152,11 @@ command_ret_t do_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        for ( ; count; count--, sec++) {
                res = disk_read(dev, buffer, sec, 1);
 
        for ( ; count; count--, sec++) {
                res = disk_read(dev, buffer, sec, 1);
 
-               if (res) {
-                       printf_P(PSTR("rc=%.2x\n"), res);
-                       return CMD_RET_FAILURE;
-               }
+               if (res)
+                       cmd_error(CMD_RET_FAILURE, 0, PSTR("rc=%.2x"), res);
 
                sprintf_P(header, PSTR("Sector: %lu"), sec);
 
                sprintf_P(header, PSTR("Sector: %lu"), sec);
-               dump_ram(buffer, 0, _MAX_SS, header);
+               dump_ram(buffer, 0, FF_MAX_SS, header);
        }
        dev_last = dev;
        sec_last = sec;
        }
        dev_last = dev;
        sec_last = sec;
@@ -175,14 +169,14 @@ command_ret_t do_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  *
  */
 static
  *
  */
 static
-command_ret_t do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_read(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
 {
        DRESULT res;
        BYTE dev;
        DWORD sec;
        uint32_t addr;
        int count, nr;
 {
        DRESULT res;
        BYTE dev;
        DWORD sec;
        uint32_t addr;
        int count, nr;
-       BYTE buffer[_MAX_SS];
+       BYTE buffer[FF_MAX_SS];
 
        static DWORD sec_last;
        static uint32_t addr_last;
 
        static DWORD sec_last;
        static uint32_t addr_last;
@@ -210,13 +204,10 @@ command_ret_t do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        for (nr = 0; nr < count;) {
                nr++;
                if ((res = disk_read(dev, buffer, sec, 1)) == RES_OK) {
        for (nr = 0; nr < count;) {
                nr++;
                if ((res = disk_read(dev, buffer, sec, 1)) == RES_OK) {
-                       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-                               my_puts_P(PSTR("Bus timeout\n"));
-                               return  CMD_RET_FAILURE;
-                       }
-                       z80_write_block(buffer, addr /*+ base*/, _MAX_SS);
+                       z80_bus_request_or_exit();
+                       z80_write_block(buffer, addr /*+ base*/, FF_MAX_SS);
                        z80_bus_cmd(Release);
                        z80_bus_cmd(Release);
-                       sec++; addr += _MAX_SS;
+                       sec++; addr += FF_MAX_SS;
                } else
                        break;
        }
                } else
                        break;
        }
@@ -237,14 +228,14 @@ command_ret_t do_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  *
  */
 static
  *
  */
 static
-command_ret_t do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_write(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
 {
        DRESULT res;
        BYTE dev;
        DWORD sec;
        uint32_t addr;
        int count, nr;
 {
        DRESULT res;
        BYTE dev;
        DWORD sec;
        uint32_t addr;
        int count, nr;
-       BYTE buffer[_MAX_SS];
+       BYTE buffer[FF_MAX_SS];
 
        static DWORD sec_last;
        static uint32_t addr_last;
 
        static DWORD sec_last;
        static uint32_t addr_last;
@@ -271,17 +262,14 @@ command_ret_t do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 
        for (nr = 0; nr < count;) {
                nr++;
 
        for (nr = 0; nr < count;) {
                nr++;
-               if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-                       my_puts_P(PSTR("Bus timeout\n"));
-                       return  CMD_RET_FAILURE;
-               }
-               z80_read_block(buffer, addr /*+ base*/, _MAX_SS);
+               z80_bus_request_or_exit();
+               z80_read_block(buffer, addr /*+ base*/, FF_MAX_SS);
                z80_bus_cmd(Release);
 
                res = disk_write(dev, buffer, sec, 1);
                if (res != RES_OK)
                        break;
                z80_bus_cmd(Release);
 
                res = disk_write(dev, buffer, sec, 1);
                if (res != RES_OK)
                        break;
-               sec++; addr += _MAX_SS;
+               sec++; addr += FF_MAX_SS;
        }
 
        printf_P(PSTR("%d sector(s) written, rc=%.2x.\n"), nr, res);
        }
 
        printf_P(PSTR("%d sector(s) written, rc=%.2x.\n"), nr, res);
@@ -300,7 +288,7 @@ command_ret_t do_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
  *
  */
 static
  *
  */
 static
-command_ret_t do_ioctl_sync(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_ioctl_sync(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
 {
        BYTE dev;
 
 {
        BYTE dev;
 
@@ -316,48 +304,45 @@ command_ret_t do_ioctl_sync(cmd_tbl_t *cmdtp, int flag, int argc, char * const a
 }
 
 
 }
 
 
-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_t cmd_tbl_sd[] = {
 CMD_TBL_ITEM(
 CMD_TBL_ITEM(
-       status, 2,                      1,      do_status,
-       "Socket staus",
+       status, 2,                      CTBL_RPT,       do_status,
+       "Socket status",
        "drive"
 ),
 CMD_TBL_ITEM(
        "drive"
 ),
 CMD_TBL_ITEM(
-       init,   2,                      1,      do_init,
+       init,   2,                      CTBL_RPT,       do_init,
        "Initialize disk",
        "drive"
 ),
 CMD_TBL_ITEM(
        "Initialize disk",
        "drive"
 ),
 CMD_TBL_ITEM(
-       info,   2,                      1,      do_info,
+       info,   2,                      CTBL_RPT,       do_info,
        "Disk info",
        "drive"
 ),
 CMD_TBL_ITEM(
        "Disk info",
        "drive"
 ),
 CMD_TBL_ITEM(
-       dump,   CONFIG_SYS_MAXARGS,     1,      do_dump,
+       dump,   CONFIG_SYS_MAXARGS,     CTBL_RPT,       do_dump,
        "Dump sector(s)",
        "drive [sector [count ]]"
 ),
 CMD_TBL_ITEM(
        "Dump sector(s)",
        "drive [sector [count ]]"
 ),
 CMD_TBL_ITEM(
-       read,   2,                      1,      do_read,
+       read,   2,                      CTBL_RPT,       do_read,
        "Read disk sector(s) into meomory",
        "drive [sector [count [memaddr]]]"
 ),
 CMD_TBL_ITEM(
        "Read disk sector(s) into meomory",
        "drive [sector [count [memaddr]]]"
 ),
 CMD_TBL_ITEM(
-       write,  2,                      1,      do_write,
+       write,  2,                      CTBL_RPT,       do_write,
        "Write sector(s) from meomory to disk",
        "drive [sector [count [memaddr]]]"
 ),
 CMD_TBL_ITEM(
        "Write sector(s) from meomory to disk",
        "drive [sector [count [memaddr]]]"
 ),
 CMD_TBL_ITEM(
-       sync,   2,                      1,      do_ioctl_sync,
+       sync,   2,                      CTBL_RPT,       do_ioctl_sync,
        "Device control: SYNC",
        "drive"
 ),
 
 CMD_TBL_ITEM(
        "Device control: SYNC",
        "drive"
 ),
 
 CMD_TBL_ITEM(
-       help,   CONFIG_SYS_MAXARGS,     1,      do_help,
+       help,   CONFIG_SYS_MAXARGS,     CTBL_RPT,       do_help,
        "Print sub command description/usage",
        "\n"
        "       - print brief description of all sub commands\n"
        "Print sub command description/usage",
        "\n"
        "       - print brief description of all sub commands\n"
@@ -367,38 +352,22 @@ 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,
 
 /* 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'"),
+        NULL,
 #ifdef  CONFIG_SYS_LONGHELP
        FSTR(""),
 #endif /* CONFIG_SYS_LONGHELP */
 #ifdef  CONFIG_SYS_LONGHELP
        FSTR(""),
 #endif /* CONFIG_SYS_LONGHELP */
+       NULL,
 #ifdef CONFIG_AUTO_COMPLETE
 #ifdef CONFIG_AUTO_COMPLETE
-       0,
+       NULL,
 #endif
 },
 #endif
 },
+/* Mark end of table */
+CMD_TBL_END(cmd_tbl_sd)
 };
 
 };
 
-static
-command_ret_t do_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       return _do_help(cmd_sd_sub, ARRAY_SIZE(cmd_sd_sub), cmdtp, flag, argc, argv);
-}
-
 
 
-command_ret_t do_sd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_sd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
 {
 {
-       cmd_tbl_t *cp;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       /* drop initial "sd" arg */
-       argc--;
-       argv++;
-
-       cp = find_cmd_tbl(argv[0], cmd_sd_sub, ARRAY_SIZE(cmd_sd_sub));
-
-       if (cp)
-               return cp->cmd(cmdtp, flag, argc, argv);
-
+       puts_P(PSTR("Huch?"));
        return CMD_RET_USAGE;
 }
        return CMD_RET_USAGE;
 }