X-Git-Url: http://developer.intra2net.com/git/?a=blobdiff_plain;f=src%2Fftdi_stream.c;h=7a8c1407b590768ab249662ab84241cb4515d526;hb=1ec530dc7a8f5720c263226ac43548ecc027e33e;hp=d39fc2a2cde61bb46936880634c4a083fe84f3e3;hpb=97c6b5f63d77f28968f4ad19c6901f11598898c9;p=libftdi diff --git a/src/ftdi_stream.c b/src/ftdi_stream.c index d39fc2a..7a8c140 100644 --- a/src/ftdi_stream.c +++ b/src/ftdi_stream.c @@ -73,7 +73,7 @@ ftdi_readstream_cb(struct libusb_transfer *transfer) uint8_t *ptr = transfer->buffer; int length = transfer->actual_length; int numPackets = (length + packet_size - 1) / packet_size; - int res; + int res = 0; for (i = 0; i < numPackets; i++) { @@ -152,8 +152,28 @@ ftdi_readstream(struct ftdi_context *ftdi, int bufferSize = packetsPerTransfer * ftdi->max_packet_size; int xferIndex; int err = 0; + + /* Only FT2232H and FT232H know about the synchronous FIFO Mode*/ + if ((ftdi->type != TYPE_2232H) && (ftdi->type != TYPE_232H)) + { + fprintf(stderr,"Device doesn't support synchronous FIFO mode\n"); + return 1; + } - fprintf(stderr, "ftdi_readstream\n"); + /* We don't know in what state we are, switch to reset*/ + if (ftdi_set_bitmode(ftdi, 0xff, BITMODE_RESET) < 0) + { + fprintf(stderr,"Can't reset mode\n"); + return 1; + } + + /* Purge anything remaining in the buffers*/ + if (ftdi_usb_purge_buffers(ftdi) < 0) + { + fprintf(stderr,"Can't Purge\n"); + return 1; + } + /* * Set up all transfers */