summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-09 10:07:07 +0000
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-09 10:07:07 +0000
commite8febc22551f1afe3cfa556f7afb16fd8996b6c8 (patch)
tree602f5c8e4d457cd08c3709ef7756dde4c8c2fbc0
parent5f4ecc60a9ed083d208c56dd5ff50fac81dbe4d5 (diff)
downloadopenocd+libswd-e8febc22551f1afe3cfa556f7afb16fd8996b6c8.tar.gz
openocd+libswd-e8febc22551f1afe3cfa556f7afb16fd8996b6c8.tar.bz2
openocd+libswd-e8febc22551f1afe3cfa556f7afb16fd8996b6c8.tar.xz
openocd+libswd-e8febc22551f1afe3cfa556f7afb16fd8996b6c8.zip
Encapsulate the core jtag interface pointer:
- Add new jtag_config_khz to increase encapsulation of jtag->khz call. - Add new jtag_get_speed_readable to encapsulate of jtag->speed_div call. - Make definition of jtag static in core.c, remove extern from tcl.c. git-svn-id: svn://svn.berlios.de/openocd/trunk@2171 b42882b7-edfa-0310-969c-e2dbd0fdcd60
-rw-r--r--src/jtag/core.c29
-rw-r--r--src/jtag/jtag.h9
-rw-r--r--src/jtag/tcl.c32
3 files changed, 44 insertions, 26 deletions
diff --git a/src/jtag/core.c b/src/jtag/core.c
index 4d4d2783..27866502 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 ce8daccc..dcdad8e1 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 f26e934a..4f2f6b5f 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,