]> git.sur5r.net Git - openocd/commitdiff
jtag: getting the JTAG speed can fail
authorØyvind Harboe <oyvind.harboe@zylin.com>
Mon, 6 Dec 2010 08:21:23 +0000 (09:21 +0100)
committerØyvind Harboe <oyvind.harboe@zylin.com>
Wed, 8 Dec 2010 07:43:52 +0000 (08:43 +0100)
If the JTAG speed has not been set, then it has no defined
value, add code to propagate the error.

No change to actual behavior as no new failure paths have
been introduced. This is a no-op patch to make subsequent patches
smaller.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
src/jtag/core.c
src/jtag/drivers/amt_jtagaccel.c
src/jtag/drivers/ft2232.c
src/jtag/drivers/gw16012.c
src/jtag/drivers/jlink.c
src/jtag/drivers/parport.c
src/jtag/drivers/presto.c
src/jtag/drivers/rlink.c
src/jtag/drivers/usb_blaster.c
src/jtag/jtag.h
src/jtag/zy1000/zy1000.c

index c1b64bba41b040ae8bdbea7d3dde302cdea6ffa5..b89530946a6647eb6d86233ee55d292c5a0b0150 100644 (file)
@@ -1384,9 +1384,13 @@ int adapter_init(struct command_context *cmd_ctx)
 
        int requested_khz = jtag_get_speed_khz();
        int actual_khz = requested_khz;
-       int retval = jtag_get_speed_readable(&actual_khz);
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       if (retval != ERROR_OK)
+               return retval;
+       retval = jtag_get_speed_readable(&actual_khz);
        if (ERROR_OK != retval)
-               LOG_INFO("adapter-specific clock speed value %d", jtag_get_speed());
+               LOG_INFO("adapter-specific clock speed value %d", jtag_speed_var);
        else if (actual_khz)
        {
                /* Adaptive clocking -- JTAG-specific */
@@ -1632,30 +1636,33 @@ int jtag_config_rclk(unsigned fallback_speed_khz)
        return (ERROR_OK != retval) ? retval : jtag_set_speed(speed);
 }
 
-int jtag_get_speed(void)
+int jtag_get_speed(int *speed)
 {
-       int speed = 0; /* avoid -O3 warning */
        switch(clock_mode)
        {
                case CLOCK_MODE_SPEED:
-                       speed = jtag_speed;
+                       *speed = jtag_speed;
                        break;
                case CLOCK_MODE_KHZ:
-                       adapter_khz_to_speed(jtag_get_speed_khz(), &speed);
+                       adapter_khz_to_speed(jtag_get_speed_khz(), speed);
                        break;
                case CLOCK_MODE_RCLK:
-                       jtag_rclk_to_speed(rclk_fallback_speed_khz, &speed);
+                       jtag_rclk_to_speed(rclk_fallback_speed_khz, speed);
                        break;
                default:
                        LOG_ERROR("BUG: unknown jtag clock mode");
-                       break;
+                       return ERROR_FAIL;
        }
-       return speed;
+       return ERROR_OK;
 }
 
 int jtag_get_speed_readable(int *khz)
 {
-       return jtag ? jtag->speed_div(jtag_get_speed(), khz) : ERROR_OK;
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       if (retval != ERROR_OK)
+               return retval;
+       return jtag ? jtag->speed_div(jtag_speed_var, khz) : ERROR_OK;
 }
 
 void jtag_set_verify(bool enable)
index fca8cfe32551147bf4eab7397db6dc5060e1e273..552d04d20ef82002c0b396b485353880d5623acc 100644 (file)
@@ -191,7 +191,8 @@ 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();
+       int retval = jtag_get_speed(&jtag_speed);
+       assert(retval == ERROR_OK);
        if (jtag_speed > 3 || rtck_enabled)
                amt_wait_scan_busy();
 
@@ -249,7 +250,9 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
        uint8_t dr_tdo;
        uint8_t aw_tms_scan;
        uint8_t tms_scan[2];
