]> git.sur5r.net Git - openocd/commitdiff
improve command handling examples
authorZachary T Welch <zw@superlucidity.net>
Sun, 22 Nov 2009 03:27:20 +0000 (19:27 -0800)
committerZachary T Welch <zw@superlucidity.net>
Wed, 25 Nov 2009 18:29:05 +0000 (10:29 -0800)
Removes hello and foo commands from top-level registration.  Instead,
the dummy interface driver and faux flash driver have been augmented
to register these commands as sub-commands.

src/flash/faux.c
src/hello.c
src/hello.h [new file with mode: 0644]
src/jtag/dummy.c
src/openocd.c

index adfc7bd3e79b038f62111a83cd472d38e1f39cea..caec2c791f39d7350facf10aecb4bf351fc2da66 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "flash.h"
 #include "image.h"
+#include "../hello.h"
 
 
 struct faux_flash_bank
@@ -123,8 +124,19 @@ static int faux_probe(struct flash_bank *bank)
        return ERROR_OK;
 }
 
+static const struct command_registration faux_command_handlers[] = {
+       {
+               .name = "faux",
+               .mode = COMMAND_ANY,
+               .help = "faux flash command group",
+               .chain = hello_command_handlers,
+       },
+       COMMAND_REGISTRATION_DONE
+};
+
 struct flash_driver faux_flash = {
                .name = "faux",
+               .commands = faux_command_handlers,
                .flash_bank_command = &faux_flash_bank_command,
                .erase = &faux_erase,
                .protect = &faux_protect,
index 9a1bf92520349366206ae43f43c8e41ce717a9c1..2e5c9289c19d08842f149f8e3756b5bf8b2d38f6 100644 (file)
@@ -101,7 +101,7 @@ COMMAND_HANDLER(handle_hello_command)
        return retval;
 }
 
-static const struct command_registration hello_command_handlers[] = {
+const struct command_registration hello_command_handlers[] = {
        {
                .name = "hello",
                .handler = &handle_hello_command,
diff --git a/src/hello.h b/src/hello.h
new file mode 100644 (file)
index 0000000..fc674ad
--- /dev/null
@@ -0,0 +1,35 @@
+/***************************************************************************
+ *   Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net>             *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef OPENOCD_HELLO_H
+#define OPENOCD_HELLO_H
+
+struct command_context;
+struct command_registration;
+
+/// Register the hello commands in the specified command_context
+int hello_register_commands(struct command_context *cmd_ctx);
+
+/**
+ * Export the registration for the hello command group, so it can be
+ * embedded in example drivers.
+ */
+extern const struct command_registration hello_command_handlers[];
+
+#endif // OPENOCD_HELLO_H
index 11b6f71ae10fa4223c954d3a0a43cee8db3a59d3..c2beb0920cf73dea443eaefc2562b4023657bd9d 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "interface.h"
 #include "bitbang.h"
+#include "../hello.h"
 
 
 /* my private tap controller state, which tracks state for calling code */
@@ -146,12 +147,25 @@ static int dummy_quit(void)
        return ERROR_OK;
 }
 
+static const struct command_registration dummy_command_handlers[] = {
+       {
+               .name = "dummy",
+               .mode = COMMAND_ANY,
+               .help = "dummy interface driver commands",
+
+               .chain = hello_command_handlers,
+       },
+       COMMAND_REGISTRATION_DONE,
+};
+
 /* The dummy driver is used to easily check the code path
  * where the target is unresponsive.
  */
 struct jtag_interface dummy_interface = {
                .name = "dummy",
 
+               .commands = dummy_command_handlers,
+
                .execute_queue = &bitbang_execute_queue,
 
                .speed = &dummy_speed,
index e38c84ecc663e6bed7c436660ac1907faaa6e596..1f29acdb5b3a1e825adfce053901db9d1fda38cf 100644 (file)
@@ -179,9 +179,6 @@ static const struct command_registration openocd_command_handlers[] = {
 
 struct command_context *global_cmd_ctx;
 
-/// src/hello.c gives a simple example for writing new command modules
-int hello_register_commands(struct command_context *cmd_ctx);
-
 /* NB! this fn can be invoked outside this file for non PC hosted builds */
 struct command_context *setup_command_handler(void)
 {
@@ -191,7 +188,6 @@ struct command_context *setup_command_handler(void)
 
        register_commands(cmd_ctx, NULL, openocd_command_handlers);
        /* register subsystem commands */
-       hello_register_commands(cmd_ctx);
        server_register_commands(cmd_ctx);
        telnet_register_commands(cmd_ctx);
        gdb_register_commands(cmd_ctx);