]> cloudbase.mooo.com Git - z180-stamp.git/blame - avr/command_tbl.c
Call subcommands from main command processor
[z180-stamp.git] / avr / command_tbl.c
CommitLineData
35edb766 1/*
04b3ea0e 2 * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
35edb766 3 *
b51d2360 4 * SPDX-License-Identifier: GPL-2.0
35edb766 5 */
d684c216
L
6
7#include "common.h"
d684c216 8#include "command.h"
72f58822 9#include "cmd_mem.h"
d684c216 10
fcf1d5b3
L
11extern command_ret_t do_help(cmd_tbl_t *, uint_fast8_t, int, char * const []);
12extern command_ret_t do_echo(cmd_tbl_t *, uint_fast8_t, int, char * const []);
13extern command_ret_t do_sleep(cmd_tbl_t *, uint_fast8_t, int, char * const []);
14extern command_ret_t do_env_print(cmd_tbl_t *, uint_fast8_t, int, char * const []);
15extern command_ret_t do_env_default(cmd_tbl_t *, uint_fast8_t, int, char * const []);
16extern command_ret_t do_env_set(cmd_tbl_t *, uint_fast8_t, int, char * const []);
17extern command_ret_t do_env_save(cmd_tbl_t *, uint_fast8_t, int, char * const []);
18extern command_ret_t do_loadf(cmd_tbl_t *, uint_fast8_t, int, char * const []);
19extern command_ret_t do_bootcf(cmd_tbl_t *, uint_fast8_t, int, char * const []);
20extern command_ret_t do_loadcpm3(cmd_tbl_t *, uint_fast8_t, int, char * const []);
21extern command_ret_t do_loadihex(cmd_tbl_t *, uint_fast8_t, int, char * const []);
393b1897 22#if defined(CONFIG_CMD_LOADB)
fcf1d5b3 23extern command_ret_t do_load_serial_bin(cmd_tbl_t *, uint_fast8_t, int, char * const []);
393b1897 24#endif
fcf1d5b3
L
25extern command_ret_t do_go(cmd_tbl_t *, uint_fast8_t, int, char * const []);
26extern command_ret_t do_restart(cmd_tbl_t *, uint_fast8_t, int, char * const []);
27extern command_ret_t do_console(cmd_tbl_t *, uint_fast8_t, int, char * const []);
28extern command_ret_t do_dump_mem(cmd_tbl_t *, uint_fast8_t, int, char * const []);
29extern command_ret_t do_mem_mm_avr(cmd_tbl_t *, uint_fast8_t, int, char * const []);
30extern command_ret_t do_mem_nm_avr(cmd_tbl_t *, uint_fast8_t, int, char * const []);
31extern command_ret_t do_eep_cp(cmd_tbl_t *, uint_fast8_t, int, char * const []);
32extern command_ret_t do_busreq_pulse(cmd_tbl_t *, uint_fast8_t, int, char * const []);
33extern command_ret_t do_date(cmd_tbl_t *, uint_fast8_t, int, char * const []);
34extern command_ret_t do_gpio(cmd_tbl_t *, uint_fast8_t, int, char * const []);
35extern command_ret_t do_sd(cmd_tbl_t *, uint_fast8_t, int, char * const []);
36extern command_ret_t do_fat(cmd_tbl_t *, uint_fast8_t, int, char * const []);
37extern command_ret_t do_run(cmd_tbl_t *, uint_fast8_t, int, char * const []);
38extern command_ret_t do_source(cmd_tbl_t *, uint_fast8_t, int, char * const []);
39extern command_ret_t do_attach(cmd_tbl_t *, uint_fast8_t, int, char * const []);
40extern command_ret_t do_pr_free_avr(cmd_tbl_t *, uint_fast8_t, int, char * const []);
05994bd9 41
8da60ec5
L
42extern cmd_tbl_t cmd_tbl_fat[];
43extern cmd_tbl_t cmd_tbl_sd[];
d684c216
L
44
45cmd_tbl_t cmd_tbl[] = {
46
61b0cfe9
L
47CMD_TBL_ITEM(
48 date, 2, 1, do_date,
a036b05f 49 "get/set date & time",
85046f8c 50 "[MMDDhhmm[[CC]YY][.ss]]\n"
61b0cfe9
L
51 " - without arguments: print date & time\n"
52 " - with numeric argument: set the system date & time\n"
61b0cfe9
L
53),
54
323398b1 55#ifdef DEBUG
4565be9a 56
323398b1 57CMD_TBL_ITEM(
f338df2a
L
58 !mdr, 3, 1, do_dump_mem,
59 "RAM dump",
60 "address [count]"
61),
62CMD_TBL_ITEM(
63 !mde, 3, 1, do_dump_mem,
323398b1
L
64 "EEPROM dump",
65 "address [count]"
66),
c748023e
L
67CMD_TBL_ITEM(
68 !mdf, 3, 1, do_dump_mem,
69 "FLASH dump",
70 "address [count]"
71),
323398b1 72CMD_TBL_ITEM(
f338df2a 73 !cpe, 4, 0, do_eep_cp,
323398b1
L
74 "EEPROM copy",
75 "source target count"
76),
ad9bc17c
L
77CMD_TBL_ITEM(
78 !mm, 2, 1, do_mem_mm_avr,
79 "avr memory modify (auto-incrementing address)",
80 "address"
81),
82CMD_TBL_ITEM(
83 !nm, 2, 1, do_mem_nm_avr,
84 "avr memory modify (constant address)",
85 "address"
86),
fb9b17a9
L
87CMD_TBL_ITEM(
88 !prfree, 2, 1, do_pr_free_avr,
89 "print avr heap free list",
90 "address"
91),
323398b1 92#endif
f338df2a
L
93CMD_TBL_ITEM(
94 mstep, 2, 1, do_busreq_pulse,
95 "execute one M cycle",
96 "[count]\n"
97 " - repeat count times"
98),
d684c216
L
99CMD_TBL_ITEM(
100 echo, CONFIG_SYS_MAXARGS, 1, do_echo,
bbd45c46
L
101 "display a line of text",
102 "[-n] [argument ...]\n"
32154e5a
L
103 "- echo the argument(s) to console.\n"
104 " -n do not output the trailing newline"
d684c216 105),
8a7decea
L
106CMD_TBL_ITEM(
107 sleep , 2, 1, do_sleep,
108 "delay execution for some time",
109 "N[m][s]\n"
110 " - delay execution for decimal N (milli) seconds"
111),
d684c216
L
112CMD_TBL_ITEM_COMPLETE(
113 run, CONFIG_SYS_MAXARGS, 1, do_run,
114 "run commands in an environment variable",
115 "var [...]\n"
116 " - run the commands in the environment variable(s) 'var'",
117 var_complete
118),
04b3ea0e
L
119CMD_TBL_ITEM_COMPLETE(
120 source, CONFIG_SYS_MAXARGS, 1, do_source,
121 "run commands from a file",
122 "filename\n"
123 " - run the commands in the script file 'filename'",
124 var_complete
125),
d684c216
L
126CMD_TBL_ITEM_COMPLETE(
127 printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
128 "print environment variables",
8eb73d17
L
129 "[-s] [name ...]\n"
130 " Print value of environment variable(s) 'name'\n"
131 " If no names are given, print values of all environment variables\n"
132 " -s Print in setenv form",
d684c216
L
133 var_complete
134),
135CMD_TBL_ITEM_COMPLETE(
136 setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
137 "set environment variables",
72f58822
L
138 "name value ...\n"
139 " - set environment variable 'name' to 'value ...'\n"
140 "setenv name\n"
141 " - delete environment variable 'name'",
d684c216
L
142 var_complete
143),
323398b1
L
144CMD_TBL_ITEM(
145 saveenv, 1, 0, do_env_save,
146 "save environment variables to persistent storage",
147 ""
148),
7e24905c
L
149CMD_TBL_ITEM(
150 defaultenv, 1, 0, do_env_default,
151 "set all environment variables to their default values",
152 ""
153),
72f58822 154
534e1dfc 155CMD_TBL_ITEM(
323398b1 156 loadf, 1, 0, do_loadf,
534e1dfc
L
157 "load srec_cat prepared image from controller flash",
158 ""
159),
a2907f2e
L
160CMD_TBL_ITEM(
161 bootcf, CONFIG_SYS_MAXARGS, 0, do_bootcf,
162 "boot from cf card",
163 "[options]\n"
164 " Load a number of sectors from the first CP/M partition and jump to\n"
165 " the load address.\n"
166 " -a ADDRESS\n"
167 " Load and start address (default 100 hex)\n"
168 " -s NUM\n"
169 " First sector of partition to load (0..255, default 0)\n"
170 " -c NUM\n"
171 " Number of sectors to load (1..127, default 7)\n"
172 " -i NUM\n"
173 " Partition type to look for (default 52 hex)\n"
174 " -n\n"
175 " Load only, do not execute\n"
176 " -t NUM\n"
177 " Timeout for IDE commands (1..65535, default 10000)\n"
178 " -v verbose\n"
179 " TODO: be verbose"
180),
c0abd68b
L
181CMD_TBL_ITEM(
182 loadcpm3, 3, 0, do_loadcpm3,
183 "load CPM3.SYS file",
98aac4d0 184 "[filename [common-base [banked-base]]] \n"
fa84c3ba
L
185 " - Load CP/M 3 system file from FAT filesystem. This command makes\n"
186 " CPMLDR superfluous. Uses the following environment variables if set:\n"
b51d2360
L
187 " '"ENV_CPM3_SYSFILE"' File to load. Default is '"CONFIG_CPM3_SYSFILE"'.\n"
188 " '"ENV_CPM3_BANKED_BASE"' Default is '"CONFIG_CPM3_BANKED_BASE_STR"'.\n"
189 " Sets the following environment variables after loading:\n"
190 " '"ENV_CPM3_COMMON_BASE"'\n"
191 " '"ENV_STARTADDRESS"'"
c0abd68b 192),
179bc609
L
193CMD_TBL_ITEM(
194 loadi, 2, 0, do_loadihex,
bf587043
L
195 "load intel hex file over serial line",
196 "[[-]offset]\n"
197 " - load Intel-Hex-Record file over serial line with offset 'offset'"
179bc609 198),
393b1897
L
199
200#if defined(CONFIG_CMD_LOADB)
201CMD_TBL_ITEM(
202 loadb, 1, 0, do_load_serial_bin,
203 "load binary file over serial line (kermit mode)",
204 " - load binary file over serial line"
205),
206
207CMD_TBL_ITEM(
208 loadx, 1, 0, do_load_serial_bin,
209 "load binary file over serial line (xmodem mode)",
210 " - load binary file over serial line"
211),
212
213CMD_TBL_ITEM(
214 loady, 1, 0, do_load_serial_bin,
215 "load binary file over serial line (ymodem mode)",
216 " - load binary file over serial line"
217),
218#endif /* CONFIG_CMD_LOADB */
219
534e1dfc 220CMD_TBL_ITEM(
323398b1 221 go, 2, 0, do_go,
534e1dfc
L
222 "start application at address 'addr'",
223 "addr\n"
224 " - start application at address 'addr'"
225// "\n"
226// " passing 'arg' as arguments"
227),
228CMD_TBL_ITEM(
323398b1 229 reset, 1, 0, do_reset,
534e1dfc
L
230 "Keep CPU in RESET state",
231 ""
232),
233CMD_TBL_ITEM(
89adce76 234 restart, 1, 1, do_restart,
534e1dfc
L
235 "Perform RESET of the CPU",
236 ""
237),
89adce76 238CMD_TBL_ITEM(
2fe44122 239 connect, 1, 0, do_console,
89adce76 240 "Connect to CPU console i/o",
98aac4d0
L
241 "\n"
242 " - type the escape character followed by Q to close the connection, \n"
243 " or followed by ? to see other options. The default escape character \n"
244 " is Ctrl-^ (0x1E). It can be changed by setting env var '"ENV_ESC_CHAR"'."
245
89adce76 246),
41d36f28 247
41d36f28 248CMD_TBL_ITEM(
05994bd9 249 pin, CONFIG_SYS_MAXARGS, 1, do_gpio,
cd5ee544
L
250 "Set or query pin state",
251 "[-s] [<pins>]\n"
41d36f28
L
252 " - print cofiguration and state or frequency of pins\n"
253 " print all pins, if argument is omitted\n"
cd5ee544 254 "pin <pins> h[igh]|l[ow]\n"
41d36f28 255 " - config pins as output and set to level high or low\n"
cd5ee544 256 "pin <pins> ts|i[n]|p[ullup]\n"
41d36f28 257 " - config pins as input/tristate or input with pullup\n"
cd5ee544 258 "pin <pins> value[K|M][Hz]\n"
41d36f28
L
259 " - output a clock on pins\n"
260 " value is system clock divider or frequency, if 'Hz' is appended\n"
261 " divider is rounded down to next possible value (depends on pin)\n"
262 "\n"
cd5ee544 263 "<pins> is a comma separated list of numbers or ranges, i.e. \"0,9,3-6\"\n"
6035a17b 264),
534e1dfc 265
72f58822 266CMD_TBL_ITEM(
fcf1d5b3 267 md, 3, CTBL_REPEAT, do_mem_md,
72f58822
L
268 "memory display",
269 "address [# of objects]"
270),
271CMD_TBL_ITEM(
fcf1d5b3 272 mm, 2, CTBL_REPEAT, do_mem_mm,
72f58822
L
273 "memory modify (auto-incrementing address)",
274 "address"
275),
276CMD_TBL_ITEM(
fcf1d5b3 277 nm, 2, CTBL_REPEAT, do_mem_nm,
72f58822
L
278 "memory modify (constant address)",
279 "address"
280),
281CMD_TBL_ITEM(
fcf1d5b3 282 mw, CONFIG_SYS_MAXARGS, CTBL_REPEAT, do_mem_mw,
72f58822 283 "memory write (fill)",
32154e5a
L
284 "[-bwl] address value [count]\n"
285 " -b write value as byte (8 bit, default)\n"
286 " -w write value as word (16 bit)\n"
fcd2239e 287 " -l write value as long (32 bit)"
72f58822
L
288),
289CMD_TBL_ITEM(
fcf1d5b3 290 cp, 4, CTBL_REPEAT, do_mem_cp,
72f58822
L
291 "memory copy",
292 "source target count"
293),
294CMD_TBL_ITEM(
fcf1d5b3 295 cmp, 4, CTBL_REPEAT, do_mem_cmp,
72f58822
L
296 "memory compare",
297 "addr1 addr2 count"
298),
299CMD_TBL_ITEM(
c79c80b4 300 base, 2, 0, do_mem_base,
72f58822
L
301 "print or set address offset",
302 "\n"
303 " - print address offset for memory commands\n"
304 "base offset\n"
305 " - set address offset for memory commands to 'offset'"
306),
307CMD_TBL_ITEM(
fcf1d5b3 308 mloop, 3, CTBL_REPEAT, do_mem_loop,
72f58822
L
309 "infinite loop on address range",
310 "address number_of_bytes"
311),
72f58822 312CMD_TBL_ITEM(
fcf1d5b3 313 mloopw, 4, CTBL_REPEAT, do_mem_loopw,
72f58822
L
314 "infinite write loop on address range",
315 "address number_of_bytes data_to_write"
316),
72f58822
L
317
318#ifdef CONFIG_CMD_MEMTEST
319CMD_TBL_ITEM(
fcf1d5b3 320 mtest, 4, CTBL_REPEAT, do_mem_mtest,
72f58822 321 "simple RAM read/write test",
5480dc65 322 "[start [end [iterations]]]"
72f58822
L
323),
324#endif /* CONFIG_CMD_MEMTEST */
325
326#ifdef CONFIG_MX_CYCLIC
327CMD_TBL_ITEM(
fcf1d5b3 328 mdc, 4, CTBL_REPEAT, do_mem_mdc,
72f58822
L
329 "memory display cyclic",
330 "address count delay(ms)"
331),
332CMD_TBL_ITEM(
fcf1d5b3 333 mwc, CONFIG_SYS_MAXARGS, CTBL_REPEAT, do_mem_mdc,
72f58822 334 "memory write cyclic",
fcd2239e
L
335 "[-bwl] address value delay(ms)\n"
336 " -b write value as byte (8 bit, default)\n"
337 " -w write value as word (16 bit)\n"
338 " -l write value as long (32 bit)"
72f58822
L
339),
340#endif /* CONFIG_MX_CYCLIC */
341
8da60ec5 342CMD_TBL_ITEM_TOP(
7f552300
L
343 sd, CONFIG_SYS_MAXARGS, 1, do_sd,
344 "SD/MMC card handling commands",
345 "<subcommand> args ...\n"
346 "sd help\n"
8da60ec5
L
347 " - print help on subcommands",
348 cmd_tbl_sd
7f552300 349),
8da60ec5 350CMD_TBL_ITEM_TOP(
8a2b0da0
L
351 fat, CONFIG_SYS_MAXARGS, 1, do_fat,
352 "fat filesystem commands",
353 "<subcommand> args ...\n"
354 "fat help\n"
8da60ec5
L
355 " - print help on subcommands",
356 cmd_tbl_fat
2f53dd65 357),
8a2b0da0 358
cb4fb1ed 359CMD_TBL_ITEM(
fcf1d5b3 360 attach, CONFIG_SYS_MAXARGS, CTBL_REPEAT, do_attach,
cb4fb1ed 361 "attach filesystem image file to CP/M drive",
96798b2c
L
362 "[-rw] [-o options] dsk<n> diskfile\n"
363 " Attach diskfile to dsk<n>, where n in 0..7\n"
364 " -r File is read only (write protected)\n"
365 " -w File is read/write (default)\n"
366 " -o options\n"
367 " Options is a comma-separated list of\n"
368 " ro, rw, debug, nodebug\n"
369 "\n"
370 "attach [-rw] -o reattach[,other options] dsk<n>\n"
371 " Change options for dsk<n>.\n"
372 " Options as above.\n"
373 "\n"
374 "attach -d -a|dsk<n>\n"
375 "detach -a|dsk<n>\n"
376 " Detach diskfile from dsk<n>.\n"
377 " -a Detach all.\n"
378 "\n"
cb4fb1ed 379 "attach\n"
8da60ec5 380 " Without arguments, list current assignments"
cb4fb1ed
L
381),
382CMD_TBL_ITEM(
fcf1d5b3 383 detach, 2, CTBL_REPEAT, do_attach,
cb4fb1ed
L
384 "detach file from CP/M drive",
385 "dsk<n>]\n"
a2907f2e 386 " - alias for 'attach -d dsk<n>'"
cb4fb1ed 387),
2f53dd65 388
d684c216 389CMD_TBL_ITEM(
fcf1d5b3 390 help, CONFIG_SYS_MAXARGS, CTBL_REPEAT, do_help,
d684c216
L
391 "print command description/usage",
392 "\n"
393 " - print brief description of all commands\n"
394 "help command ...\n"
395 " - print detailed usage of 'command'"
396),
397
72f58822 398/* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
d684c216
L
399 {FSTR("?"), CONFIG_SYS_MAXARGS, 1, do_help,
400 FSTR("alias for 'help'"),
401#ifdef CONFIG_SYS_LONGHELP
402 FSTR(""),
403#endif /* CONFIG_SYS_LONGHELP */
8da60ec5 404 NULL,
d684c216 405#ifdef CONFIG_AUTO_COMPLETE
8da60ec5 406 NULL,
d684c216
L
407#endif
408},
409/* Mark end of table */
410{ 0 },
411};