diff --git a/src/platforms/hosted/bmp_remote.c b/src/platforms/hosted/bmp_remote.c index b12f5ae..47abab8 100644 --- a/src/platforms/hosted/bmp_remote.c +++ b/src/platforms/hosted/bmp_remote.c @@ -345,7 +345,7 @@ void remote_adiv5_dp_defaults(ADIv5_DP_t *dp) "Please update BMP firmware for substantial speed increase!\n"); return; } - if (dp->dev) { + if (dp->dp_jd_index < JTAG_MAX_DEVS) { DEBUG_WARN("Falling back to ll as high level JTAG is not yet possible!\n"); return; } diff --git a/src/platforms/hosted/dap.c b/src/platforms/hosted/dap.c index a2d6e1c..03844d1 100644 --- a/src/platforms/hosted/dap.c +++ b/src/platforms/hosted/dap.c @@ -339,8 +339,7 @@ uint32_t dap_read_reg(ADIv5_DP_t *dp, uint8_t reg) { uint8_t buf[8]; uint8_t dap_index = 0; - if (dp->dev) - dap_index = dp->dev->jd_dev; + dap_index = dp->dp_jd_index; buf[0] = ID_DAP_TRANSFER; buf[1] = dap_index; buf[2] = 0x01; // Request size @@ -358,8 +357,7 @@ void dap_write_reg(ADIv5_DP_t *dp, uint8_t reg, uint32_t data) buf[0] = ID_DAP_TRANSFER; uint8_t dap_index = 0; - if (dp->dev) - dap_index = dp->dev->jd_dev; + dap_index = dp->dp_jd_index; buf[1] = dap_index; buf[2] = 0x01; // Request size buf[3] = reg & ~DAP_TRANSFER_RnW;; @@ -390,8 +388,7 @@ unsigned int dap_read_block(ADIv5_AP_t *ap, void *dest, uint32_t src, uint8_t buf[1024]; unsigned int sz = len >> align; uint8_t dap_index = 0; - if (ap->dp->dev) - dap_index = ap->dp->dev->jd_dev; + dap_index = ap->dp->dp_jd_index; buf[0] = ID_DAP_TRANSFER_BLOCK; buf[1] = dap_index; buf[2] = sz & 0xff; @@ -426,8 +423,7 @@ unsigned int dap_write_block(ADIv5_AP_t *ap, uint32_t dest, const void *src, uint8_t buf[1024]; unsigned int sz = len >> align; uint8_t dap_index = 0; - if (ap->dp->dev) - dap_index = ap->dp->dev->jd_dev; + dap_index = ap->dp->dp_jd_index; buf[0] = ID_DAP_TRANSFER_BLOCK; buf[1] = dap_index; buf[2] = sz & 0xff; @@ -527,8 +523,7 @@ static uint8_t *mem_access_setup(ADIv5_AP_t *ap, uint8_t *p, break; } uint8_t dap_index = 0; - if (ap->dp->dev) - dap_index = ap->dp->dev->jd_dev; + dap_index = ap->dp->dp_jd_index; *p++ = ID_DAP_TRANSFER; *p++ = dap_index; *p++ = 3; /* Nr transfers */ @@ -563,8 +558,7 @@ uint32_t dap_ap_read(ADIv5_AP_t *ap, uint16_t addr) uint8_t buf[63], *p = buf; buf[0] = ID_DAP_TRANSFER; uint8_t dap_index = 0; - if (ap->dp->dev) - dap_index = ap->dp->dev->jd_dev; + dap_index = ap->dp->dp_jd_index; *p++ = ID_DAP_TRANSFER; *p++ = dap_index; *p++ = 2; /* Nr transfers */ @@ -584,8 +578,7 @@ void dap_ap_write(ADIv5_AP_t *ap, uint16_t addr, uint32_t value) DEBUG_PROBE("dap_ap_write addr %04x value %08x\n", addr, value); uint8_t buf[63], *p = buf; uint8_t dap_index = 0; - if (ap->dp->dev) - dap_index = ap->dp->dev->jd_dev; + dap_index = ap->dp->dp_jd_index; *p++ = ID_DAP_TRANSFER; *p++ = dap_index; *p++ = 2; /* Nr transfers */ diff --git a/src/platforms/hosted/stlinkv2.c b/src/platforms/hosted/stlinkv2.c index fce2fbc..42941c8 100644 --- a/src/platforms/hosted/stlinkv2.c +++ b/src/platforms/hosted/stlinkv2.c @@ -1047,7 +1047,7 @@ int jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens) if((jtag_devs[i].jd_idcode & dev_descr[j].idmask) == dev_descr[j].idcode) { if(dev_descr[j].handler) - dev_descr[j].handler(&jtag_devs[i]); + dev_descr[j].handler(i, dev_descr[j].idcode); break; } diff --git a/src/target/adiv5.h b/src/target/adiv5.h index 39d4d5a..ee296d3 100644 --- a/src/target/adiv5.h +++ b/src/target/adiv5.h @@ -174,15 +174,8 @@ typedef struct ADIv5_DP_s { void (*mem_read)(ADIv5_AP_t *ap, void *dest, uint32_t src, size_t len); void (*mem_write_sized)(ADIv5_AP_t *ap, uint32_t dest, const void *src, size_t len, enum align align); -#if PC_HOSTED == 1 - jtag_dev_t *dev; + uint8_t dp_jd_index; uint8_t fault; -#else - union { - jtag_dev_t *dev; - uint8_t fault; - }; -#endif } ADIv5_DP_t; struct ADIv5_AP_s { @@ -270,7 +263,7 @@ ADIv5_AP_t *adiv5_new_ap(ADIv5_DP_t *dp, uint8_t apsel); void adiv5_ap_ref(ADIv5_AP_t *ap); void adiv5_ap_unref(ADIv5_AP_t *ap); -void adiv5_jtag_dp_handler(jtag_dev_t *dev); +void adiv5_jtag_dp_handler(uint8_t jd_index, uint32_t j_idcode); int platform_jtag_dp_init(ADIv5_DP_t *dp); void adiv5_mem_write(ADIv5_AP_t *ap, uint32_t dest, const void *src, size_t len); diff --git a/src/target/adiv5_jtagdp.c b/src/target/adiv5_jtagdp.c index 9b02bbe..12dad85 100644 --- a/src/target/adiv5_jtagdp.c +++ b/src/target/adiv5_jtagdp.c @@ -41,7 +41,7 @@ static uint32_t adiv5_jtagdp_error(ADIv5_DP_t *dp); static void adiv5_jtagdp_abort(ADIv5_DP_t *dp, uint32_t abort); -void adiv5_jtag_dp_handler(jtag_dev_t *dev) +void adiv5_jtag_dp_handler(uint8_t jd_index, uint32_t j_idcode) { ADIv5_DP_t *dp = (void*)calloc(1, sizeof(*dp)); if (!dp) { /* calloc failed: heap exhaustion */ @@ -49,9 +49,9 @@ void adiv5_jtag_dp_handler(jtag_dev_t *dev) return; } - dp->dev = dev; + dp->dp_jd_index = jd_index; if ((PC_HOSTED == 0 ) || (!platform_jtag_dp_init(dp))) { - dp->idcode = dev->jd_idcode; + dp->idcode = j_idcode; dp->dp_read = fw_adiv5_jtagdp_read; dp->error = adiv5_jtagdp_error; dp->low_access = fw_adiv5_jtagdp_low_access; @@ -85,11 +85,11 @@ uint32_t fw_adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, request = ((uint64_t)value << 3) | ((addr >> 1) & 0x06) | (RnW?1:0); - jtag_dev_write_ir(&jtag_proc, dp->dev, APnDP ? IR_APACC : IR_DPACC); + jtag_dev_write_ir(&jtag_proc, dp->dp_jd_index, APnDP ? IR_APACC : IR_DPACC); platform_timeout_set(&timeout, 2000); do { - jtag_dev_shift_dr(&jtag_proc, dp->dev, (uint8_t*)&response, + jtag_dev_shift_dr(&jtag_proc, dp->dp_jd_index, (uint8_t*)&response, (uint8_t*)&request, 35); ack = response & 0x07; } while(!platform_timeout_is_expired(&timeout) && (ack == JTAGDP_ACK_WAIT)); @@ -106,6 +106,6 @@ uint32_t fw_adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, static void adiv5_jtagdp_abort(ADIv5_DP_t *dp, uint32_t abort) { uint64_t request = (uint64_t)abort << 3; - jtag_dev_write_ir(&jtag_proc, dp->dev, IR_ABORT); - jtag_dev_shift_dr(&jtag_proc, dp->dev, NULL, (const uint8_t*)&request, 35); + jtag_dev_write_ir(&jtag_proc, dp->dp_jd_index, IR_ABORT); + jtag_dev_shift_dr(&jtag_proc, dp->dp_jd_index, NULL, (const uint8_t*)&request, 35); } diff --git a/src/target/adiv5_swdp.c b/src/target/adiv5_swdp.c index eba7cab..457b35f 100644 --- a/src/target/adiv5_swdp.c +++ b/src/target/adiv5_swdp.c @@ -39,6 +39,7 @@ int adiv5_swdp_scan(void) target_list_free(); ADIv5_DP_t *dp = (void*)calloc(1, sizeof(*dp)); + dp->dp_jd_index = JTAG_MAX_DEVS; /* Tag for BMP_REMOTE */ if (!dp) { /* calloc failed: heap exhaustion */ DEBUG_WARN("calloc: failed in %s\n", __func__); return -1; diff --git a/src/target/jtag_devs.h b/src/target/jtag_devs.h index 47d17d0..8c2c0b5 100644 --- a/src/target/jtag_devs.h +++ b/src/target/jtag_devs.h @@ -22,7 +22,7 @@ typedef const struct jtag_dev_descr_s { const uint32_t idcode; const uint32_t idmask; const char * const descr; - void (*const handler)(jtag_dev_t *dev); + void (*const handler)(uint8_t jd_index, uint32_t j_idcode); } jtag_dev_descr_t; extern jtag_dev_descr_t dev_descr[]; diff --git a/src/target/jtag_scan.c b/src/target/jtag_scan.c index 69114d4..90843f5 100644 --- a/src/target/jtag_scan.c +++ b/src/target/jtag_scan.c @@ -188,15 +188,16 @@ int jtag_scan(const uint8_t *irlens) jtag_devs[i].jd_descr = dev_descr[j].descr; /* Call handler to initialise/probe device further */ if(dev_descr[j].handler) - dev_descr[j].handler(&jtag_devs[i]); + dev_descr[j].handler(i, dev_descr[j].idcode); break; } return jtag_dev_count; } -void jtag_dev_write_ir(jtag_proc_t *jp, jtag_dev_t *d, uint32_t ir) +void jtag_dev_write_ir(jtag_proc_t *jp, uint8_t jd_index, uint32_t ir) { + jtag_dev_t *d = &jtag_devs[jd_index]; if(ir == d->current_ir) return; for(int i = 0; i < jtag_dev_count; i++) jtag_devs[i].current_ir = -1; @@ -209,8 +210,9 @@ void jtag_dev_write_ir(jtag_proc_t *jp, jtag_dev_t *d, uint32_t ir) jtagtap_return_idle(); } -void jtag_dev_shift_dr(jtag_proc_t *jp, jtag_dev_t *d, uint8_t *dout, const uint8_t *din, int ticks) +void jtag_dev_shift_dr(jtag_proc_t *jp, uint8_t jd_index, uint8_t *dout, const uint8_t *din, int ticks) { + jtag_dev_t *d = &jtag_devs[jd_index]; jtagtap_shift_dr(); jp->jtagtap_tdi_seq(0, ones, d->dr_prescan); if(dout) diff --git a/src/target/jtag_scan.h b/src/target/jtag_scan.h index 30ced85..8089668 100644 --- a/src/target/jtag_scan.h +++ b/src/target/jtag_scan.h @@ -43,8 +43,8 @@ typedef struct jtag_dev_s { extern struct jtag_dev_s jtag_devs[JTAG_MAX_DEVS+1]; extern int jtag_dev_count; -void jtag_dev_write_ir(jtag_proc_t *jp, jtag_dev_t *dev, uint32_t ir); -void jtag_dev_shift_dr(jtag_proc_t *jp, jtag_dev_t *dev, uint8_t *dout, const uint8_t *din, int ticks); +void jtag_dev_write_ir(jtag_proc_t *jp, uint8_t jd_index, uint32_t ir); +void jtag_dev_shift_dr(jtag_proc_t *jp, uint8_t jd_index, uint8_t *dout, const uint8_t *din, int ticks); #endif