This is an automated email from Gerrit.

Hellosun Wu ([email protected]) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/4292

-- gerrit

commit b7440a428cefb312435675637184d412b37670e6
Author: Hellosun Wu <[email protected]>
Date:   Wed Nov 8 17:04:11 2017 +0800

    nds32: Avoid detected JTAG clock and set timeout
    
    AICE2 doesn't support scan for the maximum clock frequency of
    JTAG chain. It will cause USB command timeout.
    After setup JTAG clock, AICE will repeatedly polls the target until the
    completion of the command, set maximum waiting time to 5000ms as default.
    
    Change-Id: I41d1e3be387b6ed5a4dd0be663385a5f053fbcf9
    Signed-off-by: Hellosun Wu <[email protected]>

diff --git a/src/jtag/aice/aice_usb.c b/src/jtag/aice/aice_usb.c
index 50468f3..e5d6a89 100644
--- a/src/jtag/aice/aice_usb.c
+++ b/src/jtag/aice/aice_usb.c
@@ -1778,7 +1778,7 @@ static uint8_t total_num_of_core;
 static char *custom_srst_script;
 static char *custom_trst_script;
 static char *custom_restart_script;
-static uint32_t aice_count_to_check_dbger = 30;
+static uint32_t aice_count_to_check_dbger = 5000;
 
 static int aice_read_reg(uint32_t coreid, uint32_t num, uint32_t *val);
 static int aice_write_reg(uint32_t coreid, uint32_t num, uint32_t val);
@@ -2289,37 +2289,25 @@ get_delay:
 
 static int aice_usb_set_clock(int set_clock)
 {
-       if (aice_write_ctrl(AICE_WRITE_CTRL_TCK_CONTROL,
-                               AICE_TCK_CONTROL_TCK_SCAN) != ERROR_OK)
-               return ERROR_FAIL;
-
-       /* Read out TCK_SCAN clock value */
-       uint32_t scan_clock;
-       if (aice_read_ctrl(AICE_READ_CTRL_GET_ICE_STATE, &scan_clock) != 
ERROR_OK)
-               return ERROR_FAIL;
+       if (set_clock == 16) {
+               /* Users do NOT specify the jtag clock, use scan-freq */
+               LOG_DEBUG("Use scan -freq");
 
-       scan_clock &= 0x0F;
-
-       uint32_t scan_base_freq;
-       if (scan_clock & 0x8)
-               scan_base_freq = 48000; /* 48 MHz */
-       else
-               scan_base_freq = 30000; /* 30 MHz */
+               if (aice_write_ctrl(AICE_WRITE_CTRL_TCK_CONTROL,
+                                       AICE_TCK_CONTROL_TCK_SCAN) != ERROR_OK)
+                       return ERROR_FAIL;
 
-       uint32_t set_base_freq;
-       if (set_clock & 0x8)
-               set_base_freq = 48000;
-       else
-               set_base_freq = 30000;
+               /* Read out TCK_SCAN clock value */
+               uint32_t scan_clock = 0;
+               if (aice_read_ctrl(AICE_READ_CTRL_GET_ICE_STATE,
+                                       &scan_clock) != ERROR_OK)
+                       return ERROR_FAIL;
 
-       uint32_t set_freq;
-       uint32_t scan_freq;
-       set_freq = set_base_freq >> (set_clock & 0x7);
-       scan_freq = scan_base_freq >> (scan_clock & 0x7);
+               set_clock = (scan_clock & 0x0F);
 
-       if (scan_freq < set_freq) {
-               LOG_ERROR("User specifies higher jtag clock than TCK_SCAN 
clock");
-               return ERROR_FAIL;
+               /* If scan-freq = 48MHz, use 24MHZ by default */
+               if (set_clock == 8)
+                       set_clock = 9;
        }
 
        if (aice_write_ctrl(AICE_WRITE_CTRL_TCK_CONTROL, set_clock) != ERROR_OK)
@@ -2334,6 +2322,8 @@ static int aice_usb_set_clock(int set_clock)
                return ERROR_FAIL;
        }
 
+       aice_write_ctrl(AICE_WRITE_CTRL_TIMEOUT, aice_count_to_check_dbger);
+       jtag_clock = set_clock;
        return ERROR_OK;
 }
 
diff --git a/src/jtag/aice/aice_usb.h b/src/jtag/aice/aice_usb.h
index 2911ae5..a41d352 100644
--- a/src/jtag/aice/aice_usb.h
+++ b/src/jtag/aice/aice_usb.h
@@ -40,6 +40,7 @@
 #define AICE_READ_CTRL_GET_FPGA_VERSION                0x02
 #define AICE_READ_CTRL_GET_FIRMWARE_VERSION    0x03
 #define AICE_READ_CTRL_GET_JTAG_PIN_STATUS     0x04
+#define AICE_WRITE_CTRL_TIMEOUT                                0x07
 #define AICE_READ_CTRL_BATCH_BUF_INFO          0x22
 #define AICE_READ_CTRL_BATCH_STATUS                    0x23
 #define AICE_READ_CTRL_BATCH_BUF0_STATE                0x31

-- 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to