void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks) { char *tmp; int index = 0; int rticks; if(!ticks) return; if(final_tms) ticks--; rticks = ticks & 7; ticks >>= 3; tmp = alloca(ticks + 9); if(ticks) { tmp[index++] = 0x19; tmp[index++] = ticks - 1; tmp[index++] = 0; while(ticks--) tmp[index++] = *DI++; } if(rticks) { tmp[index++] = 0x1B; tmp[index++] = rticks - 1; tmp[index++] = *DI; } if(final_tms) { tmp[index++] = 0x4B; tmp[index++] = 0; tmp[index++] = (*DI)>>rticks?0x81:0x01; } // assert(ftdi_write_data(ftdic, tmp, index) == index); platform_buffer_write(tmp, index); }
static void swdptap_set_bits(void) { uint8_t cmd[] = { SET_BITS_LOW, swdptap_outputs & 0xff, swdptap_direction & 0xff, SET_BITS_HIGH, (swdptap_outputs >> 8) & 0xff, (swdptap_direction >> 8) & 0xff }; platform_buffer_write(cmd, sizeof(cmd)); }
void jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks) { uint8_t *tmp; int index = 0, rsize; int rticks; if(!ticks) return; // printf("ticks: %d\n", ticks); if(final_tms) ticks--; rticks = ticks & 7; ticks >>= 3; tmp = alloca(ticks + 9); rsize = ticks; if(ticks) { tmp[index++] = 0x39; tmp[index++] = ticks - 1; tmp[index++] = 0; while(ticks--) tmp[index++] = *DI++; } if(rticks) { rsize++; tmp[index++] = 0x3B; tmp[index++] = rticks - 1; tmp[index++] = *DI; } if(final_tms) { rsize++; tmp[index++] = 0x6B; tmp[index++] = 0; tmp[index++] = (*DI)>>rticks?0x81:0x01; } // assert(ftdi_write_data(ftdic, tmp, index) == index); platform_buffer_write(tmp, index); // index = 0; // while((index += ftdi_read_data(ftdic, tmp + index, rsize-index)) != rsize); platform_buffer_read(tmp, rsize); /*for(index = 0; index < rsize; index++) printf("%02X ", tmp[index]); printf("\n");*/ index = 0; if(final_tms) rsize--; while(rsize--) { /*if(rsize) printf("%02X ", tmp[index]);*/ *DO++ = tmp[index++]; } if(final_tms) { rticks++; *(--DO) >>= 1; *DO |= tmp[index] & 0x80; } else DO--;
uint32_t swdptap_seq_in(int ticks) { uint8_t buf[] = { MPSSE_DO_READ | MPSSE_LSB, 0, /* len - 1 low */ 0 /* len - 1 high (always 0) */ }; assert(ticks <= 32); /* DEBUG("seq_in %d\n", ticks); */ swdptap_turnaround(1); if (ticks >= 8) { buf[1] = ticks / 8 - 1; platform_buffer_write(buf, sizeof(buf)); } if (ticks % 8) { buf[0] |= MPSSE_BITMODE; buf[1] = ticks % 8 - 1; platform_buffer_write(buf, 2); } uint8_t res[4] = {0}; /* max 32 bits */ platform_buffer_read(res, (ticks + 7) / 8); uint32_t ret = 0; for (int msb = ticks / 8 - 1; msb >= 0; --msb) ret = (ret << 8) | res[msb]; int bits_remaining = ticks % 8; ret |= (res[ticks / 8] >> /* remaining byte */ (8 - bits_remaining)) /* bits come in from MSB */ << (ticks - bits_remaining); /* move them to the top */ /* DEBUG(" read: %08x\n", ret); */ return (ret); }
void swdptap_bit_out(uint8_t val) { uint8_t buf[3] = "\xA0\xA1\xA0"; //DEBUG("%d", val); if(val) { for(int i = 0; i < 3; i++) buf[i] |= 0x08; } //ftdi_write_data(ftdic, buf, 3); platform_buffer_write(buf, 3); }
void jtagtap_tms_seq(uint32_t MS, int ticks) { uint8_t tmp[3] = "\x4B"; while(ticks >= 0) { //jtagtap_next(MS & 1, 1); tmp[1] = ticks<7?ticks-1:6; tmp[2] = 0x80 | (MS & 0x7F); // assert(ftdi_write_data(ftdic, tmp, 3) == 3); platform_buffer_write(tmp, 3); MS >>= 7; ticks -= 7; } }
static void swdptap_init_internal(void) { int err; if((err = ftdi_set_bitmode(ftdic, 0, BITMODE_RESET)) || (err = ftdi_set_bitmode(ftdic, 0, BITMODE_MPSSE))) { fprintf(stderr, "ftdi_set_bitmode: %d: %s\n", err, ftdi_get_error_string(ftdic)); abort(); } uint8_t setup[] = { DIS_DIV_5, TCK_DIVISOR, 0, 1, LOOPBACK_END }; platform_buffer_write(setup, sizeof(setup)); swdptap_set_bits(); platform_buffer_flush(); }