Skip to content

Commit

Permalink
jAER: update USBTransferThread to 0.9.2.
Browse files Browse the repository at this point in the history
Fix lockup on exceptional USB shutdown (device unplugged while running) with libusb hardware interfaces.


git-svn-id: https://svn.code.sf.net/p/jaer/code/jAER/trunk@5958 b7f4320f-462c-0410-a916-d9f35bb82d52
  • Loading branch information
llongi committed Jan 23, 2015
1 parent 93a369e commit 58bd8c3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<classpathentry kind="lib" path="jars/jblas-1.2.3.jar"/>
<classpathentry kind="lib" path="jars/JEvtLearn.jar"/>
<classpathentry kind="lib" path="jars/uncommons-maths-1.2.3.jar"/>
<classpathentry kind="lib" path="jars/USBTransferThread-0.9.1.jar"/>
<classpathentry kind="lib" path="jars/USBTransferThread-0.9.2.jar"/>
<classpathentry kind="lib" path="jars/usb4java/libusb4java-1.2.0-linux-arm.jar"/>
<classpathentry kind="lib" path="jars/usb4java/libusb4java-1.2.0-linux-x86_64.jar"/>
<classpathentry kind="lib" path="jars/usb4java/libusb4java-1.2.0-linux-x86.jar"/>
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion jars/libs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ svgSalamander-tiny - downloaded on 2013-07-13 - https://svgsalamander.java.net/
swing-layout - 1.0.4 - NetBeans IDE
usb4java - 1.2.0 - https://github.com/usb4java/usb4java/
UsbIoJava - ??? - http://www.thesycon.de/eng/usbio.shtml
USBTransferThread - 0.9.1 - https://github.com/llongi/USBTransferThread/
USBTransferThread - 0.9.2 - https://github.com/llongi/USBTransferThread/
4 changes: 2 additions & 2 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ file.reference.swing-layout-1.0.4.jar=jars/swing-layout-1.0.4.jar
file.reference.uncommons-maths-1.2.3.jar=jars/uncommons-maths-1.2.3.jar
file.reference.usb4java-1.2.0.jar=jars/usb4java/usb4java-1.2.0.jar
file.reference.UsbIoJava.jar-1=jars/UsbIoJava.jar
file.reference.USBTransferThread-0.9.1.jar=jars/USBTransferThread-0.9.1.jar
file.reference.USBTransferThread-0.9.2.jar=jars/USBTransferThread-0.9.2.jar
includes=**
jar.archive.disabled=${jnlp.enabled}
jar.index=${jnlp.enabled}
Expand Down Expand Up @@ -72,7 +72,7 @@ file.reference.java-src=src
jar.compress=true
javac.classpath=\
${file.reference.JEvtLearn.jar}:\
${file.reference.USBTransferThread-0.9.1.jar}:\
${file.reference.USBTransferThread-0.9.2.jar}:\
${file.reference.UsbIoJava.jar-1}:\
${file.reference.ant.jar}:\
${file.reference.betterbeansbinding-1.3.0-all.jar}:\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,16 @@
* normally be constructed but rather a subclass that overrides
* the AEReader should be used.
* <p>
* In this class, you can also set the size of the host buffer with
* {@link #setAEBufferSize}, giving you more time between calls to process the
* events.
* In this class, you can also set the size of the host buffer with {@link #setAEBufferSize}, giving you more time
* between calls to process the events.
* <p>
* On the device, a timer sends all available events approximately every 10ms --
* you don't need to wait for a fixed size buffer to be captured to be available
* to the host. But if events come quickly enough, new events can be available
* On the device, a timer sends all available events approximately every 10ms -- you don't need to wait for a fixed size
* buffer to be captured to be available to the host. But if events come quickly enough, new events can be available
* much faster than this.
* <p>
* You can also request at any time an early transfer of events with
* {@link #requestEarlyTransfer}. This will send a vendor request to the device
* to immediately transfer available events, but they won't be available to the
* host for a little while, depending on USBIOInterface and driver latency.
* You can also request at any time an early transfer of events with {@link #requestEarlyTransfer}. This will send a
* vendor request to the device to immediately transfer available events, but they won't be available to the host for a
* little while, depending on USBIOInterface and driver latency.
* <p>
* See the main() method for an example of use.
* <p>
Expand Down Expand Up @@ -360,8 +357,7 @@ public class CypressFX2 implements AEMonitorInterface, ReaderBufferControl, USBI
* default size of AE buffer for user processes. This is the buffer that is
* written by the hardware capture thread
* that holds events
* that have not yet been transferred via
* {@link #acquireAvailableEventsFromDriver} to another thread
* that have not yet been transferred via {@link #acquireAvailableEventsFromDriver} to another thread
*
* @see #acquireAvailableEventsFromDriver
* @see AEReader
Expand Down Expand Up @@ -957,8 +953,7 @@ synchronized public void downloadFirmwareHex(final String hexFileResourcePath) t
* @param listener
* the listener. It is called with a PropertyChangeEvent when new
* events
* are received by a call to
* {@link #acquireAvailableEventsFromDriver}.
* are received by a call to {@link #acquireAvailableEventsFromDriver}.
* These events may be accessed by calling {@link #getEvents}.
*/
@Override
Expand Down Expand Up @@ -996,8 +991,8 @@ public void startAEReader() throws HardwareInterfaceException {
* <p>
* This method also starts event acquisition if it is not running already.
*
* Not thread safe but does use the thread-safe swap() method of
* AEPacketRawPool to swap data with the acquisition thread.
* Not thread safe but does use the thread-safe swap() method of AEPacketRawPool to swap data with the acquisition
* thread.
*
* @return packet of events acquired.
* @throws HardwareInterfaceException
Expand Down Expand Up @@ -1099,8 +1094,7 @@ void computeEstimatedEventRate(final AEPacketRaw events) {
}

/**
* Returns the number of events acquired by the last call to
* {@link #acquireAvailableEventsFromDriver }
* Returns the number of events acquired by the last call to {@link #acquireAvailableEventsFromDriver }
*
* @return number of events acquired
*/
Expand Down Expand Up @@ -1180,15 +1174,13 @@ synchronized public void setLed(final boolean value) {
}

/**
* Is true if an overrun occured in the driver (>
* <code> AE_BUFFER_SIZE</code> events) during the period before the
* Is true if an overrun occured in the driver (> <code> AE_BUFFER_SIZE</code> events) during the period before the
* last time {@link #acquireAvailableEventsFromDriver } was called. This flag
* is cleared by {@link #acquireAvailableEventsFromDriver}, so you need to
* check it before you acquire the events.
* <p>
* If there is an overrun, the events grabbed are the most ancient; events
* after the overrun are discarded. The timestamps continue on but will
* probably be lagged behind what they should be.
* If there is an overrun, the events grabbed are the most ancient; events after the overrun are discarded. The
* timestamps continue on but will probably be lagged behind what they should be.
*
* @return true if there was an overrun.
*/
Expand Down Expand Up @@ -1532,7 +1524,12 @@ public void startThread() {

CypressFX2.log.info("Starting AEReader");
usbTransfer = new USBTransferThread(monitor.deviceHandle, (byte) 0x86, LibUsb.TRANSFER_TYPE_BULK,
new ProcessAEData(), getNumBuffers(), getFifoSize());
new ProcessAEData(), getNumBuffers(), getFifoSize(), null, null, new Runnable() {
@Override
public void run() {
monitor.close();
}
});
usbTransfer.setPriority(AEReader.MONITOR_PRIORITY);
usbTransfer.setName("AEReaderThread");
usbTransfer.start();
Expand Down Expand Up @@ -1633,9 +1630,6 @@ public void processTransfer(final RestrictedTransfer transfer) {
else {
CypressFX2.log.warning("ProcessAEData: Bytes transferred: " + transfer.actualLength()
+ " Status: " + LibUsb.errorName(transfer.status()));

monitor.close(); // watch out, this can call
// synchronized method
}

if (timestampsReset) {
Expand Down Expand Up @@ -1709,10 +1703,9 @@ public void setNumBuffers(final int numBuffers) {
* used for motor control or other purposes.
* </strong>
* <p>
* TODO: at present this processing is redundant in that the most
* recently captured events are copied to a different AEPacketRaw,
* extracted to an EventPacket, and then processed. This effort is
* duplicated later in rendering. This should be fixed somehow.
* TODO: at present this processing is redundant in that the most recently captured events are copied to a
* different AEPacketRaw, extracted to an EventPacket, and then processed. This effort is duplicated later in
* rendering. This should be fixed somehow.
*
* @param addresses
* the raw input addresses; these are filtered in place
Expand Down Expand Up @@ -2334,14 +2327,12 @@ public byte[] loadBinaryFirmwareFileSystemFile(final String firmwareFilename) th
* Firmware file is a binary file produced by uVision2 (Keil) from source
* code for firmware.
* <p>
* Firmware that is actually downloaded depends on discovered PID of device.
* If the PID is discovered to be a bare CypressFX2, then a dialog is shown
* that user can use to program the VID/PID of the device.
* Firmware that is actually downloaded depends on discovered PID of device. If the PID is discovered to be a bare
* CypressFX2, then a dialog is shown that user can use to program the VID/PID of the device.
* <p>
* In addition, there is a problem if firmware is downloaded more than once
* to an FX2LP device between hard resets. Therefore if this method detects
* that the device has string identitifers, it assumes the firmware has
* already been downloaded.
* In addition, there is a problem if firmware is downloaded more than once to an FX2LP device between hard resets.
* Therefore if this method detects that the device has string identitifers, it assumes the firmware has already
* been downloaded.
*
*
* Firmware file is loaded as a resource from the jar archive.
Expand Down Expand Up @@ -2372,18 +2363,15 @@ synchronized public void downloadFirmwareBinary(final String firmwareFilename) t
* Firmware file is a binary file produced by uVision2 (Keil) from source
* code for firmware.
* <p>
* Firmware that is actually downloaded depends on discovered PID of device.
* If the PID is discovered to be a bare CypressFX2, then a dialog is shown
* that user can use to program the VID/PID of the device.
* Firmware that is actually downloaded depends on discovered PID of device. If the PID is discovered to be a bare
* CypressFX2, then a dialog is shown that user can use to program the VID/PID of the device.
* <p>
* In addition, there is a problem if firmware is downloaded more than once
* to an FX2LP device between hard resets. Therefore if this method detects
* that the device has string identifiers, it assumes the firmware has
* already been downloaded.
* In addition, there is a problem if firmware is downloaded more than once to an FX2LP device between hard resets.
* Therefore if this method detects that the device has string identifiers, it assumes the firmware has already been
* downloaded.
*
* <p>
* Firmware file is loaded either from the file system or as a resource from
* the jar archive.
* Firmware file is loaded either from the file system or as a resource from the jar archive.
*
* @throws BlankDeviceException
* if device is blank or firmware file is not found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,13 @@ public void startThread() {

CypressFX3.log.info("Starting AEReader");
usbTransfer = new USBTransferThread(monitor.deviceHandle, CypressFX3.AE_MONITOR_ENDPOINT_ADDRESS,
LibUsb.TRANSFER_TYPE_BULK, new ProcessAEData(), getNumBuffers(), getFifoSize());
LibUsb.TRANSFER_TYPE_BULK, new ProcessAEData(), getNumBuffers(), getFifoSize(), null, null,
new Runnable() {
@Override
public void run() {
monitor.close();
}
});
usbTransfer.setPriority(AEReader.MONITOR_PRIORITY);
usbTransfer.setName("AEReaderThread");
usbTransfer.start();
Expand Down Expand Up @@ -990,11 +996,6 @@ public void processTransfer(final RestrictedTransfer transfer) {
else {
CypressFX3.log.warning("ProcessAEData: Bytes transferred: " + transfer.actualLength()
+ " Status: " + LibUsb.errorName(transfer.status()));

if (transfer.status() != LibUsb.TRANSFER_CANCELLED) {
monitor.close(); // watch out, this can call
// synchronized method
}
}
}
}
Expand Down

0 comments on commit 58bd8c3

Please sign in to comment.