summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-05-30 22:23:12 +0000
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-05-30 22:23:12 +0000
commit335fee3f36bd491197f8bd987baa6a7390f1750d (patch)
tree8efc24cf843d20c90ba35e720693feb9e147deb5
parent77015d5ae35cebea28b7f6be80e3ea83f4a07f06 (diff)
downloadopenocd+libswd-335fee3f36bd491197f8bd987baa6a7390f1750d.tar.gz
openocd+libswd-335fee3f36bd491197f8bd987baa6a7390f1750d.tar.bz2
openocd+libswd-335fee3f36bd491197f8bd987baa6a7390f1750d.tar.xz
openocd+libswd-335fee3f36bd491197f8bd987baa6a7390f1750d.zip
Encapsulate the global "jtag" jtag_interface pointer:
- Add jtag_interface_quit, factored from exit_handler() in openocd.c. - Remove its extern declaration. - Add static keyword to its definition. git-svn-id: svn://svn.berlios.de/openocd/trunk@1952 b42882b7-edfa-0310-969c-e2dbd0fdcd60
-rw-r--r--src/jtag/jtag.c16
-rw-r--r--src/jtag/jtag.h5
-rw-r--r--src/openocd.c4
3 files changed, 19 insertions, 6 deletions
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index ecd4931a..c9167f41 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -227,7 +227,7 @@ jtag_interface_t *jtag_interfaces[] = {
NULL,
};
-jtag_interface_t *jtag = NULL;
+static jtag_interface_t *jtag = NULL;
/* configuration */
static jtag_interface_t *jtag_interface = NULL;
@@ -2407,6 +2407,20 @@ static int jtag_init_inner(struct command_context_s *cmd_ctx)
return ERROR_OK;
}
+int jtag_interface_quit(void)
+{
+ if (!jtag || !jtag->quit)
+ return ERROR_OK;
+
+ // close the JTAG interface
+ int result = jtag->quit();
+ if (ERROR_OK != result)
+ LOG_ERROR("failed: %d", result);
+
+ return ERROR_OK;
+}
+
+
int jtag_init_reset(struct command_context_s *cmd_ctx)
{
int retval;
diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h
index af4c64da..00a7bc83 100644
--- a/src/jtag/jtag.h
+++ b/src/jtag/jtag.h
@@ -512,8 +512,6 @@ typedef struct jtag_event_callback_s
extern jtag_event_callback_t* jtag_event_callbacks;
-extern jtag_interface_t* jtag; /* global pointer to configured JTAG interface */
-
extern int jtag_speed;
extern int jtag_speed_post_reset;
@@ -535,6 +533,9 @@ extern enum reset_types jtag_reset_config;
*/
extern int jtag_interface_init(struct command_context_s* cmd_ctx);
+/// Shutdown the JTAG interface upon program exit.
+extern int jtag_interface_quit(void);
+
/* initialize JTAG chain using only a RESET reset. If init fails,
* try reset + init.
*/
diff --git a/src/openocd.c b/src/openocd.c
index 65664464..026a32b3 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -79,9 +79,7 @@ static int handle_version_command(struct command_context_s *cmd_ctx, char *cmd,
static void exit_handler(void)
{
- /* close JTAG interface */
- if (jtag && jtag->quit)
- jtag->quit();
+ jtag_interface_quit();
}
static int log_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv)