Hi all, The following patch encapsulates the global JTAG interface pointer, adding a wrapper routine for the only out-of-module user.
I will apply unless there are objections. Cheers, Zach ====== 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. --- jtag/jtag.c | 16 +++++++++++++++- jtag/jtag.h | 5 +++-- openocd.c | 4 +--- 3 files changed, 19 insertions(+), 6 deletions(-) --- Index: src/jtag/jtag.c =================================================================== --- src/jtag/jtag.c (revision 1942) +++ src/jtag/jtag.c (working copy) @@ -227,7 +227,7 @@ NULL, }; -jtag_interface_t *jtag = NULL; +static jtag_interface_t *jtag = NULL; /* configuration */ static jtag_interface_t *jtag_interface = NULL; @@ -2407,6 +2407,20 @@ 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; Index: src/jtag/jtag.h =================================================================== --- src/jtag/jtag.h (revision 1942) +++ src/jtag/jtag.h (working copy) @@ -515,8 +515,6 @@ 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; @@ -538,6 +536,9 @@ */ 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. */ Index: src/openocd.c =================================================================== --- src/openocd.c (revision 1942) +++ src/openocd.c (working copy) @@ -79,9 +79,7 @@ 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) _______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development