libftdi/jtagtap.c: Allow NULL as one DI/DO argument jtagtap_tdi_tdo_seq.

Implement jtagtap_tdi_seq() by calling jtagtap_tdi_tdo_seq().
This commit is contained in:
Uwe Bonnes 2018-04-29 13:50:29 +02:00
parent de33473535
commit 2ec078cfcf
1 changed files with 42 additions and 65 deletions

View File

@ -94,97 +94,74 @@ jtagtap_tms_seq(uint32_t MS, int ticks)
}
}
void
jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks)
{
int rticks;
if(!ticks) return;
if(final_tms) ticks--;
rticks = ticks & 7;
ticks >>= 3;
uint8_t data[3];
if(ticks) {
data[0] = MPSSE_DO_WRITE | MPSSE_LSB | MPSSE_WRITE_NEG;
data[1] = ticks - 1;
data[2] = 0;
platform_buffer_write(data, 3);
platform_buffer_write(DI, ticks);
}
if(rticks) {
data[0] = MPSSE_DO_WRITE | MPSSE_LSB | MPSSE_BITMODE | MPSSE_WRITE_NEG;
data[1] = rticks - 1;
data[2] = DI[ticks];
platform_buffer_write(data, 3);
}
if(final_tms) {
data[0] = MPSSE_WRITE_TMS | MPSSE_LSB | MPSSE_BITMODE | MPSSE_WRITE_NEG;
data[1] = 0;
data[2] = (*DI)>>rticks?0x81:0x01;
platform_buffer_write(data, 3);
}
}
void
jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks)
{
int rsize, rticks;
if(!ticks) return;
if (!DI && !DO) return;
// printf("ticks: %d\n", ticks);
if(final_tms) ticks--;
rticks = ticks & 7;
ticks >>= 3;
uint8_t data[3];
uint8_t cmd = ((DO)? MPSSE_DO_READ : 0) | ((DI)? (MPSSE_DO_WRITE | MPSSE_WRITE_NEG) : 0) | MPSSE_LSB;
rsize = ticks;
if(ticks) {
data[0] = MPSSE_DO_READ | MPSSE_DO_WRITE | MPSSE_LSB | MPSSE_WRITE_NEG;
data[0] = cmd;
data[1] = ticks - 1;
data[2] = 0;
platform_buffer_write(data, 3);
platform_buffer_write(DI, ticks);
if (DI)
platform_buffer_write(DI, ticks);
}
if(rticks) {
int index = 0;
rsize++;
data[0] = MPSSE_DO_READ | MPSSE_DO_WRITE | MPSSE_LSB | MPSSE_BITMODE | MPSSE_WRITE_NEG;
data[1] = rticks - 1;
data[2] = DI[ticks];
platform_buffer_write(data, 3);
data[index++] = cmd | MPSSE_BITMODE;
data[index++] = rticks - 1;
if (DI)
data[index++] = DI[ticks];
platform_buffer_write(data, index);
}
if(final_tms) {
int index = 0;
rsize++;
data[0] = MPSSE_WRITE_TMS | MPSSE_DO_READ | MPSSE_LSB | MPSSE_BITMODE | MPSSE_WRITE_NEG;
data[1] = 0;
data[2] = (*DI)>>rticks?0x81:0x01;
platform_buffer_write(data, 3);
data[index++] = MPSSE_WRITE_TMS | ((DO)? MPSSE_DO_READ : 0) | MPSSE_LSB | MPSSE_BITMODE | MPSSE_WRITE_NEG;
data[index++] = 0;
if (DI)
data[index++] = (*DI)>>rticks?0x81:0x01;
platform_buffer_write(data, index);
}
uint8_t *tmp = alloca(ticks);
int index = 0;
platform_buffer_read(tmp, rsize);
if(final_tms) rsize--;
if (DO) {
int index = 0;
uint8_t *tmp = alloca(ticks);
platform_buffer_read(tmp, rsize);
if(final_tms) rsize--;
while(rsize--) {
/*if(rsize) printf("%02X ", tmp[index]);*/
*DO++ = tmp[index++];
while(rsize--) {
/*if(rsize) printf("%02X ", tmp[index]);*/
*DO++ = tmp[index++];
}
if (rticks == 0)
*DO++ = 0;
if(final_tms) {
rticks++;
*(--DO) >>= 1;
*DO |= tmp[index] & 0x80;
} else DO--;
if(rticks) {
*DO >>= (8-rticks);
}
/*printf("%02X\n", *DO);*/
}
if (rticks == 0)
*DO++ = 0;
if(final_tms) {
rticks++;
*(--DO) >>= 1;
*DO |= tmp[index] & 0x80;
} else DO--;
if(rticks) {
*DO >>= (8-rticks);
}
/*printf("%02X\n", *DO);*/
}
void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks)
{
return jtagtap_tdi_tdo_seq(NULL, final_tms, DI, ticks);
}
uint8_t jtagtap_next(uint8_t dTMS, uint8_t dTDI)