stm32f1x: fix bug in flash loader and restrict instruction set to armv6-m
[openocd/andreasf.git] / src / hello.c
blob6584aa20db612dcca11c774f97ee5112f6651e40
1 /***************************************************************************
2 * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <helper/log.h>
25 COMMAND_HANDLER(handle_foo_command)
27 if (CMD_ARGC < 1 || CMD_ARGC > 2)
29 return ERROR_COMMAND_SYNTAX_ERROR;
32 uint32_t address;
33 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
35 const char *msg = "<unchanged>";
36 if (CMD_ARGC == 2)
38 bool enable;
39 COMMAND_PARSE_ENABLE(CMD_ARGV[1], enable);
40 msg = enable ? "enable" : "disable";
43 LOG_INFO("%s: address=0x%8.8" PRIx32 " enabled=%s", CMD_NAME, address, msg);
44 return ERROR_OK;
47 static bool foo_flag;
49 COMMAND_HANDLER(handle_flag_command)
51 return CALL_COMMAND_HANDLER(handle_command_parse_bool,
52 &foo_flag, "foo flag");
55 static const struct command_registration foo_command_handlers[] = {
57 .name = "bar",
58 .handler = &handle_foo_command,
59 .mode = COMMAND_ANY,
60 .usage = "address ['enable'|'disable']",
61 .help = "an example command",
64 .name = "baz",
65 .handler = &handle_foo_command,
66 .mode = COMMAND_ANY,
67 .usage = "address ['enable'|'disable']",
68 .help = "a sample command",
71 .name = "flag",
72 .handler = &handle_flag_command,
73 .mode = COMMAND_ANY,
74 .usage = "[on|off]",
75 .help = "set a flag",
77 COMMAND_REGISTRATION_DONE
80 static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
82 if (CMD_ARGC > 1)
84 return ERROR_COMMAND_SYNTAX_ERROR;
86 if (1 == CMD_ARGC)
88 *sep = " ";
89 *name = CMD_ARGV[0];
91 else
92 *sep = *name = "";
94 return ERROR_OK;
96 COMMAND_HANDLER(handle_hello_command)
98 const char *sep, *name;
99 int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name);
100 if (ERROR_OK == retval)
101 command_print(CMD_CTX, "Greetings%s%s!", sep, name);
102 return retval;
105 const struct command_registration hello_command_handlers[] = {
107 .name = "hello",
108 .handler = handle_hello_command,
109 .mode = COMMAND_ANY,
110 .help = "prints a warm welcome",
111 .usage = "[name]",
114 .name = "foo",
115 .mode = COMMAND_ANY,
116 .help = "example command handler skeleton",
118 .chain = foo_command_handlers,
120 COMMAND_REGISTRATION_DONE