jAER project on SourceForge

net.sf.jaer.hardwareinterface.usb.linux
Class CypressFX2RetinaLinux

java.lang.Object
  extended by net.sf.jaer.hardwareinterface.usb.linux.CypressFX2RetinaLinux
All Implemented Interfaces:
AEMonitorInterface, BiasgenHardwareInterface, HardwareInterface, HasResettablePixelArray, USBInterface

public class CypressFX2RetinaLinux
extends java.lang.Object
implements AEMonitorInterface, BiasgenHardwareInterface, HasResettablePixelArray

The Tmpdiff128 retina under linux using the JSR-80 linux java USB library (JSR-80 project).

Author:
Martin Ebner (martin_ebner)

Nested Class Summary
 class CypressFX2RetinaLinux.AEReader
          Class to listen to aer events
 
Field Summary
static int AE_BUFFER_SIZE
           
protected  net.sf.jaer.hardwareinterface.usb.linux.CypressFX2RetinaLinux.AEPacketRawPool aePacketRawPool
          The pool of raw AE packets, used for data transfer
protected  CypressFX2RetinaLinux.AEReader aeReader
          the event reader - a buffer pool thread from USBIO subclassing
protected  AEChip chip
           
protected  java.lang.String devicName
           
protected  boolean inEndpointEnabled
           
protected  boolean isOpened
          device open status
protected  AEPacketRaw lastEventsAcquired
           
static int MAX_BYTES_PER_BIAS
          max number of bytes used for each bias.
 java.beans.PropertyChangeEvent NEW_EVENTS_PROPERTY_CHANGE
          event supplied to listeners when new events are collected.
protected  java.util.prefs.Preferences prefs
           
protected  java.io.FileInputStream retina
           
protected  java.io.FileOutputStream retinaVendor
           
static byte VENDOR_DEVICE_OUT_REQUEST
           
 
Fields inherited from interface net.sf.jaer.hardwareinterface.usb.USBInterface
PID_THESYCON_END, PID_THESYCON_START, VID_THESYCON
 
Constructor Summary
CypressFX2RetinaLinux(java.lang.String deviceName)
          This instance is typically constructint interfaceNumbered by the factory instance (HardwareInterfaceFactoryLinux)
 
Method Summary
 AEPacketRaw acquireAvailableEventsFromDriver()
          Gets available events from driver.
 void addAEListener(AEListener listener)
          add a PropertyChangeListener for new events
 void claimInterface()
          Claim this interface for exclusive access.
 void close()
          Closes the device and frees the internal device handle.
 void flashConfiguration(Biasgen biasgen)
          flashes the configuration in non-volatile storage so they will be reloaded on reset or powerup.
 byte[] formatConfigurationBytes(Biasgen biasgen)
          Formats and returns the bytes that should be sent to set a particular configuration.
 int getAEBufferSize()
          Returns the size of the host buffer.
 CypressFX2RetinaLinux.AEReader getAeReader()
           
 AEChip getChip()
          Sets the AEChip that this interface is acquiring events for
 short getDID()
           
 int getEstimatedEventRate()
          Returns estimate of present event rate on this interface
 AEPacketRaw getEvents()
          returns the last events acquired by AEMonitorInterface.acquireAvailableEventsFromDriver()
 int getMaxCapacity()
          the max capacity of this USB2 bus interface is 24MB/sec/4 bytes/event
 int getNumEventsAcquired()
          Returns the number of events acquired by the last call to AEMonitorInterface.acquireAvailableEventsFromDriver()
 short getPID()
           
 java.lang.String[] getStringDescriptors()
          return the string USB descriptors for the device.
 int getTimestampTickUs()
           
 java.lang.String getTypeName()
          get text name of interface, e.g.
 short getVID()
           
 int[] getVIDPID()
          return the USB VID/PID of the interface
 boolean isEventAcquisitionEnabled()
           
 boolean isOpen()
           
 void open()
          Opens the device driver and gets a handle to the device which is internally maintained.
 boolean overrunOccurred()
          Is true if an overrun occured in the driver the last time AEMonitorInterface.acquireAvailableEventsFromDriver() was called.
 void releaseInterface()
          Release this interface from exclusive access.
 void removeAEListener(AEListener listener)
          remove a PropertyChangeListener for new events
 void resetPixelArray()
          momentarily reset the entire pixel array
 void resetTimestamps()
          Sends a vendor request to reset the retina timestamps to zero
 void sendConfiguration(Biasgen biasgen)
          Sends a vendor request with the new bias values
 void setAEBufferSize(int size)
          Sets the size in events of the host buffer.
 void setAeReader(CypressFX2RetinaLinux.AEReader aeReader)
           
 void setArrayReset(boolean value)
          Returns the array reset flag.
 void setChip(AEChip chip)
          Sets the AEChip that this interface is acquiring events for
 void setEventAcquisitionEnabled(boolean enable)
          Enables event acquisition, e.g.
 boolean setLed(boolean value)
          Set LED on board.
 void setPowerDown(boolean powerDown)
          sends the powerdown vendor request to power down the chip.
 boolean startAer()
          Start AER data from IN endpoint 3
 void startAEReader()
           
 boolean stopAer()
          Start AER data from IN endpoint 3
 void stopAEReader()
           
