Improve FTDI communication in bitbang mode

sub layer cut package in allowed size, so it's not mandatory to do this
at openFPGALoader level. The only situation when the size is important
is in read mode. So increase buffer size to reduce system calls.
This commit is contained in:
Gwenhael Goavec-Merou 2020-10-29 08:15:32 +01:00
parent e0a5d376ba
commit 88c6b2ff6d
2 changed files with 29 additions and 8 deletions

View File

@ -23,6 +23,7 @@
#include <map>
#include <vector>
#include <string>
#include <stdexcept>
#include "ftdiJtagBitbang.hpp"
#include "ftdipp_mpsse.hpp"
@ -44,18 +45,38 @@ FtdiJtagBitBang::FtdiJtagBitBang(const FTDIpp_MPSSE::mpsse_bit_config &cable,
const jtag_pins_conf_t *pin_conf, string dev, const std::string &serial,
uint32_t clkHZ, bool verbose):
FTDIpp_MPSSE(cable, dev, serial, clkHZ, verbose), _bitmode(0),
_curr_tms(0)
_curr_tms(0), _rx_size(0)
{
unsigned char *ptr;
_tck_pin = (1 << pin_conf->tck_pin);
_tms_pin = (1 << pin_conf->tms_pin);
_tdi_pin = (1 << pin_conf->tdi_pin);
_tdo_pin = (1 << pin_conf->tdo_pin);
_buffer_size = 512; // TX Fifo size
/* store FTDI TX Fifo size */
if (_pid == 0x6001) // FT232R
_rx_size = 256;
else if (_pid == 0x6015) // FT231X
_rx_size = 512;
else
_rx_size = _buffer_size;
/* RX Fifo size (rx: USB -> FTDI)
* is 128 or 256 Byte and MaxPacketSize ~= 64Byte
* but we let subsystem (libftdi, libusb, linux)
* sending with the correct size -> this reduce hierarchical calls
*/
_buffer_size = 4096;
/* _buffer_size has changed -> resize buffer */
ptr = (unsigned char *)realloc(_buffer, sizeof(char) * _buffer_size);
if (!ptr)
throw std::runtime_error("_buffer realloc failed\n");
_buffer = ptr;
setClkFreq(_clkHZ);
_buffer = (unsigned char *)realloc(_buffer, sizeof(char) * _buffer_size);
init(1, _tck_pin | _tms_pin | _tdi_pin, BITMODE_BITBANG);
setBitmode(BITMODE_BITBANG);
}
@ -134,10 +155,11 @@ int FtdiJtagBitBang::writeTMS(uint8_t *tms, int len, bool flush_buffer)
int FtdiJtagBitBang::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
{
uint32_t iter;
if (len * 2 + 1 < (uint32_t)_buffer_size) {
uint32_t xfer_size = (rx) ? _rx_size : _buffer_size;
if (len * 2 + 1 < xfer_size) {
iter = len;
} else {
iter = _buffer_size >> 1; // two tx / bit
iter = xfer_size >> 1; // two tx / bit
iter = (iter / 8) * 8;
}

View File

@ -58,21 +58,20 @@ class FtdiJtagBitBang : public JtagInterface, private FTDIpp_MPSSE {
*/
int get_buffer_size() override { return _buffer_size/8/2; }
bool isFull() override { return _nb_bit == 8*get_buffer_size();}
bool isFull() override { return _num == 8*get_buffer_size();}
int flush() override;
private:
int write(uint8_t *tdo, int nb_bit);
int setBitmode(uint8_t mode);
uint8_t *_in_buf;
uint8_t _bitmode;
uint8_t _tck_pin; /*!< tck pin: 1 << pin id */
uint8_t _tms_pin; /*!< tms pin: 1 << pin id */
uint8_t _tdo_pin; /*!< tdo pin: 1 << pin id */
uint8_t _tdi_pin; /*!< tdi pin: 1 << pin id */
int _nb_bit;
uint8_t _curr_tms;
int _rx_size;
};
#endif