Encapsulate the core jtag interface pointer:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Tue, 9 Jun 2009 10:07:07 +0000 (10:07 +0000)
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Tue, 9 Jun 2009 10:07:07 +0000 (10:07 +0000)
- 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

src/jtag/core.c
src/jtag/jtag.h
src/jtag/tcl.c

index 4d4d278347ffc0963b40633d362545f3d3ad9176..27866502aeaa08256a01b2dc10e89e9127d666ae 100644 (file)
@@ -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;
index ce8daccc926cd63ae4bdfcc9c4d2b9a4d212f642..dcdad8e17dde4906066b4d0e6a49c08eaa44705d 100644 (file)
@@ -269,6 +269,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.
@@ -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);
 
index f26e934a4d52d74de48ea34004921b2027fc5864..4f2f6b5f5b283041dc98f556b77ee26b8561ce92 100644 (file)
@@ -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,

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)