arm_adi_v5: fix mem_ap_read_buf_u32() JTAG nastiness..77/1277/4
authormike brown <theshed@mikebrown.org.uk>
Mon, 18 Mar 2013 17:19:14 +0000 (18 17:19 +0000)
committerSpencer Oliver <spen@spen-soft.co.uk>
Tue, 2 Apr 2013 15:09:40 +0000 (2 15:09 +0000)
Moved JTAG code out of transport-neutral file (arm_adi_v5.c) into
transport specific file (adi_v5_jtag.c).
Added ap_block_read to dap_ops interface (arm_adi_v5.h) to support
the move.

Change-Id: I796d3984f138aad052b97c77ac9c12ffd1158f74
Signed-off-by: mike brown <mike@theshedworks.org.uk>
Reviewed-on: http://openocd.zylin.com/1277
Tested-by: jenkins
Reviewed-by: Michel JAOUEN <michel.jaouen@stericsson.com>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
src/target/adi_v5_jtag.c
src/target/arm_adi_v5.c
src/target/arm_adi_v5.h

index 9f37bd5..e500416 100644 (file)
  * @param ack points to where the three bit JTAG_ACK_* code will be stored
  */
 
-/* FIXME don't export ... this is a temporary workaround for the
- * mem_ap_read_buf_u32() mess, until it's no longer JTAG-specific.
- */
-int adi_jtag_dp_scan(struct adiv5_dap *dap,
+static int adi_jtag_dp_scan(struct adiv5_dap *dap,
                uint8_t instr, uint8_t reg_addr, uint8_t RnW,
                uint8_t *outvalue, uint8_t *invalue, uint8_t *ack)
 {
@@ -417,6 +414,40 @@ static int jtag_ap_q_write(struct adiv5_dap *dap, unsigned reg,
        return adi_jtag_ap_write_check(dap, reg, out_value_buf);
 }
 
+static int jtag_ap_q_read_block(struct adiv5_dap *dap, unsigned reg,
+               uint32_t blocksize, uint8_t *buffer)
+{
+       uint32_t readcount;
+       int retval = ERROR_OK;
+
+       /* Scan out first read */
+       retval = adi_jtag_dp_scan(dap, JTAG_DP_APACC, reg,
+                       DPAP_READ, 0, NULL, NULL);
+       if (retval != ERROR_OK)
+               return retval;
+
+       for (readcount = 0; readcount < blocksize - 1; readcount++) {
+               /* Scan out next read; scan in posted value for the
+                * previous one.  Assumes read is acked "OK/FAULT",
+                * and CTRL_STAT says that meant "OK".
+                */
+               retval = adi_jtag_dp_scan(dap, JTAG_DP_APACC, reg,
+                               DPAP_READ, 0, buffer + 4 * readcount,
+                               &dap->ack);
+               if (retval != ERROR_OK)
+                       return retval;
+       }
+
+       /* Scan in last posted value; RDBUFF has no other effect,
+        * assuming ack is OK/FAULT and CTRL_STAT says "OK".
+        */
+       retval = adi_jtag_dp_scan(dap, JTAG_DP_DPACC, DP_RDBUFF,
+                       DPAP_READ, 0, buffer + 4 * readcount,
+                       &dap->ack);
+
+       return retval;
+}
+
 static int jtag_ap_q_abort(struct adiv5_dap *dap, uint8_t *ack)
 {
        /* for JTAG, this is the only valid ABORT register operation */
@@ -433,13 +464,14 @@ static int jtag_dp_run(struct adiv5_dap *dap)
  * part of DAP setup
 */
 const struct dap_ops jtag_dp_ops = {
-       .queue_idcode_read =    jtag_idcode_q_read,
-       .queue_dp_read =        jtag_dp_q_read,
-       .queue_dp_write =       jtag_dp_q_write,
-       .queue_ap_read =        jtag_ap_q_read,
-       .queue_ap_write =       jtag_ap_q_write,
-       .queue_ap_abort =       jtag_ap_q_abort,
-       .run =                  jtag_dp_run,
+       .queue_idcode_read   = jtag_idcode_q_read,
+       .queue_dp_read       = jtag_dp_q_read,
+       .queue_dp_write      = jtag_dp_q_write,
+       .queue_ap_read       = jtag_ap_q_read,
+       .queue_ap_write      = jtag_ap_q_write,
+       .queue_ap_read_block = jtag_ap_q_read_block,
+       .queue_ap_abort      = jtag_ap_q_abort,
+       .run                 = jtag_dp_run,
 };
 
 
index 1572861..28f4318 100644 (file)
@@ -539,13 +539,6 @@ int mem_ap_write_buf_u8(struct adiv5_dap *dap, const uint8_t *buffer, int count,
        return retval;
 }
 
-/* FIXME don't import ... this is a temporary workaround for the
- * mem_ap_read_buf_u32() mess, until it's no longer JTAG-specific.
- */
-extern int adi_jtag_dp_scan(struct adiv5_dap *dap,
-               uint8_t instr, uint8_t reg_addr, uint8_t RnW,
-               uint8_t *outvalue, uint8_t *invalue, uint8_t *ack);
-
 /**
  * Synchronously read a block of 32-bit words into a buffer
  * @param dap The DAP connected to the MEM-AP.
@@ -588,38 +581,7 @@ int mem_ap_read_buf_u32(struct adiv5_dap *dap, uint8_t *buffer,
                if (retval != ERROR_OK)
                        return retval;
 
-               /* FIXME remove these three calls to adi_jtag_dp_scan(),
-                * so this routine becomes transport-neutral.  Be careful
-                * not to cause performance problems with JTAG; would it
-                * suffice to loop over dap_queue_ap_read(), or would that
-                * be slower when JTAG is the chosen transport?
-                */
-
-               /* Scan out first read */
-               retval = adi_jtag_dp_scan(dap, JTAG_DP_APACC, AP_REG_DRW,
-                               DPAP_READ, 0, NULL, NULL);
-               if (retval != ERROR_OK)
-                       return retval;
-               for (readcount = 0; readcount < blocksize - 1; readcount++) {
-                       /* Scan out next read; scan in posted value for the
-                        * previous one.  Assumes read is acked "OK/FAULT",
-                        * and CTRL_STAT says that meant "OK".
-                        */
-                       retval = adi_jtag_dp_scan(dap, JTAG_DP_APACC, AP_REG_DRW,
-                                       DPAP_READ, 0, buffer + 4 * readcount,
-                                       &dap->ack);
-                       if (retval != ERROR_OK)
-                               return retval;
-               }
-
-               /* Scan in last posted value; RDBUFF has no other effect,
-                * assuming ack is OK/FAULT and CTRL_STAT says "OK".
-                */
-               retval = adi_jtag_dp_scan(dap, JTAG_DP_DPACC, DP_RDBUFF,
-                               DPAP_READ, 0, buffer + 4 * readcount,
-                               &dap->ack);
-               if (retval != ERROR_OK)
-                       return retval;
+               retval = dap_queue_ap_read_block(dap, AP_REG_DRW, blocksize, buffer);
 
                retval = dap_run(dap);
                if (retval != ERROR_OK) {
index 7f1ebf5..301402e 100644 (file)
@@ -216,6 +216,9 @@ struct dap_ops {
        /** AP register write. */
        int (*queue_ap_write)(struct adiv5_dap *dap, unsigned reg,
                        uint32_t data);
+       /** AP read block. */
+       int (*queue_ap_read_block)(struct adiv5_dap *dap, unsigned reg,
+                       uint32_t blocksize, uint8_t *buffer);
 
        /** AP operation abort. */
        int (*queue_ap_abort)(struct adiv5_dap *dap, uint8_t *ack);
@@ -322,6 +325,24 @@ static inline int dap_queue_ap_write(struct adiv5_dap *dap,
 }
 
 /**
+ * Queue an AP block read.
+ *
+ * @param dap The DAP used for reading.
+ * @param reg The number of the AP register being read.
+ * @param blocksize The number of the AP register being read.
+ * @param buffer Pointer saying where to store the data
+ * (in host endianness).
+ *
+ * @return ERROR_OK for success, else a fault code.
+ */
+static inline int dap_queue_ap_read_block(struct adiv5_dap *dap,
+               unsigned reg, unsigned blocksize, uint8_t *buffer)
+{
+       assert(dap->ops != NULL);
+       return dap->ops->queue_ap_read_block(dap, reg, blocksize, buffer);
+}
+
+/**
  * Queue an AP abort operation.  The current AP transaction is aborted,
  * including any update of the transaction counter.  The AP is left in
  * an unknown state (so it must be re-initialized).  For use only after