protected  void translateEvents_code(byte[] b, int bytesSent)
          Method that translates the UsbIoBuffer when a board that has a CPLD to timetamp events and that uses the CypressFX2 in slave FIFO mode, such as the USBAERmini2 board or StereoRetinaBoard, is used.
 boolean vendorRequest(byte request, short value, short index, byte[] data)
          Submit Vendor Request
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chip

protected AEChip chip

inEndpointEnabled

protected boolean inEndpointEnabled

prefs

protected java.util.prefs.Preferences prefs

MAX_BYTES_PER_BIAS

public static final int MAX_BYTES_PER_BIAS
max number of bytes used for each bias. For 24-bit biasgen, only 3 bytes are used, but we oversize considerably for the future.

See Also:
Constant Field Values

VENDOR_DEVICE_OUT_REQUEST

public static final byte VENDOR_DEVICE_OUT_REQUEST
See Also:
Constant Field Values

devicName

protected java.lang.String devicName

retina

protected java.io.FileInputStream retina

retinaVendor

protected java.io.FileOutputStream retinaVendor

aePacketRawPool

protected net.sf.jaer.hardwareinterface.usb.linux.CypressFX2RetinaLinux.AEPacketRawPool aePacketRawPool
The pool of raw AE packets, used for data transfer


AE_BUFFER_SIZE

public static final int AE_BUFFER_SIZE
See Also:
Constant Field Values

lastEventsAcquired

protected AEPacketRaw lastEventsAcquired

aeReader

protected CypressFX2RetinaLinux.AEReader aeReader
the event reader - a buffer pool thread from USBIO subclassing


NEW_EVENTS_PROPERTY_CHANGE

public final java.beans.PropertyChangeEvent NEW_EVENTS_PROPERTY_CHANGE
event supplied to listeners when new events are collected. this is final because it is just a marker for the listeners that new events are available


isOpened

protected boolean isOpened
device open status

Constructor Detail

CypressFX2RetinaLinux

public CypressFX2RetinaLinux(java.lang.String deviceName)
                      throws java.io.FileNotFoundException
This instance is typically constructint interfaceNumbered by the factory instance (HardwareInterfaceFactoryLinux)

Throws:
java.io.FileNotFoundException
Method Detail

acquireAvailableEventsFromDriver

public AEPacketRaw acquireAvailableEventsFromDriver()
                                             throws HardwareInterfaceException
Description copied from interface: AEMonitorInterface
Gets available events from driver. This call returns a reference to an AEPacket that holds the events. HardwareInterfaceException is thrown if there is an error.

Specified by:
acquireAvailableEventsFromDriver in interface AEMonitorInterface
Returns:
packet. A empty packet is returned if there are no events.
Throws:
HardwareInterfaceException - .

getNumEventsAcquired

public int getNumEventsAcquired()
Description copied from interface: AEMonitorInterface
Returns the number of events acquired by the last call to AEMonitorInterface.acquireAvailableEventsFromDriver()

Specified by:
getNumEventsAcquired in interface AEMonitorInterface
Returns:
number of events acquired

getEvents

public AEPacketRaw getEvents()
Description copied from interface: AEMonitorInterface
returns the last events acquired by AEMonitorInterface.acquireAvailableEventsFromDriver()

Specified by:
getEvents in interface AEMonitorInterface
Returns:
the packet of raw events

resetTimestamps

public void resetTimestamps()
Sends a vendor request to reset the retina timestamps to zero

Specified by:
resetTimestamps in interface AEMonitorInterface

resetPixelArray

public void resetPixelArray()
momentarily reset the entire pixel array

Specified by:
resetPixelArray in interface HasResettablePixelArray

overrunOccurred

public boolean overrunOccurred()
Description copied from interface: AEMonitorInterface
Is true if an overrun occured in the driver the last time AEMonitorInterface.acquireAvailableEventsFromDriver() was called. This flag is cleared by the next AEMonitorInterface.acquireAvailableEventsFromDriver(). 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.

