Skip to content

Commit 105cebb

Browse files
committed
patch #9327: ft245r.c: add TPI support (patches 1-4)
Submitted by David Mosberger-Tang: Optimize TPI programming speed by reducing number of USB reads. Specifically, when writing to the FTDI chip (without needing the data it accumulates), simply increment a count of how many bytes the next read should ignore. Thus, if there is one or more write followed by a read, we only need to read from the device once. Improves TPI programming speed by another factor of 2. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1485 81a1dc3b-b13d-400b-aceb-764788c761c2
1 parent 7ff5652 commit 105cebb

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2021-11-24 Joerg Wunsch <[email protected]>
2+
3+
Submitted by David Mosberger-Tang:
4+
patch #9327: ft245r.c: add TPI support (patches 1-4)
5+
* ft245r.c (ft245r_recv): Optimize TPI programming
6+
speed by reducing number of USB reads.
7+
18
2021-11-24 Joerg Wunsch <[email protected]>
29

310
Submitted by David Mosberger-Tang:

ft245r.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ static pthread_t readerthread;
161161
static sem_t buf_data, buf_space;
162162
static unsigned char buffer[BUFSIZE];
163163
static int head, tail;
164+
static struct {
165+
int discard; // # of bytes to discard during read
166+
} rx;
164167

165168
static void add_to_buf (unsigned char c) {
166169
int nh;
@@ -206,15 +209,24 @@ static int ft245r_send(PROGRAMMER * pgm, unsigned char * buf, size_t len) {
206209
return 0;
207210
}
208211

212+
static int ft245r_send_and_discard(PROGRAMMER * pgm, unsigned char * buf,
213+
size_t len) {
214+
rx.discard += len;
215+
return ft245r_send(pgm, buf, len);
216+
}
217+
209218
static int ft245r_recv(PROGRAMMER * pgm, unsigned char * buf, size_t len) {
210-
int i;
219+
int i = 0;
211220

212221
// Copy over data from the circular buffer..
213222
// XXX This should timeout, and return error if there isn't enough
214223
// data.
215-
for (i=0; i<len; i++) {
224+
while (i < len) {
216225
sem_wait (&buf_data);
217-
buf[i] = buffer[tail];
226+
if (rx.discard > 0)
227+
--rx.discard;
228+
else
229+
buf[i++] = buffer[tail];
218230
if (tail == (BUFSIZE -1)) tail = 0;
219231
else tail++;
220232
sem_post (&buf_space);
@@ -645,8 +657,7 @@ static int ft245r_tpi_tx(PROGRAMMER * pgm, uint8_t byte) {
645657
int len;
646658

647659
len = set_tpi_data(pgm, buf, byte);
648-
ft245r_send(pgm, buf, len);
649-
ft245r_recv(pgm, buf, len);
660+
ft245r_send_and_discard(pgm, buf, len);
650661
return 0;
651662
}
652663

0 commit comments

Comments
 (0)