]> git.sur5r.net Git - openocd/commitdiff
Add get and set accessors for jtag_speed:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Tue, 9 Jun 2009 08:40:10 +0000 (08:40 +0000)
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Tue, 9 Jun 2009 08:40:10 +0000 (08:40 +0000)
- Setter calls the interface driver callback to improve core encapsulation.
- Use getter in standard JTAG interface drivers and ZY1000 minidriver.

git-svn-id: svn://svn.berlios.de/openocd/trunk@2159 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/jtag/amt_jtagaccel.c
src/jtag/core.c
src/jtag/ft2232.c
src/jtag/gw16012.c
src/jtag/jlink.c
src/jtag/jtag.h
src/jtag/parport.c
src/jtag/presto.c
src/jtag/rlink/rlink.c
src/jtag/tcl.c
src/jtag/zy1000/zy1000.c

index b19fae17ebd6a7980634cfc57c5788c69565482c..4071c25c984f285ba67e6dce74f0000327267c85 100644 (file)
@@ -187,6 +187,7 @@ static void amt_jtagaccel_state_move(void)
 
        aw_scan_tms_5 = 0x40 | (tms_scan[0] & 0x1f);
        AMT_AW(aw_scan_tms_5);
+       int jtag_speed = jtag_get_speed();
        if (jtag_speed > 3 || rtck_enabled)
                amt_wait_scan_busy();
 
@@ -244,6 +245,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, u8 *buffer, in
        u8 dr_tdo;
        u8 aw_tms_scan;
        u8 tms_scan[2];
+       int jtag_speed = jtag_get_speed();
 
        if (ir_scan)
                amt_jtagaccel_end_state(TAP_IRSHIFT);
@@ -496,7 +498,7 @@ static int amt_jtagaccel_init(void)
        aw_control_fsm |= 0x04;
        AMT_AW(aw_control_fsm);
 
-       amt_jtagaccel_speed(jtag_speed);
+       amt_jtagaccel_speed(jtag_get_speed());
 
        if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
                aw_control_rst &= ~0x8;
index 5edcce22c12b09909cd7a43f50b7b92470e54a70..f6db00a5c326d987337c022c623740d697e8cb70 100644 (file)
@@ -1153,6 +1153,18 @@ unsigned jtag_get_speed_khz(void)
 {
        return speed_khz;
 }
+int jtag_get_speed(void)
+{
+       return jtag_speed;
+}
+
+int jtag_set_speed(int speed)
+{
+       jtag_speed = speed;
+       /* this command can be called during CONFIG,
+        * in which case jtag isn't initialized */
+       return jtag ? jtag->speed(speed) : ERROR_OK;
+}
 
 void jtag_set_verify(bool enable)
 {
index ae3bd863c30ee83593e820a73d279997c213123e..734833b125594408e3d36a49a5c376aea29d3203 100644 (file)
@@ -2099,7 +2099,7 @@ static int ft2232_init(void)
        if (layout->init() != ERROR_OK)
                return ERROR_JTAG_INIT_FAILED;
 
-       ft2232_speed(jtag_speed);
+       ft2232_speed(jtag_get_speed());
 
        buf[0] = 0x85; /* Disconnect TDI/DO to TDO/DI for Loopback */
        if (((retval = ft2232_write(buf, 1, &bytes_written)) != ERROR_OK) || (bytes_written != 1))
index a89a5f7e3212143ba6251936e0948ca61ee01e6b..0ea66340c465941d0cd802216a1f5725c0960c34 100644 (file)
@@ -557,7 +557,7 @@ static int gw16012_init(void)
        gw16012_input(&status_port);
        gw16012_msb = (status_port & 0x80) ^ 0x80;
 
-       gw16012_speed(jtag_speed);
+       gw16012_speed(jtag_get_speed());
        gw16012_reset(0, 0);
 
        return ERROR_OK;
index 22b058df3360eca6f2b623293c7d1e46c3ea4df7..ce0489c0cc72ebda5fdaf6abbef5ea47ab665895 100644 (file)
@@ -340,7 +340,7 @@ static int jlink_init(void)
        jlink_reset(0, 0);
        jtag_sleep(3000);
        jlink_tap_init();
-       jlink_speed(jtag_speed);
+       jlink_speed(jtag_get_speed());
 
        /* v5/6 jlink seems to have an issue if the first tap move
         * is not divisible by 8, so we send a TLR on first power up */
index fd4953ec04683f17683976dc4e54b3ebdc9bae37..0e21738ebc38a3b92489408246c684db9e687511 100644 (file)
@@ -255,7 +255,17 @@ typedef struct jtag_event_callback_s
        struct jtag_event_callback_s* next;
 } jtag_event_callback_t;
 