Specified by:
overrunOccurred in interface AEMonitorInterface
Returns:
true if there was an overrun.

getAEBufferSize

public int getAEBufferSize()
Description copied from interface: AEMonitorInterface
Returns the size of the host buffer.

Specified by:
getAEBufferSize in interface AEMonitorInterface
Returns:
the size of the buffer in events

setAEBufferSize

public void setAEBufferSize(int size)
Description copied from interface: AEMonitorInterface
Sets the size in events of the host buffer. Default is AE_BUFFER_SIZE. You can set this larger if you have overruns because your host processing (e.g. rendering) is taking too long.

This call discards collected events.

Specified by:
setAEBufferSize in interface AEMonitorInterface
Parameters:
size - size of buffer in events

setEventAcquisitionEnabled

public void setEventAcquisitionEnabled(boolean enable)
                                throws HardwareInterfaceException
Description copied from interface: AEMonitorInterface
Enables event acquisition, e.g. sends vendor commands to enable transfers, starts buffer pool threads. This method can be called, e.g. from acquireAvailableEventsFromDriver method to ensure driver is acquiring events.

Specified by:
setEventAcquisitionEnabled in interface AEMonitorInterface
Parameters:
enable - true to start, false to stop
Throws:
HardwareInterfaceException

isEventAcquisitionEnabled

public boolean isEventAcquisitionEnabled()
Specified by:
isEventAcquisitionEnabled in interface AEMonitorInterface
Returns:
true if event acquisition is enabled

addAEListener

public void addAEListener(AEListener listener)
Description copied from interface: AEMonitorInterface
add a PropertyChangeListener for new events

Specified by:
addAEListener in interface AEMonitorInterface
Parameters:
listener - will be called after each AEMonitorInterface.acquireAvailableEventsFromDriver() call

removeAEListener

public void removeAEListener(AEListener listener)
Description copied from interface: AEMonitorInterface
remove a PropertyChangeListener for new events

Specified by:
removeAEListener in interface AEMonitorInterface
Parameters:
listener - to remove

getMaxCapacity

public int getMaxCapacity()
the max capacity of this USB2 bus interface is 24MB/sec/4 bytes/event

Specified by:
getMaxCapacity in interface AEMonitorInterface
Returns:
max capacity in events/sec

getEstimatedEventRate

public int getEstimatedEventRate()
Description copied from interface: AEMonitorInterface
Returns estimate of present event rate on this interface

Specified by:
getEstimatedEventRate in interface AEMonitorInterface
Returns:
event rate in events/sec as computed from last acquisition.

getTimestampTickUs

public final int getTimestampTickUs()
Specified by:
getTimestampTickUs in interface AEMonitorInterface
Returns:
timestamp tick in us NOTE: DOES NOT RETURN THE TICK OF THE USBAERmini2 board

setChip

public void setChip(AEChip chip)
Description copied from interface: AEMonitorInterface
Sets the AEChip that this interface is acquiring events for

Specified by:
setChip in interface AEMonitorInterface
Parameters:
chip - the chip

getChip

public AEChip getChip()
Description copied from interface: AEMonitorInterface
Sets the AEChip that this interface is acquiring events for

Specified by:
getChip in interface AEMonitorInterface
Returns:
the chip

getStringDescriptors

public java.lang.String[] getStringDescriptors()
Description copied from interface: USBInterface
return the string USB descriptors for the device. By USB convention, the first string is the manufactuer, the second is product, and the last is the unique serial number. The serial number may not be implemented, in which case a null string may be the third string or the length of the returned array may only be 2.

Specified by:
getStringDescriptors in interface USBInterface
Returns:
String[] of USB descriptors

getVIDPID

public int[] getVIDPID()
Description copied from interface: USBInterface
return the USB VID/PID of the interface

Specified by:
getVIDPID in interface USBInterface
Returns:
int[] of length 2 containing the Vendor ID (VID) and Product ID (PID) of the device. First element is VID, second element is PID.

getVID

public short getVID()
Specified by:
getVID in interface USBInterface
Returns:
PID (vendor ID)

getPID

public short getPID()
Specified by:
getPID in interface USBInterface
Returns:
PID (product ID)

getDID

public short getDID()
Specified by:
getDID in interface USBInterface
Returns:
DID (device ID). This is the firmware version number, not the serial number. A device may not set the firmware version number in it's descriptors. Returns 0 then. DVS128 and the USBAERmini2 do have it.

getTypeName

public java.lang.String getTypeName()
Description copied from interface: HardwareInterface
get text name of interface, e.g. "CypressFX2" or "SiLabsC8051F320"

Specified by:
getTypeName in interface HardwareInterface

