This is an automated email from Gerrit.

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

-- gerrit

commit 70c33b18b2568cc7e06ed0a3246a46e9ece569a1
Author: Andrey Smirnov <[email protected]>
Date:   Thu Apr 3 14:27:27 2014 -0700

    arm_adi_v5: Do not ignore register polling timeout
    
    Previous to this commit 'ahbap_debugport_init' would ignore if timeout
    happened or not when waiting for CDBGPWRUPACK and CSYSPWRUPACK and would
    continue initialization regardless. It also would not reset the
    timeout counter after finishing polling for CDBGPWRUPACK and starting
    for CSYSPWRUPACK which could potentially cause some problems.
    
    Also refactor code of both snippets into a more generic function to
    avoid duplication.
    
    Change-Id: I16e4f50e6819e08c4126e71ef8cec7db559d608e
    Signed-off-by: Andrey Smirnov <[email protected]>

diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c
index 4a1e42c..0a1289a 100644
--- a/src/target/arm_adi_v5.c
+++ b/src/target/arm_adi_v5.c
@@ -736,6 +736,8 @@ int dap_syssec(struct adiv5_dap *dap)
 /*--------------------------------------------------------------------------*/
 
 
+#define DAP_POWER_DOMAIN_TIMEOUT (10)
+
 /* FIXME don't import ... just initialize as
  * part of DAP transport setup
 */
@@ -757,8 +759,6 @@ extern const struct dap_ops jtag_dp_ops;
  */
 int ahbap_debugport_init(struct adiv5_dap *dap)
 {
-       uint32_t ctrlstat;
-       int cnt = 0;
        int retval;
 
        LOG_DEBUG(" ");
@@ -798,36 +798,21 @@ int ahbap_debugport_init(struct adiv5_dap *dap)
        if (retval != ERROR_OK)
                return retval;
 
-       retval = dap_queue_dp_read(dap, DP_CTRL_STAT, &ctrlstat);
+       /* Check that we have debug power domains activated */
+       LOG_DEBUG("DAP: wait CDBGPWRUPACK");
+       retval = dap_dp_poll_register(dap, DP_CTRL_STAT,
+                                     CDBGPWRUPACK, CDBGPWRUPACK,
+                                     DAP_POWER_DOMAIN_TIMEOUT);
        if (retval != ERROR_OK)
                return retval;
-       retval = dap_run(dap);
+
+       LOG_DEBUG("DAP: wait CSYSPWRUPACK");
+       retval = dap_dp_poll_register(dap, DP_CTRL_STAT,
+                                     CSYSPWRUPACK, CSYSPWRUPACK,
+                                     DAP_POWER_DOMAIN_TIMEOUT);
        if (retval != ERROR_OK)
                return retval;
 
-       /* Check that we have debug power domains activated */
-       while (!(ctrlstat & CDBGPWRUPACK) && (cnt++ < 10)) {
-               LOG_DEBUG("DAP: wait CDBGPWRUPACK");
-               retval = dap_queue_dp_read(dap, DP_CTRL_STAT, &ctrlstat);
-               if (retval != ERROR_OK)
-                       return retval;
-               retval = dap_run(dap);
-               if (retval != ERROR_OK)
-                       return retval;
-               alive_sleep(10);
-       }
-
-       while (!(ctrlstat & CSYSPWRUPACK) && (cnt++ < 10)) {
-               LOG_DEBUG("DAP: wait CSYSPWRUPACK");
-               retval = dap_queue_dp_read(dap, DP_CTRL_STAT, &ctrlstat);
-               if (retval != ERROR_OK)
-                       return retval;
-               retval = dap_run(dap);
-               if (retval != ERROR_OK)
-                       return retval;
-               alive_sleep(10);
-       }
-
        retval = dap_queue_dp_read(dap, DP_CTRL_STAT, NULL);
        if (retval != ERROR_OK)
                return retval;
diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h
index df9ceed..7d938b4 100644
--- a/src/target/arm_adi_v5.h
+++ b/src/target/arm_adi_v5.h
@@ -392,6 +392,32 @@ static inline int dap_dp_read_atomic_u32(struct adiv5_dap 
*dap, unsigned reg,
        return dap_run(dap);
 }
 
+static inline int dap_dp_poll_register(struct adiv5_dap *dap, unsigned reg,
+                                      uint32_t mask, uint32_t value, int 
timeout)
+{
+       int ret;
+       uint32_t regval;
+       LOG_DEBUG("DAP: poll %x, mask 0x08%" PRIx32 ", value 0x%08" PRIx32,
+                 reg, mask, value);
+       do {
+               ret = dap_dp_read_atomic_u32(dap, DP_CTRL_STAT, &regval);
+               if (ret != ERROR_OK)
+                       return ret;
+
+               if ((regval & mask) == value)
+                       break;
+
+               alive_sleep(10);
+       } while (--timeout);
+
+       if (!timeout) {
+               LOG_DEBUG("DAP: poll %x timeout", reg);
+               return ERROR_FAIL;
+       } else {
+               return ERROR_OK;
+       }
+}
+
 static inline int dap_ap_abort_atomic(struct adiv5_dap *dap, uint8_t *ack)
 {
        int ret;

-- 

------------------------------------------------------------------------------
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to