-       int jtag_speed = jtag_get_speed();
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       assert(retval == ERROR_OK);
 
        if (ir_scan)
                amt_jtagaccel_end_state(TAP_IRSHIFT);
@@ -267,7 +270,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
 
                dw_tdi_scan = buf_get_u32(buffer, bit_count, (scan_size - 1) % 8) & 0xff;
                AMT_DW(dw_tdi_scan);
-               if (jtag_speed > 3 || rtck_enabled)
+               if (jtag_speed_var > 3 || rtck_enabled)
                        amt_wait_scan_busy();
 
                if ((type == SCAN_IN) || (type == SCAN_IO))
@@ -285,7 +288,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
        {
                dw_tdi_scan = buf_get_u32(buffer, bit_count, 8) & 0xff;
                AMT_DW(dw_tdi_scan);
-               if (jtag_speed > 3 || rtck_enabled)
+               if (jtag_speed_var > 3 || rtck_enabled)
                        amt_wait_scan_busy();
 
                if ((type == SCAN_IN) || (type == SCAN_IO))
@@ -302,7 +305,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
        tms_scan[1] = amt_jtagaccel_tap_move[tap_move_ndx(tap_get_state())][tap_move_ndx(tap_get_end_state())][1];
        aw_tms_scan = 0x40 | (tms_scan[0] & 0x1f) | (buf_get_u32(buffer, bit_count, 1) << 5);
        AMT_AW(aw_tms_scan);
-       if (jtag_speed > 3 || rtck_enabled)
+       if (jtag_speed_var > 3 || rtck_enabled)
                amt_wait_scan_busy();
 
        if ((type == SCAN_IN) || (type == SCAN_IO))
@@ -316,7 +319,7 @@ static void amt_jtagaccel_scan(bool ir_scan, enum scan_type type, uint8_t *buffe
        {
                aw_tms_scan = 0x40 | (tms_scan[1] & 0x1f);
                AMT_AW(aw_tms_scan);
-               if (jtag_speed > 3 || rtck_enabled)
+               if (jtag_speed_var > 3 || rtck_enabled)
                        amt_wait_scan_busy();
        }
        tap_set_state(tap_get_end_state());
@@ -502,7 +505,9 @@ static int amt_jtagaccel_init(void)
        aw_control_fsm |= 0x04;
        AMT_AW(aw_control_fsm);
 
-       amt_jtagaccel_speed(jtag_get_speed());
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       amt_jtagaccel_speed(jtag_speed_var);
 
        enum reset_types jtag_reset_config = jtag_get_reset_config();
        if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
index 928ec1c66f33eb1fbd5b910f5db49e3732784e0c..77b5880b1f774ccb148e0113953d80595cc6187d 100644 (file)
@@ -2395,7 +2395,11 @@ static int ft2232_init(void)
                        return ERROR_JTAG_INIT_FAILED;
        }
 
-       ft2232_speed(jtag_get_speed());
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       if (retval != ERROR_OK)
+               return retval;
+       ft2232_speed(jtag_speed_var);
 
        buf[0] = 0x85; /* Disconnect TDI/DO to TDO/DI for Loopback */
        if ((retval = ft2232_write(buf, 1, &bytes_written)) != ERROR_OK)
index cb29d33aac99e0d864d58b52eeea115ddc5528b8..172929943c9d8c5dda14f168cf3a7359f1ea9c64 100644 (file)
@@ -529,7 +529,11 @@ static int gw16012_init(void)
        gw16012_input(&status_port);
        gw16012_msb = (status_port & 0x80) ^ 0x80;
 
-       gw16012_speed(jtag_get_speed());
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       if (retval != ERROR_OK)
+               return retval;
+       gw16012_speed(jtag_speed_var);
        gw16012_reset(0, 0);
 
        return ERROR_OK;
index ff389e9ef798368d2639e129ccebca217afec097..e7e3ced9797cb60d7cace00c60261d2c19a97827 100644 (file)
@@ -321,7 +321,11 @@ static int jlink_init(void)
        jlink_reset(0, 0);
        jtag_sleep(3000);
        jlink_tap_init();
-       jlink_speed(jtag_get_speed());
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       if (retval != ERROR_OK)
+               return retval;
+       jlink_speed(jtag_speed_var);
 
        /* 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 2323ec56a95fa1b2736aff941a4eb0e5f4eb869c..3402bc2a05b78350b8127fd598f097f8f4d15d15 100644 (file)
@@ -384,7 +384,9 @@ static int parport_init(void)
 
        bitbang_interface = &parport_bitbang;
 
-       wait_states = jtag_get_speed();
+       int retval = jtag_get_speed(&wait_states);
+       if (retval != ERROR_OK)
+               return retval;
 
        return ERROR_OK;
 }
@@ -475,7 +477,9 @@ COMMAND_HANDLER(parport_handle_parport_toggling_time_command)
                }
 
                parport_toggling_time_ns = ns;
-               wait_states = jtag_get_speed();
+               int retval = jtag_get_speed(&wait_states);
+               if (retval != ERROR_OK)
+                       return retval;
        }
 
        command_print(CMD_CTX, "parport toggling time = %" PRIu32 " ns",
index 10bed2720a4bc1fe8703faeeb72deaf23556ea68..ca6e9d50a169d850406f4cd480ea7bf3620596ee 100644 (file)
@@ -770,7 +770,11 @@ 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_get_speed());
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       if (retval != ERROR_OK)
+               return retval;
+       presto_jtag_speed(jtag_speed_var);
 
        bitq_interface = &presto_bitq;
        return ERROR_OK;
index dde117b0554676073b6c639b5e181a0659a8d59a..a3fad358e37f56678564b052dada93dd1ed7731a 100644 (file)
@@ -1771,7 +1771,11 @@ int rlink_init(void)
 
        tap_state_queue_init();
        dtc_queue_init();
-       rlink_speed(jtag_get_speed());
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       if (retval != ERROR_OK)
+               return retval;
+       rlink_speed(jtag_speed_var);
        rlink_reset(0, 0);
 
        return ERROR_OK;
index 16790405ff0cd4128c1c22377ab39347b9d2ab60..c9b88f86534d43700033e8f6e6b5208a02142aee 100644 (file)
@@ -442,7 +442,11 @@ static int usb_blaster_init(void)
 
        bitbang_interface = &usb_blaster_bitbang;
 
-       usb_blaster_speed(jtag_get_speed());
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       if (retval != ERROR_OK)
+               return retval;
+       usb_blaster_speed(jtag_speed_var);
 
 #if 0
 #if BUILD_USB_BLASTER_FTD2XX == 1
index d6e49e0ac237a035307beff7b35033b347cb1849..db7cd5c9d78e8aa564146ea14cbe06d2650abbc3 100644 (file)
@@ -239,7 +239,7 @@ int jtag_call_event_callbacks(enum jtag_event event);
 
 
 /// @returns The current JTAG speed setting.
-int jtag_get_speed(void);
+int jtag_get_speed(int *speed);
 
 /**
  * Given a @a speed setting, use the interface @c speed_div callback to
index c8bee2f506292c282f03e4cb1271ebb7712b76fe..69fa4dc8e296c7876785eb59768488bf969ad9a9 100644 (file)
@@ -1620,7 +1620,11 @@ int zy1000_init(void)
 
         /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
        zy1000_reset(0, 0);
-       zy1000_speed(jtag_get_speed());
+       int jtag_speed_var;
+       int retval = jtag_get_speed(&jtag_speed_var);
+       if (retval != ERROR_OK)
+               return retval;
+       zy1000_speed(jtag_speed_var);
 
 
 #if BUILD_ECOSBOARD