]> cloudbase.mooo.com Git - z180-stamp.git/blame - avr/command.h
New U-Boot like AVR main program.
[z180-stamp.git] / avr / command.h
CommitLineData
d684c216
L
1
2/*
3 * Definitions for Command Processor
4 */
5#ifndef __COMMAND_H
6#define __COMMAND_H
7
8#include "common.h"
9#include "config.h"
10
11#ifndef NULL
12#define NULL 0
13#endif
14
15/* Default to a width of 8 characters for help message command width */
16#ifndef CONFIG_SYS_HELP_CMD_WIDTH
17#define CONFIG_SYS_HELP_CMD_WIDTH 8
18#endif
19
20/*
21 * Monitor Command Table
22 */
23
24struct cmd_tbl_s {
25 const FLASH char *name; /* Command Name */
26 int maxargs; /* maximum number of arguments */
27 int repeatable; /* autorepeat allowed? */
28 /* Implementation function */
29 int (*cmd)(const FLASH struct cmd_tbl_s *, int, int, char * const []);
30 const FLASH char *usage; /* Usage message (short) */
31#ifdef CONFIG_SYS_LONGHELP
32 const FLASH char *help; /* Help message (long) */
33#endif
34#ifdef CONFIG_AUTO_COMPLETE
35 /* do auto completion on the arguments */
36 int (*complete)(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);
37#endif
38};
39
40typedef const FLASH struct cmd_tbl_s cmd_tbl_t;
41
42extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
43
44/* command.c */
45int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
46 flag, int argc, char * const argv[]);
47cmd_tbl_t *find_cmd(const char *cmd);
48cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
49
50int cmd_tbl_item_count(void);
51int cmd_usage(cmd_tbl_t *cmdtp);
52
53#ifdef CONFIG_AUTO_COMPLETE
54extern int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]);
55extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp);
56#endif
57
58/**
59 * cmd_process_error() - report and process a possible error
60 *
61 * @cmdtp: Command which caused the error
62 * @err: Error code (0 if none, -ve for error, like -EIO)
63 * @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found
64 */
65int cmd_process_error(cmd_tbl_t *cmdtp, int err);
66
67/*
68 * Monitor Command
69 *
70 * All commands use a common argument format:
71 *
72 * void function (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
73 */
74
75
76#ifdef CONFIG_CMD_BOOTD
77extern int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
78#endif
79#ifdef CONFIG_CMD_BOOTM
80extern int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
81extern int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd);
82#else
83static inline int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
84{
85 (void) cmdtp; (void) cmd;
86
87 return 0;
88}
89#endif
90
91extern int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
92 char *const argv[]);
93
94extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
95
96/*
97 * Error codes that commands return to cmd_process(). We use the standard 0
98 * and 1 for success and failure, but add one more case - failure with a
99 * request to call cmd_usage(). But the cmd_process() function handles
100 * CMD_RET_USAGE itself and after calling cmd_usage() it will return 1.
101 * This is just a convenience for commands to avoid them having to call
102 * cmd_usage() all over the place.
103 */
104enum command_ret_t {
105 CMD_RET_SUCCESS, /* 0 = Success */
106 CMD_RET_FAILURE, /* 1 = Failure */
107 CMD_RET_USAGE = -1, /* Failure, please report 'usage' error */
108};
109
110/**
111 * Process a command with arguments. We look up the command and execute it
112 * if valid. Otherwise we print a usage message.
113 *
114 * @param flag Some flags normally 0 (see CMD_FLAG_.. above)
115 * @param argc Number of arguments (arg 0 must be the command text)
116 * @param argv Arguments
117 * @param repeatable This function sets this to 0 if the command is not
118 * repeatable. If the command is repeatable, the value
119 * is left unchanged.
120 * @return 0 if the command succeeded, 1 if it failed
121 */
122int cmd_process(int flag, int argc, char * const argv[], uint_fast8_t *repeatable);
123
124
125/*
126 * Command Flags:
127 */
128#define CMD_FLAG_REPEAT 0x0001 /* repeat last command */
129#define CMD_FLAG_BOOTD 0x0002 /* command is from bootd */
130
131#ifdef CONFIG_AUTO_COMPLETE
132# define _CMD_COMPLETE(x) x,
133#else
134# define _CMD_COMPLETE(x)
135#endif
136#ifdef CONFIG_SYS_LONGHELP
137# define _CMD_HELP(x) x,
138#else
139# define _CMD_HELP(x)
140#endif
141
142
143#define CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd, \
144 _usage, _help, _comp) \
145 { FSTR(#_name), _maxargs, _rep, _cmd, FSTR(_usage), \
146 _CMD_HELP(FSTR(_help)) _CMD_COMPLETE(_comp) }
147
148#define CMD_TBL_ITEM(_name, _maxargs, _rep, _cmd, _usage, _help) \
149 CMD_TBL_ITEM_COMPLETE(_name, _maxargs, _rep, _cmd, \
150 _usage, _help, NULL)
151
152typedef int (*do_cmd_t)(cmd_tbl_t *, int, int, char * const []);
153
154extern cmd_tbl_t cmd_tbl[];
155
156
157#endif /* __COMMAND_H */