diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jtag/core.c | 29 | ||||
-rw-r--r-- | src/jtag/jtag.h | 9 | ||||
-rw-r--r-- | src/jtag/tcl.c | 32 |
3 files changed, 44 insertions, 26 deletions
diff --git a/src/jtag/core.c b/src/jtag/core.c index 4d4d278..2786650 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -103,7 +103,7 @@ static int speed_khz = 0; static bool hasKHz = false; static int jtag_speed = 0; -struct jtag_interface_s *jtag = NULL; +static struct jtag_interface_s *jtag = NULL; /* configuration */ jtag_interface_t *jtag_interface = NULL; @@ -1178,6 +1178,27 @@ unsigned jtag_get_speed_khz(void) { return speed_khz; } +int jtag_config_khz(unsigned khz) +{ + LOG_DEBUG("handle jtag khz"); + jtag_set_speed_khz(khz); + + int cur_speed = 0; + if (jtag != NULL) + { + LOG_DEBUG("have interface set up"); + int speed_div1; + int retval = jtag->khz(jtag_get_speed_khz(), &speed_div1); + if (ERROR_OK != retval) + { + jtag_set_speed_khz(0); + return retval; + } + cur_speed = speed_div1; + } + return jtag_set_speed(cur_speed); +} + int jtag_get_speed(void) { return jtag_speed; @@ -1192,6 +1213,12 @@ int jtag_set_speed(int speed) return jtag ? jtag->speed(speed) : ERROR_OK; } +int jtag_get_speed_readable(int *speed) +{ + return jtag ? jtag->speed_div(jtag_get_speed(), speed) : ERROR_OK; +} + + void jtag_set_verify(bool enable) { jtag_verify = enable; diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index ce8dacc..dcdad8e 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -270,6 +270,14 @@ extern int jtag_call_event_callbacks(enum jtag_event event); /// @returns The current JTAG speed setting. int jtag_get_speed(void); /** + * Given a @a speed setting, use the interface @c speed_div callback to + * adjust the setting. + * @param speed The speed setting to convert back to readable KHz. + * @returns ERROR_OK if the interface has not been initialized or on success; + * otherwise, the error code produced by the @c speed_div callback. + */ +int jtag_get_speed_readable(int *speed); +/** * Set the JTAG speed. This routine will call the underlying * interface @c speed callback, if the interface has been initialized. * @param speed The new speed setting. @@ -708,6 +716,7 @@ unsigned jtag_get_nsrst_delay(void); void jtag_set_ntrst_delay(unsigned delay); unsigned jtag_get_ntrst_delay(void); +int jtag_config_khz(unsigned khz); void jtag_set_speed_khz(unsigned speed); unsigned jtag_get_speed_khz(void); diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index f26e934..4f2f6b5 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -170,7 +170,6 @@ jtag_interface_t *jtag_interfaces[] = { NULL, }; -extern struct jtag_interface_s *jtag; extern jtag_interface_t *jtag_interface; /* jtag commands */ @@ -1012,41 +1011,24 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, return ERROR_COMMAND_SYNTAX_ERROR; int retval = ERROR_OK; - int cur_speed = 0; if (argc == 1) { - LOG_DEBUG("handle jtag khz"); - - jtag_set_speed_khz(strtoul(args[0], NULL, 0)); - if (jtag != NULL) - { - LOG_DEBUG("have interface set up"); - int speed_div1; - retval = jtag->khz(jtag_get_speed_khz(), &speed_div1); - if (ERROR_OK != retval) - { - jtag_set_speed_khz(0); - return retval; - } - cur_speed = speed_div1; - } - retval = jtag_set_speed(cur_speed); - } - - cur_speed = jtag_get_speed_khz(); - if (jtag != NULL) - { - retval = jtag->speed_div(jtag_get_speed(), &cur_speed); + retval = jtag_config_khz(strtoul(args[0], NULL, 0)); if (ERROR_OK != retval) return retval; } + int cur_speed; + retval = jtag_get_speed_readable(&cur_speed); + if (ERROR_OK != retval) + return retval; + if (cur_speed) command_print(cmd_ctx, "%d kHz", cur_speed); else command_print(cmd_ctx, "RCLK - adaptive"); - return retval; + return retval; } static int handle_jtag_reset_command(struct command_context_s *cmd_ctx, |