-extern int jtag_speed;
+/// @returns The current JTAG speed setting.
+int jtag_get_speed(void);
+/**
+ * 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.
+ * @returns ERROR_OK during configuration or on success, or an error
+ *   code returned from the interface @c speed callback.
+ */
+int jtag_set_speed(int speed);
+
 extern int jtag_speed_post_reset;
 
 enum reset_types {
index 3f026b043df5a9fe966423bfd9100b03bdd5abf2..4ee2202d06e4919e06723fddf05774e7d55dd6dd 100644 (file)
@@ -189,7 +189,7 @@ static __inline__ void parport_write_data(void)
 
 static void parport_write(int tck, int tms, int tdi)
 {
-       int i = jtag_speed + 1;
+       int i = jtag_get_speed() + 1;
 
        if (tck)
                dataport_value |= cable->TCK_MASK;
index 6123259c64bf71878d86c037f4fab2acd8527857..125658be5b8a6977656399c8b521215c91b961a9 100644 (file)
@@ -787,7 +787,7 @@ static int presto_jtag_init(void)
        LOG_INFO("PRESTO open, serial number '%s'", presto->serial);
 
        /* use JTAG speed setting from configuration file */
-       presto_jtag_speed(jtag_speed);
+       presto_jtag_speed(jtag_get_speed());
 
        bitq_interface = &presto_bitq;
        return ERROR_OK;
index f47e189c3bfe97bbdc983e6e8bef1059ae104224..121de01ff182e637cedc5e36a5ec528b257affec 100644 (file)
@@ -1849,7 +1849,7 @@ int rlink_init(void)
 
        tap_state_queue_init();
        dtc_queue_init();
-       rlink_speed(jtag_speed);
+       rlink_speed(jtag_get_speed());
        rlink_reset(0, 0);
 
        return ERROR_OK;
index 8836b484673f581fa40df73a34a3dc626661c938..ed24498b87e10e2847aa224bdbc7dac730afb384 100644 (file)
@@ -960,14 +960,11 @@ static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cm
                LOG_DEBUG("handle jtag speed");
 
                int cur_speed = 0;
-               cur_speed = jtag_speed = strtoul(args[0], NULL, 0);
+               cur_speed = strtoul(args[0], NULL, 0);
+               retval = jtag_set_speed(cur_speed);
 
-               /* this command can be called during CONFIG,
-                * in which case jtag isn't initialized */
-               if (jtag)
-                       retval = jtag->speed(cur_speed);
        }
-       command_print(cmd_ctx, "jtag_speed: %d", jtag_speed);
+       command_print(cmd_ctx, "jtag_speed: %d", jtag_get_speed());
 
        return retval;
 }
@@ -994,9 +991,9 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd,
                                jtag_set_speed_khz(0);
                                return retval;
                        }
-                       cur_speed = jtag_speed = speed_div1;
+                       cur_speed = speed_div1;
 
-                       retval = jtag->speed(cur_speed);
+                       retval = jtag_set_speed(cur_speed);
                }
                else
                        hasKHz = true;
@@ -1005,7 +1002,7 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd,
        cur_speed = jtag_get_speed_khz();
        if (jtag != NULL)
        {
-               retval = jtag->speed_div(jtag_speed, &cur_speed);
+               retval = jtag->speed_div(jtag_get_speed(), &cur_speed);
                if (ERROR_OK != retval)
                        return retval;
        }
index ad148f1d6d7c6c6ff41bf713d7e0f7b3c8504aef..05bbd4c5cd0d24a2437bb90f7bb4ae796de82c5d 100644 (file)
@@ -356,7 +356,7 @@ int zy1000_init(void)
 
         /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
        zy1000_reset(0, 0);
-       zy1000_speed(jtag_speed);
+       zy1000_speed(jtag_get_speed());
 
        return ERROR_OK;
 }