summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
b9aef06)
# Conflicts:
# avr/cmd_fat.c
* fatstat path - Show logical drive status
*
*/
* fatstat path - Show logical drive status
*
*/
-command_ret_t do_stat(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
+command_ret_t do_stat(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
{
FATFS *fs;
DWORD nfreeclst;
{
FATFS *fs;
DWORD nfreeclst;
path = (char *) malloc(BUFFER_SIZE);
if (path == NULL) {
path = (char *) malloc(BUFFER_SIZE);
if (path == NULL) {
- printf_P(PSTR("fatstat: Out of Memory!\n"));
+ printf_P(PSTR("fat stat: Out of Memory!\n"));
free(path);
return CMD_RET_FAILURE;
}
free(path);
return CMD_RET_FAILURE;
}
cmd_tbl_t cmd_tbl_fat[] = {
CMD_TBL_ITEM(
cmd_tbl_t cmd_tbl_fat[] = {
CMD_TBL_ITEM(
- stat, 2, CTBL_REPEAT, do_stat,
+ stat, 2, CTBL_RPT, do_stat,
"Show logical drive status",
"dev"
),
CMD_TBL_ITEM(
"Show logical drive status",
"dev"
),
CMD_TBL_ITEM(
- pwd, 2, CTBL_REPEAT, do_pwd,
+ pwd, 2, CTBL_RPT, do_pwd,
"Print name of current/working directory",
""
),
CMD_TBL_ITEM(
"Print name of current/working directory",
""
),
CMD_TBL_ITEM(
- cd, 2, CTBL_REPEAT, do_cd,
"Change the current/working directory.",
"path"
),
CMD_TBL_ITEM(
"Change the current/working directory.",
"path"
),
CMD_TBL_ITEM(
- ls, 2, CTBL_REPEAT, do_ls,
+ ls, 2, CTBL_RPT, do_ls,
"Directory listing",
"path"
),
"Directory listing",
"path"
),
" the load stops on end of file."
),
CMD_TBL_ITEM(
" the load stops on end of file."
),
CMD_TBL_ITEM(
"write file into a dos filesystem",
"<d:/path/filename> <addr> <bytes>\n"
" - Write file to 'path/filename' on logical drive 'd' from RAM\n"
"write file into a dos filesystem",
"<d:/path/filename> <addr> <bytes>\n"
" - Write file to 'path/filename' on logical drive 'd' from RAM\n"
- help, CONFIG_SYS_MAXARGS, CTBL_REPEAT, 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"
cmd_tbl_t cmd_tbl_sd[] = {
CMD_TBL_ITEM(
cmd_tbl_t cmd_tbl_sd[] = {
CMD_TBL_ITEM(
- status, 2, CTBL_REPEAT, do_status,
+ status, 2, CTBL_RPT, do_status,
"Socket staus",
"drive"
),
CMD_TBL_ITEM(
"Socket staus",
"drive"
),
CMD_TBL_ITEM(
- init, 2, CTBL_REPEAT, do_init,
+ init, 2, CTBL_RPT, do_init,
"Initialize disk",
"drive"
),
CMD_TBL_ITEM(
"Initialize disk",
"drive"
),
CMD_TBL_ITEM(
- info, 2, CTBL_REPEAT, do_info,
+ info, 2, CTBL_RPT, do_info,
"Disk info",
"drive"
),
CMD_TBL_ITEM(
"Disk info",
"drive"
),
CMD_TBL_ITEM(
- dump, CONFIG_SYS_MAXARGS, CTBL_REPEAT, 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, CTBL_REPEAT, 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, CTBL_REPEAT, 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, CTBL_REPEAT, 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, CTBL_REPEAT, 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"
command_ret_t do_sd(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
{
command_ret_t do_sd(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
{
/*
* find command table entry for a command
*/
/*
* find command table entry for a command
*/
-cmd_tbl_t *find_cmd (const char *cmd, cmd_tbl_t *table)
-{
- cmd_tbl_t *cmdtp;
- cmd_tbl_t *cmdtp_temp = table; /*Init value */
- int table_len = cmd_tbl_item_count(table);
- size_t len;
- uint_fast8_t n_found = 0;
-
- char *optenv = getenv_str(PSTR("cmd"));
- bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL;
-
- if (!cmd)
- return NULL;
+typedef struct {
+ size_t len;
+ uint_fast8_t level;
+ bool opt_debug;
+ } find_cmd_para_t;
+cmd_tbl_t *_find_cmd (const char *cmd, cmd_tbl_t *table, find_cmd_para_t *para)
+{
+ cmd_tbl_t *cmdtp_ret = NULL;
+ uint_fast8_t n_found = 0, sub_found = 0;
- for (cmdtp = table;
- cmdtp != table + table_len;
- cmdtp++) {
- if (strncmp_P(cmd, cmdtp->name, len) == 0 &&
- (opt_debug || cmdtp->name[0] != '!')) {
- if (len == strlen_P(cmdtp->name))
+ for (cmd_tbl_t *cmdtp = table; cmdtp->name != NULL; cmdtp++) {
+ if (strncmp_P(cmd, cmdtp->name, para->len) == 0 &&
+ (para->opt_debug || !(cmdtp->flags & CTBL_DBG))) {
+ if (para->len == strlen_P(cmdtp->name))
return cmdtp; /* full match */
return cmdtp; /* full match */
- cmdtp_temp = cmdtp; /* abbreviated command ? */
+ cmdtp_ret = cmdtp; /* abbreviated command ? */
+ } else if (cmdtp->subcmd && cmdtp->flags & CTBL_SUBCMDAUTO) {
+ cmd_tbl_t *sub = _find_cmd(cmd, cmdtp->subcmd, para);
+ if (sub) {
+ cmdtp_ret = sub;
+ ++n_found;
+ }
- if (n_found == 1) /* exactly one match */
- return cmdtp_temp;
+ if (n_found == 1) { /* exactly one match */
+ if (sub_found)
+ para->level++;
+ return cmdtp_ret;
+ }
return NULL; /* not found or ambiguous command */
}
return NULL; /* not found or ambiguous command */
}
+
+cmd_tbl_t *find_cmd (const char *cmd, cmd_tbl_t *table, uint_fast8_t *cmdlevel)
+{
+ find_cmd_para_t para;
+
+ if (!cmd)
+ return NULL;
+
+ char *optenv = getenv_str(PSTR("cmd"));
+ para.level = 0;
+ para.opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL;
+ para.len = strlen(cmd);
+
+ cmd_tbl_t *cmdtp = _find_cmd(cmd, table, ¶);
+
+ if (cmdlevel)
+ *cmdlevel = para.level;
+ return cmdtp;
+}
+
cmd_tbl_t *find_cmd_sub(const char *cmd, cmd_tbl_t *table)
{
cmd_tbl_t *entry = NULL;
for (cmd_tbl_t *tp = get_cmd_tbl_base(table); tp->name && entry == NULL; tp++)
if (tp->subcmd && tp->flags & CTBL_SUBCMDAUTO)
cmd_tbl_t *find_cmd_sub(const char *cmd, cmd_tbl_t *table)
{
cmd_tbl_t *entry = NULL;
for (cmd_tbl_t *tp = get_cmd_tbl_base(table); tp->name && entry == NULL; tp++)
if (tp->subcmd && tp->flags & CTBL_SUBCMDAUTO)
- entry = find_cmd(cmd, tp->subcmd);
+ entry = find_cmd(cmd, tp->subcmd, NULL);
* for long help messages
*/
* for long help messages
*/
-command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
+command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char * const argv[])
cmd_tbl_t *tbl_start = get_cmd_tbl_base(cmdtp);
char *optenv = getenv_str(PSTR("cmd"));
cmd_tbl_t *tbl_start = get_cmd_tbl_base(cmdtp);
char *optenv = getenv_str(PSTR("cmd"));
/* print short help (usage) */
for (int i = 0; i < cmd_items; i++) {
/* print short help (usage) */
for (int i = 0; i < cmd_items; i++) {
- if (opt_debug || cmd_array[i]->name[0] != '!') {
+ if (opt_debug || !(cmd_array[i]->flags & CTBL_DBG)) {
const FLASH char *usage = cmd_array[i]->usage;
/* allow user abort */
const FLASH char *usage = cmd_array[i]->usage;
/* allow user abort */
* command help (long version)
*/
for (uint8_t i = 1; i < argc; ++i) {
* command help (long version)
*/
for (uint8_t i = 1; i < argc; ++i) {
- if ((cmdtp = find_cmd(argv[i], tbl_start)) != NULL &&
+ if ((cmdtp = find_cmd(argv[i], tbl_start, NULL)) != NULL &&
(opt_debug || cmdtp->name[0] != '!')) {
cmd_usage(cmdtp);
} else {
(opt_debug || cmdtp->name[0] != '!')) {
cmd_usage(cmdtp);
} else {
{
command_ret_t rc = CMD_RET_SUCCESS;
cmd_tbl_t *cmdtp;
{
command_ret_t rc = CMD_RET_SUCCESS;
cmd_tbl_t *cmdtp;
/* Look up command in command table */
/* Look up command in command table */
- cmdtp = find_cmd(argv[0], cmd_tbl);
+ cmdtp = find_cmd(argv[0], cmd_tbl, &cmdlevel);
if (cmdtp != NULL) {
/* Check if this command has subcommands */
if (cmdtp->subcmd && argc > 1) {
/* Look up subcommand in subcommand table */
if (cmdtp != NULL) {
/* Check if this command has subcommands */
if (cmdtp->subcmd && argc > 1) {
/* Look up subcommand in subcommand table */
- cmd_tbl_t *cmdtpsub = find_cmd(argv[1], cmdtp->subcmd);
+ cmd_tbl_t *cmdtpsub = find_cmd(argv[1], cmdtp->subcmd, &cmdlevel);
if (cmdtpsub == NULL) {
printf_P(PSTR("Unknown '%s' subcommand '%s' - try '%s help'\n"), argv[0], argv[1], argv[0]);
return CMD_RET_FAILURE;
if (cmdtpsub == NULL) {
printf_P(PSTR("Unknown '%s' subcommand '%s' - try '%s help'\n"), argv[0], argv[1], argv[0]);
return CMD_RET_FAILURE;
- cmdtp = find_cmd_sub(argv[0], cmd_tbl);
+ cmdtp = find_cmd_sub(argv[0], cmd_tbl, &cmdlevel);
if (cmdtp == NULL) {
printf_P(PSTR("Unknown command '%s' - try 'help'\n"), argv[0]);
if (cmdtp == NULL) {
printf_P(PSTR("Unknown command '%s' - try 'help'\n"), argv[0]);
/* If OK so far, then do the command */
if (!rc) {
rc = cmd_call(cmdtp, flag, argc, argv);
/* If OK so far, then do the command */
if (!rc) {
rc = cmd_call(cmdtp, flag, argc, argv);
- *repeatable &= (cmdtp->flags & CTBL_REPEAT) != 0;
+ *repeatable &= (cmdtp->flags & CTBL_RPT) != 0;
}
if (rc == CMD_RET_USAGE)
rc = cmd_usage(cmdtp);
}
if (rc == CMD_RET_USAGE)
rc = cmd_usage(cmdtp);
#ifdef DEBUG
CMD_TBL_ITEM(
#ifdef DEBUG
CMD_TBL_ITEM(
- !mdr, 3, 1, do_dump_mem,
+ !mdr, 3, CTBL_DBG|CTBL_RPT, do_dump_mem,
"RAM dump",
"address [count]"
),
CMD_TBL_ITEM(
"RAM dump",
"address [count]"
),
CMD_TBL_ITEM(
- !mde, 3, 1, do_dump_mem,
+ !mde, 3, CTBL_DBG|CTBL_RPT, do_dump_mem,
"EEPROM dump",
"address [count]"
),
CMD_TBL_ITEM(
"EEPROM dump",
"address [count]"
),
CMD_TBL_ITEM(
- !mdf, 3, 1, do_dump_mem,
+ !mdf, 3, CTBL_DBG|CTBL_RPT, do_dump_mem,
"FLASH dump",
"address [count]"
),
CMD_TBL_ITEM(
"FLASH dump",
"address [count]"
),
CMD_TBL_ITEM(
+ !cpe, 4, CTBL_DBG, do_eep_cp,
"EEPROM copy",
"source target count"
),
CMD_TBL_ITEM(
"EEPROM copy",
"source target count"
),
CMD_TBL_ITEM(
- !mm, 2, 1, do_mem_mm_avr,
+ !mm, 2, CTBL_DBG|CTBL_RPT, do_mem_mm_avr,
"avr memory modify (auto-incrementing address)",
"address"
),
CMD_TBL_ITEM(
"avr memory modify (auto-incrementing address)",
"address"
),
CMD_TBL_ITEM(
- !nm, 2, 1, do_mem_nm_avr,
+ !nm, 2, CTBL_DBG|CTBL_RPT, do_mem_nm_avr,
"avr memory modify (constant address)",
"address"
),
CMD_TBL_ITEM(
"avr memory modify (constant address)",
"address"
),
CMD_TBL_ITEM(
- !prfree, 1, 1, do_pr_free_avr,
+ !prfree, 1, CTBL_DBG|CTBL_RPT, do_pr_free_avr,
"print avr heap free list",
""
),
CMD_TBL_ITEM(
"print avr heap free list",
""
),
CMD_TBL_ITEM(
- !prheap, 1, 1, do_pr_heap_avr,
+ !prheap, 1, CTBL_DBG, do_pr_heap_avr,
- md, 3, CTBL_REPEAT, do_mem_md,
+ md, 3, CTBL_RPT, do_mem_md,
"memory display",
"address [# of objects]"
),
CMD_TBL_ITEM(
"memory display",
"address [# of objects]"
),
CMD_TBL_ITEM(
- mm, 2, CTBL_REPEAT, do_mem_mm,
+ mm, 2, CTBL_RPT, do_mem_mm,
"memory modify (auto-incrementing address)",
"address"
),
CMD_TBL_ITEM(
"memory modify (auto-incrementing address)",
"address"
),
CMD_TBL_ITEM(
- nm, 2, CTBL_REPEAT, do_mem_nm,
+ nm, 2, CTBL_RPT, do_mem_nm,
"memory modify (constant address)",
"address"
),
CMD_TBL_ITEM(
"memory modify (constant address)",
"address"
),
CMD_TBL_ITEM(
- mw, CONFIG_SYS_MAXARGS, CTBL_REPEAT, do_mem_mw,
+ mw, CONFIG_SYS_MAXARGS, CTBL_RPT, do_mem_mw,
"memory write (fill)",
"[-bwl] address value [count]\n"
" -b write value as byte (8 bit, default)\n"
"memory write (fill)",
"[-bwl] address value [count]\n"
" -b write value as byte (8 bit, default)\n"
" -l write value as long (32 bit)"
),
CMD_TBL_ITEM(
" -l write value as long (32 bit)"
),
CMD_TBL_ITEM(
- cp, 4, CTBL_REPEAT, do_mem_cp,
+ cp, 4, CTBL_RPT, do_mem_cp,
"memory copy",
"source target count"
),
CMD_TBL_ITEM(
"memory copy",
"source target count"
),
CMD_TBL_ITEM(
- cmp, 4, CTBL_REPEAT, do_mem_cmp,
+ cmp, 4, CTBL_RPT, do_mem_cmp,
"memory compare",
"addr1 addr2 count"
),
"memory compare",
"addr1 addr2 count"
),
" - set address offset for memory commands to 'offset'"
),
CMD_TBL_ITEM(
" - set address offset for memory commands to 'offset'"
),
CMD_TBL_ITEM(
- mloop, 3, CTBL_REPEAT, do_mem_loop,
+ mloop, 3, CTBL_RPT, do_mem_loop,
"infinite loop on address range",
"address number_of_bytes"
),
CMD_TBL_ITEM(
"infinite loop on address range",
"address number_of_bytes"
),
CMD_TBL_ITEM(
- mloopw, 4, CTBL_REPEAT, do_mem_loopw,
+ mloopw, 4, CTBL_RPT, do_mem_loopw,
"infinite write loop on address range",
"address number_of_bytes data_to_write"
),
#ifdef CONFIG_CMD_MEMTEST
CMD_TBL_ITEM(
"infinite write loop on address range",
"address number_of_bytes data_to_write"
),
#ifdef CONFIG_CMD_MEMTEST
CMD_TBL_ITEM(
- mtest, 4, CTBL_REPEAT, do_mem_mtest,
+ mtest, 4, CTBL_RPT, do_mem_mtest,
"simple RAM read/write test",
"[start [end [iterations]]]"
),
"simple RAM read/write test",
"[start [end [iterations]]]"
),
#ifdef CONFIG_MX_CYCLIC
CMD_TBL_ITEM(
#ifdef CONFIG_MX_CYCLIC
CMD_TBL_ITEM(
- mdc, 4, CTBL_REPEAT, do_mem_mdc,
+ mdc, 4, CTBL_RPT, do_mem_mdc,
"memory display cyclic",
"address count delay(ms)"
),
CMD_TBL_ITEM(
"memory display cyclic",
"address count delay(ms)"
),
CMD_TBL_ITEM(
- mwc, CONFIG_SYS_MAXARGS, CTBL_REPEAT, do_mem_mdc,
+ mwc, CONFIG_SYS_MAXARGS, CTBL_RPT, do_mem_mdc,
"memory write cyclic",
"[-bwl] address value delay(ms)\n"
" -b write value as byte (8 bit, default)\n"
"memory write cyclic",
"[-bwl] address value delay(ms)\n"
" -b write value as byte (8 bit, default)\n"
- attach, CONFIG_SYS_MAXARGS, CTBL_REPEAT, do_attach,
+ attach, CONFIG_SYS_MAXARGS, CTBL_RPT, do_attach,
"attach filesystem image file to CP/M drive",
"[-rw] [-o options] dsk<n> diskfile\n"
" Attach diskfile to dsk<n>, where n in 0..7\n"
"attach filesystem image file to CP/M drive",
"[-rw] [-o options] dsk<n> diskfile\n"
" Attach diskfile to dsk<n>, where n in 0..7\n"
" Without arguments, list current assignments"
),
CMD_TBL_ITEM(
" Without arguments, list current assignments"
),
CMD_TBL_ITEM(
- detach, 2, CTBL_REPEAT, do_attach,
+ detach, 2, 0, do_attach,
"detach file from CP/M drive",
"dsk<n>]\n"
" - alias for 'attach -d dsk<n>'"
),
CMD_TBL_ITEM(
"detach file from CP/M drive",
"dsk<n>]\n"
" - alias for 'attach -d dsk<n>'"
),
CMD_TBL_ITEM(
- help, CONFIG_SYS_MAXARGS, CTBL_REPEAT, do_help,
+ help, CONFIG_SYS_MAXARGS, 0, do_help,
"print command description/usage",
"\n"
" - print brief description of all commands\n"
"print command description/usage",
"\n"
" - print brief description of all commands\n"
/*
* Flags for command table:
*/
/*
* Flags for command table:
*/
-#define CTBL_REPEAT 0x01 /* command is repeatable */
+#define CTBL_RPT 0x01 /* command is repeatable */
#define CTBL_SUBCMD 0x02 /* command has subcommands */
#define CTBL_SUBCMD 0x02 /* command has subcommands */
-#define CTBL_SUBCMDAUTO 0x04 /* execute subcommands whithout prefix*/
+#define CTBL_SUBCMDAUTO 0x04 /* execute subcommands whithout prefix */
+#define CTBL_DBG 0x08 /* command is only for debugging */
#ifdef CONFIG_AUTO_COMPLETE
# define _CMD_COMPLETE(x) x,
#ifdef CONFIG_AUTO_COMPLETE
# define _CMD_COMPLETE(x) x,