close

public void close()
Description copied from interface: HardwareInterface
Closes the device and frees the internal device handle. Never throws an exception.

Specified by:
close in interface HardwareInterface

open

public void open()
          throws HardwareInterfaceException
Description copied from interface: HardwareInterface
Opens the device driver and gets a handle to the device which is internally maintained.

Specified by:
open in interface HardwareInterface
Throws:
HardwareInterfaceException - if there is a problem. Diagnostics are printeds.

isOpen

public boolean isOpen()
Specified by:
isOpen in interface HardwareInterface
Returns:
true if interface is open, false otherwise

setPowerDown

public void setPowerDown(boolean powerDown)
                  throws HardwareInterfaceException
Description copied from interface: BiasgenHardwareInterface
sends the powerdown vendor request to power down the chip.

Typically this method toggles the powerDown pin correctly to ensure on-chip biasgen is powered up. Chip may have been plugged in without being powered up. If powerdown is true, simply sets powerdown high. If powerdown is false, powerdown is toggled high and then low, to make sure a nagative transistion occurs. This transistion is necessary to ensure the startup circuit starts up the masterbias again.

Specified by:
setPowerDown in interface BiasgenHardwareInterface
Parameters:
powerDown - true to power OFF the biasgen, false to power on
Throws:
HardwareInterfaceException

sendConfiguration

public void sendConfiguration(Biasgen biasgen)
                       throws HardwareInterfaceException
Sends a vendor request with the new bias values

Specified by:
sendConfiguration in interface BiasgenHardwareInterface
Parameters:
biasgen - the object that holds the configuration.
Throws:
HardwareInterfaceException

flashConfiguration

public void flashConfiguration(Biasgen biasgen)
                        throws HardwareInterfaceException
Description copied from interface: BiasgenHardwareInterface
flashes the configuration in non-volatile storage so they will be reloaded on reset or powerup.

Specified by:
flashConfiguration in interface BiasgenHardwareInterface
Parameters:
biasgen - holds the configuration values
Throws:
HardwareInterfaceException

claimInterface

public void claimInterface()
Claim this interface for exclusive access.


releaseInterface

public void releaseInterface()
Release this interface from exclusive access.


setLed

public boolean setLed(boolean value)
Set LED on board. For Debugging.

Parameters:
value - true to turn on
Returns:
true, if successful.

startAer

public boolean startAer()
Start AER data from IN endpoint 3

Returns:
true, if successful.

stopAer

public boolean stopAer()
Start AER data from IN endpoint 3

Returns:
true, if successful.

vendorRequest

public boolean vendorRequest(byte request,
                             short value,
                             short index,
                             byte[] data)
Submit Vendor Request

Parameters:
request - the request number
value - the request value
index - the index of the request
data - the request data byte array
Returns:
true, if successful.

getAeReader

public CypressFX2RetinaLinux.AEReader getAeReader()

setAeReader

public void setAeReader(CypressFX2RetinaLinux.AEReader aeReader)

startAEReader

public void startAEReader()

stopAEReader

public void stopAEReader()

setArrayReset

public void setArrayReset(boolean value)
Description copied from interface: HasResettablePixelArray
Returns the array reset flag. boolean isArrayReset(); /** set the pixel array reset

Specified by:
setArrayReset in interface HasResettablePixelArray
Parameters:
value - true to reset the pixels, false to let them run normally

translateEvents_code

protected void translateEvents_code(byte[] b,
                                    int bytesSent)
Method that translates the UsbIoBuffer when a board that has a CPLD to timetamp events and that uses the CypressFX2 in slave FIFO mode, such as the USBAERmini2 board or StereoRetinaBoard, is used.

On these boards, the msb of the timestamp is used to signal a wrap (the actual timestamp is only 14 bits). The timestamp is also used to signal a timestamp reset The wrapAdd is incremented when an emtpy event is received which has the timestamp bit 15 set to one. The timestamp is reset when an event is received which has the timestamp bit 14 set.

Therefore for a valid event only 14 bits of the 16 transmitted timestamp bits are valid, bits 14 and 15 are the status bits. overflow happens every 16 ms. This way, no roll overs go by undetected, and the problem of invalid wraps doesn't arise.

Parameters:
b - the data buffer

formatConfigurationBytes

public byte[] formatConfigurationBytes(Biasgen biasgen)
Description copied from interface: BiasgenHardwareInterface
Formats and returns the bytes that should be sent to set a particular configuration.

Specified by:
formatConfigurationBytes in interface BiasgenHardwareInterface
Parameters:
biasgen - the source of the configuration.
Returns:
the array to be sent.

jAER project on SourceForge