Merge remote-tracking branch 'origin/review_usb_transaction'

This commit is contained in:
Gwenhael Goavec-Merou 2020-10-27 19:29:44 +01:00
commit 4dde89e082
4 changed files with 20 additions and 20 deletions

View File

@ -139,7 +139,8 @@ int FtdiJtagMPSSE::writeTMS(uint8_t *tms, int len, bool flush_buffer)
}
xfer -= bit_to_send;
}
mpsse_write();
if (flush_buffer)
mpsse_write();
if (_ch552WA) {
uint8_t c[len/8+1];
ftdi_read_data(_ftdi, c, len/8+1);
@ -166,9 +167,6 @@ int FtdiJtagMPSSE::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len)
buf[1] = ((len / 8) ) & 0xff;
buf[2] = ((len / 8) >> 8) & 0xff;
mpsse_store(buf, 3);
ret = mpsse_write();
if (ret < 0)
return ret;
len %= 8;
}
@ -176,16 +174,13 @@ int FtdiJtagMPSSE::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len)
buf[0] = 0x8E;
buf[1] = len - 1;
mpsse_store(buf, 2);
ret = mpsse_write();
if (ret < 0)
return ret;
}
ret = clk_len;
} else {
int byteLen = (len+7)/8;
uint8_t buf_tms[byteLen];
memset(buf_tms, (tms) ? 0xff : 0x00, byteLen);
ret = writeTMS(buf_tms, len, true);
ret = writeTMS(buf_tms, len, false);
}
return ret;
@ -221,6 +216,9 @@ int FtdiJtagMPSSE::writeTDI(uint8_t *tdi, uint8_t *tdo, uint32_t len, bool last)
display("%s len : %d %d %d %d\n", __func__, len, real_len, nb_byte,
nb_bit);
if ((nb_byte + _num + 3) > _buffer_size)
mpsse_write();
if ((nb_byte * 8) + nb_bit != real_len) {
printf("pas cool\n");
throw std::exception();

View File

@ -50,8 +50,8 @@ class FTDIpp_MPSSE {
int _clkHZ;
struct ftdi_context *_ftdi;
int _buffer_size;
private:
int _num;
private:
unsigned char *_buffer;
};

View File

@ -139,15 +139,15 @@ void Gowin::programFlash()
wr_rd(NOOP, NULL, 0, NULL, 0);
/* wait for reload */
usleep(150*1000);
usleep(2*150*1000);
/* check if file checksum == checksum in FPGA */
status = readUserCode();
if (_fs->checksum() != status) {
printError("SRAM Flash: FAIL");
printError("CRC check : FAIL");
printf("%04x %04x\n", _fs->checksum(), status);
} else
printSuccess("SRAM Flash: Success");
printSuccess("CRC check: Success");
if (_verbose)
displayReadReg(readStatusReg());
@ -265,6 +265,7 @@ bool Gowin::wr_rd(uint8_t cmd,
if (rx || tx) {
_jtag->shiftDR(xfer_tx, (rx) ? xfer_rx : NULL, 8 * xfer_len);
_jtag->toggleClk(6);
_jtag->flush();
}
if (rx) {
if (verbose) {
@ -375,7 +376,7 @@ bool Gowin::flashFLASH(uint8_t *data, int length)
memcpy(buffer+6*4, data, byte_length);
ProgressBar progress("Flash SRAM", buffer_length, 50);
ProgressBar progress("write Flash", buffer_length, 50);
for (int i=0, xpage=0; xpage < nb_xpage; i+=(nb_iter*4), xpage++) {
wr_rd(CONFIG_ENABLE, NULL, 0, NULL, 0);

View File

@ -132,6 +132,7 @@ int Jtag::detectChain(vector<int> &devices, int max_dev)
devices.push_back(tmp);
}
go_test_logic_reset();
flushTMS(true);
return devices.size();
}
@ -139,7 +140,7 @@ void Jtag::setTMS(unsigned char tms)
{
display("%s %x %d %d\n", __func__, tms, _num_tms, (_num_tms >> 3));
if (_num_tms+1 == _tms_buffer_size * 8)
flushTMS();
flushTMS(false);
if (tms != 0)
_tms_buffer[_num_tms>>3] |= (0x1) << (_num_tms & 0x7);
_num_tms++;
@ -175,13 +176,13 @@ void Jtag::go_test_logic_reset()
/* idenpendly to current state 5 clk with TMS high is enough */
for (int i = 0; i < 6; i++)
setTMS(0x01);
flushTMS(true);
flushTMS(false);
_state = TEST_LOGIC_RESET;
}
int Jtag::read_write(unsigned char *tdi, unsigned char *tdo, int len, char last)
{
flushTMS(true);
flushTMS(false);
_jtag->writeTDI(tdi, tdo, len, last);
if (last == 1)
_state = (_state == SHIFT_DR) ? EXIT1_DR : EXIT1_IR;
@ -191,7 +192,7 @@ int Jtag::read_write(unsigned char *tdi, unsigned char *tdo, int len, char last)
void Jtag::toggleClk(int nb)
{
unsigned char c = (TEST_LOGIC_RESET == _state) ? 1 : 0;
flushTMS(true);
flushTMS(false);
if (_jtag->toggleClk(c, 0, nb) >= 0)
return;
throw std::exception();
@ -202,7 +203,7 @@ int Jtag::shiftDR(unsigned char *tdi, unsigned char *tdo, int drlen, int end_sta
{
set_state(SHIFT_DR);
// force transmit tms state
flushTMS(true);
flushTMS(false);
// currently don't care about multiple device in the chain
read_write(tdi, tdo, drlen, 1);// 1 since only one device
@ -223,7 +224,7 @@ int Jtag::shiftIR(unsigned char *tdi, unsigned char *tdo, int irlen, int end_sta
{
display("%s: avant shiftIR\n", __func__);
set_state(SHIFT_IR);
flushTMS(true);
flushTMS(false);
// currently don't care about multiple device in the chain
display("%s: envoi ircode\n", __func__);
@ -421,7 +422,7 @@ void Jtag::set_state(int newState)
_tms_buffer[(_num_tms-1) / 8]);
}
/* force write buffer */
flushTMS();
flushTMS(false);
}
const char *Jtag::getStateName(tapState_t s)