arm_adi_v5: Do not ignore register polling timeout 86/2086/6
authorAndrey Smirnov <andrew.smirnov@gmail.com>
Thu, 3 Apr 2014 21:27:27 +0000 (14:27 -0700)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Sun, 1 Jun 2014 17:01:37 +0000 (17:01 +0000)
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 <andrew.smirnov@gmail.com>
Reviewed-on: http://openocd.zylin.com/2086
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Tested-by: jenkins
src/target/arm_adi_v5.c
src/target/arm_adi_v5.h

index 1c80fcc2f53bae2469ebeac09aafc0cff3651a53..1e324efae2e08c1ff04829372ac633610c64ae3f 100644 (file)
@@ -619,6 +619,8 @@ int mem_ap_sel_write_buf_noincr(struct adiv5_dap *swjdp, uint8_t ap,
 /*--------------------------------------------------------------------------*/
 
 
+#define DAP_POWER_DOMAIN_TIMEOUT (10)
+
 /* FIXME don't import ... just initialize as
  * part of DAP transport setup
 */
@@ -640,8 +642,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(" ");
@@ -681,36 +681,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;
index 9f0dea9119186466e38f2f389c0f6f89290ba71e..131e9d960aae1d26fc80324a7a5f2376520db565 100644 (file)
@@ -401,6 +401,35 @@ static inline int dap_dp_read_atomic(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)
+{
+       assert(timeout > 0);
+       assert((value & mask) == value);
+
+       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(dap, reg, &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;
+       }
+}
+
 /** Accessor for currently selected DAP-AP number (0..255) */
 static inline uint8_t dap_ap_get_select(struct adiv5_dap *swjdp)
 {

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)