* is used to access memory mapped resources and is called a MEM-AP. Also a
* JTAG-AP is also defined, bridging to JTAG resources; those are uncommon.
*
- * @todo Remove modality (queued/nonqueued, via DAP trans_mode) from all
- * procedure interfaces. Modal programming interfaces are very error prone.
- * Procedures should be either queued, or synchronous. Otherwise input
- * and output constraints are context-sensitive, and it's hard to know
- * what a block of code will do just by reading it.
+ * This programming interface allows DAP pipelined operations through a
+ * transaction queue. This primarily affects AP operations (such as using
+ * a MEM-AP to access memory or registers). If the current transaction has
+ * not finished by the time the next one must begin, and the ORUNDETECT bit
+ * is set in the DP_CTRL_STAT register, the SSTICKYORUN status is set and
+ * further AP operations will fail. There are two basic methods to avoid
+ * such overrun errors. One involves polling for status instead of using
+ * transaction piplining. The other involves adding delays to ensure the
+ * AP has enough time to complete one operation before starting the next
+ * one. (For JTAG these delays are controlled by memaccess_tck.)
*/
/*
#include "arm_adi_v5.h"
#include <helper/time_support.h>
-/*
- * Transaction Mode:
- * swjdp->trans_mode = TRANS_MODE_COMPOSITE;
- * Uses Overrun checking mode and does not do actual JTAG send/receive or transaction
- * result checking until swjdp_end_transaction()
- * This must be done before using or deallocating any return variables.
- * swjdp->trans_mode == TRANS_MODE_ATOMIC
- * All reads and writes to the AHB bus are checked for valid completion, and return values
- * are immediatley available.
-*/
-
/* ARM ADI Specification requires at least 10 bits used for TAR autoincrement */
jtag_set_end_state(TAP_IDLE);
arm_jtag_set_instr(jtag_info, instr, NULL);
- /* Add specified number of tck clocks before accessing memory bus */
-
- /* REVISIT these TCK cycles should be *AFTER* updating APACC, since
- * they provide more time for the (MEM) AP to complete the read ...
- * See "Minimum Response Time" for JTAG-DP, in the ADIv5 spec.
- */
- if ((instr == JTAG_DP_APACC)
- && ((reg_addr == AP_REG_DRW)
- || ((reg_addr & 0xF0) == AP_REG_BD0))
- && (swjdp->memaccess_tck != 0))
- jtag_add_runtest(swjdp->memaccess_tck, jtag_set_end_state(TAP_IDLE));
-
/* Scan out a read or write operation using some DP or AP register.
* For APACC access with any sticky error flag set, this is discarded.
*/
jtag_add_dr_scan(2, fields, jtag_get_end_state());
+ /* Add specified number of tck clocks after starting memory bus
+ * access, giving the hardware time to complete the access.
+ * They provide more time for the (MEM) AP to complete the read ...
+ * See "Minimum Response Time" for JTAG-DP, in the ADIv5 spec.
+ */
+ if ((instr == JTAG_DP_APACC)
+ && ((reg_addr == AP_REG_DRW)
+ || ((reg_addr & 0xF0) == AP_REG_BD0))
+ && (swjdp->memaccess_tck != 0))
+ jtag_add_runtest(swjdp->memaccess_tck,
+ jtag_set_end_state(TAP_IDLE));
+
return jtag_get_error();
}
/**
* Utility to write AP registers.
*/
-static int ap_write_check(struct swjdp_common *dap,
+static inline int adi_jtag_ap_write_check(struct swjdp_common *dap,
uint8_t reg_addr, uint8_t *outvalue)
{
- adi_jtag_dp_scan(dap, JTAG_DP_APACC, reg_addr, DPAP_WRITE,
+ return adi_jtag_dp_scan(dap, JTAG_DP_APACC, reg_addr, DPAP_WRITE,
outvalue, NULL, NULL);
-
- /* REVISIT except in dap_setup_accessport() almost all call paths
- * set up COMPOSITE. Probably worth just inlining the scan...
- */
-
- /* In TRANS_MODE_ATOMIC all JTAG_DP_APACC transactions wait for
- * ack = OK/FAULT and the check CTRL_STAT
- */
- if (dap->trans_mode == TRANS_MODE_ATOMIC)
- return jtagdp_transaction_endcheck(dap);
-
- return ERROR_OK;
}
-static int scan_inout_check_u32(struct swjdp_common *swjdp,
+static int adi_jtag_scan_inout_check_u32(struct swjdp_common *swjdp,
uint8_t instr, uint8_t reg_addr, uint8_t RnW,
uint32_t outvalue, uint32_t *invalue)
{
+ int retval;
+
/* Issue the read or write */
- adi_jtag_dp_scan_u32(swjdp, instr, reg_addr, RnW, outvalue, NULL, NULL);
+ retval = adi_jtag_dp_scan_u32(swjdp, instr, reg_addr,
+ RnW, outvalue, NULL, NULL);
+ if (retval != ERROR_OK)
+ return retval;
/* For reads, collect posted value; RDBUFF has no other effect.
* Assumes read gets acked with OK/FAULT, and CTRL_STAT says "OK".
*/
if ((RnW == DPAP_READ) && (invalue != NULL))
- adi_jtag_dp_scan_u32(swjdp, JTAG_DP_DPACC,
+ retval = adi_jtag_dp_scan_u32(swjdp, JTAG_DP_DPACC,
DP_RDBUFF, DPAP_READ, 0, invalue, &swjdp->ack);
-
- /* In TRANS_MODE_ATOMIC all JTAG_DP_APACC transactions wait for
- * ack = OK/FAULT and then check CTRL_STAT
- */
- if ((instr == JTAG_DP_APACC)
- && (swjdp->trans_mode == TRANS_MODE_ATOMIC))
- return jtagdp_transaction_endcheck(swjdp);
-
- return ERROR_OK;
+ return retval;
}
int jtagdp_transaction_endcheck(struct swjdp_common *swjdp)
#if 0
/* Danger!!!! BROKEN!!!! */
- scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+ adi_jtag_scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
/* Danger!!!! BROKEN!!!! Why will jtag_execute_queue() fail here????
R956 introduced the check on return value here and now Michael Schwingen reports
/* Post CTRL/STAT read; discard any previous posted read value
* but collect its ACK status.
*/
- scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+ adi_jtag_scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
if ((retval = jtag_execute_queue()) != ERROR_OK)
return retval;
return ERROR_JTAG_DEVICE_ERROR;
}
- scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+ adi_jtag_scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
if ((retval = jtag_execute_queue()) != ERROR_OK)
return retval;
LOG_ERROR("JTAG-DP STICKY ERROR");
/* Clear Sticky Error Bits */
- scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+ adi_jtag_scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
DP_CTRL_STAT, DPAP_WRITE,
swjdp->dp_ctrl_stat | SSTICKYORUN
| SSTICKYERR, NULL);
- scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+ adi_jtag_scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
if ((retval = jtag_execute_queue()) != ERROR_OK)
return retval;
static int dap_dp_write_reg(struct swjdp_common *swjdp,
uint32_t value, uint8_t reg_addr)
{
- return scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+ return adi_jtag_scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
reg_addr, DPAP_WRITE, value, NULL);
}
static int dap_dp_read_reg(struct swjdp_common *swjdp,
uint32_t *value, uint8_t reg_addr)
{
- return scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+ return adi_jtag_scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
reg_addr, DPAP_READ, 0, value);
}
if (retval != ERROR_OK)
return retval;
- return ap_write_check(swjdp, reg_addr, out_value_buf);
+ return adi_jtag_ap_write_check(swjdp, reg_addr, out_value_buf);
}
/**
- * Write an AP register value.
- * This is synchronous iff the mode is set to ATOMIC, in which
- * case any queued transactions are flushed.
+ * Asynchronous (queued) AP register write.
*
* @param swjdp The DAP whose currently selected AP will be written.
* @param reg_addr Eight bit AP register address.
* @param value Word to be written at reg_addr
*
- * @return In synchronous mode: ERROR_OK for success, and the register holds
- * the specified value; else a fault code. In asynchronous mode, a status
- * code reflecting whether the transaction was properly queued.
+ * @return ERROR_OK if the transaction was properly queued, else a fault code.
*/
int dap_ap_write_reg_u32(struct swjdp_common *swjdp,
uint32_t reg_addr, uint32_t value)
}
/**
- * Read an AP register value.
- * This is synchronous iff the mode is set to ATOMIC, in which
- * case any queued transactions are flushed.
+ * Asynchronous (queued) AP register eread.
*
* @param swjdp The DAP whose currently selected AP will be read.
* @param reg_addr Eight bit AP register address.
* @param value Points to where the 32-bit (little-endian) word will be stored.
*
- * @return In synchronous mode: ERROR_OK for success, and *value holds
- * the specified value; else a fault code. In asynchronous mode, a status
- * code reflecting whether the transaction was properly queued.
+ * @return ERROR_OK if the transaction was properly queued, else a fault code.
*/
int dap_ap_read_reg_u32(struct swjdp_common *swjdp,
uint32_t reg_addr, uint32_t *value)
if (retval != ERROR_OK)
return retval;
- return scan_inout_check_u32(swjdp, JTAG_DP_APACC, reg_addr,
+ return adi_jtag_scan_inout_check_u32(swjdp, JTAG_DP_APACC, reg_addr,
DPAP_READ, 0, value);
}
/**
- * Set up transfer parameters for the currently selected MEM-AP.
- * This is synchronous iff the mode is set to ATOMIC, in which
- * case any queued transactions are flushed.
+ * Queue transactions setting up transfer parameters for the
+ * currently selected MEM-AP.
*
* Subsequent transfers using registers like AP_REG_DRW or AP_REG_BD2
* initiate data reads or writes using memory or peripheral addresses.
* @param tar MEM-AP Transfer Address Register (TAR) to assign. If this
* matches the cached address, the register is not changed.
*
- * @return In synchronous mode: ERROR_OK for success, and the AP is set
- * up as requested else a fault code. In asynchronous mode, a status
- * code reflecting whether the transaction was properly queued.
+ * @return ERROR_OK if the transaction was properly queued, else a fault code.
*/
int dap_setup_accessport(struct swjdp_common *swjdp, uint32_t csw, uint32_t tar)
{
{
int retval;
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
/* Use banked addressing (REG_BDx) to avoid some link traffic
* (updating TAR) when reading several consecutive addresses.
*/
{
int retval;
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
/* Use banked addressing (REG_BDx) to avoid some link traffic
* (updating TAR) when writing several consecutive addresses.
*/
uint32_t adr = address;
uint8_t* pBuffer = buffer;
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
count >>= 2;
wcount = count;
int retval = ERROR_OK;
int wcount, blocksize, writecount, i;
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
wcount = count >> 1;
while (wcount > 0)
if (count >= 4)
return mem_ap_write_buf_packed_u16(swjdp, buffer, count, address);
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
while (count > 0)
{
dap_setup_accessport(swjdp, CSW_16BIT | CSW_ADDRINC_SINGLE, address);
int retval = ERROR_OK;
int wcount, blocksize, writecount, i;
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
wcount = count;
while (wcount > 0)
if (count >= 4)
return mem_ap_write_buf_packed_u8(swjdp, buffer, count, address);
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
while (count > 0)
{
dap_setup_accessport(swjdp, CSW_8BIT | CSW_ADDRINC_SINGLE, address);
uint32_t adr = address;
uint8_t* pBuffer = buffer;
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
count >>= 2;
wcount = count;
int retval = ERROR_OK;
int wcount, blocksize, readcount, i;
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
wcount = count >> 1;
while (wcount > 0)
if (count >= 4)
return mem_ap_read_buf_packed_u16(swjdp, buffer, count, address);
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
while (count > 0)
{
dap_setup_accessport(swjdp, CSW_16BIT | CSW_ADDRINC_SINGLE, address);
int retval = ERROR_OK;
int wcount, blocksize, readcount, i;
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
wcount = count;
while (wcount > 0)
if (count >= 4)
return mem_ap_read_buf_packed_u8(swjdp, buffer, count, address);
- swjdp->trans_mode = TRANS_MODE_COMPOSITE;
-
while (count > 0)
{
dap_setup_accessport(swjdp, CSW_8BIT | CSW_ADDRINC_SINGLE, address);
dap_ap_select(swjdp, 0);
/* DP initialization */
- swjdp->trans_mode = TRANS_MODE_ATOMIC;
dap_dp_read_reg(swjdp, &dummy, DP_CTRL_STAT);
dap_dp_write_reg(swjdp, SSTICKYERR, DP_CTRL_STAT);
dap_dp_read_reg(swjdp, &dummy, DP_CTRL_STAT);