improve command handling examples
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.__archive__
parent
d89c631014
commit
a93b404161
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue