Commit c936dda7 authored by Vincent van Beveren's avatar Vincent van Beveren

did some preliminary work on creating better abstractions for the future support of libftdi.

parent 98f13730
......@@ -35,6 +35,30 @@ SaFariPark shows, in the edit pane, a higher overview of the content loaded insi
\label{fig:editor}
\end{figure}
\section{Ubuntu configuration}
To run SaFariPark on Ubuntu two things need to happen:
\begin{itemize}
\item The rights of the FTDI device must be relaxed such that any use has read and write permissions
\item The ftdi\_sio driver must be prevented from loading, as it will interfere with opening the device
\end{itemize}
\subsubsection{Relaxing driver rights}
Create a file named 90-ftdi in /etc/udev/rules.d/ and put in the following statement:
\begin{verbatim}
SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", MODE="0666"
\end{verbatim}
\subsubsection{Prevent loading of the ftdi\_sio driver}
Edit the file /etc/modprobe.d/blacklist.conf and append the following line:
\begin{verbatim}
blacklist ftdi_sio
\end{verbatim}
Note: This will prevent any FTDI based device from being loaded as a USB serial converted.
\chapter{Appendices}
\section{Overlay XML description}
......
......@@ -22,13 +22,12 @@ import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import com.ftdi.FTD2XXException;
import com.ftdi.FTDevice;
import nl.nikhef.rebus.dev.PCA9848;
import nl.nikhef.rebus.ftdi.GPIO;
import nl.nikhef.rebus.ftdi.I2C;
import nl.nikhef.rebus.ftdi.JavaFTD2xxMPSSE;
import nl.nikhef.rebus.ftdi.MPSSE_GPIO;
import nl.nikhef.rebus.ftdi.MPSSE_I2C;
import nl.nikhef.rebus.ftdi.FTDIDevice;
import nl.nikhef.rebus.ftdi.FTDIEnumerator;
import nl.nikhef.rebus.ftdi.MPSSE;
import nl.nikhef.sfp.i2c.I2CLink;
......@@ -37,27 +36,27 @@ public class MultiSFPDevice extends SFPDeviceBase {
private static final Logger LOG = Logger.getLogger(MultiSFPDevice.class.getSimpleName());
private static final int PCA_RESET = I2C.GPIO_AL0;
private static final int ACTIVE_LED = I2C.GPIO_AL1;
private static final int TX_LED = I2C.GPIO_AL2;
private static final int RX_LED = I2C.GPIO_AL3;
private static final int PCA_RESET = MPSSE_I2C.GPIO_AL0;
private static final int ACTIVE_LED = MPSSE_I2C.GPIO_AL1;
private static final int TX_LED = MPSSE_I2C.GPIO_AL2;
private static final int RX_LED = MPSSE_I2C.GPIO_AL3;
private static final int MODULE_PRESENT_IOS = GPIO.GPIO_AL0 | GPIO.GPIO_AL1 | GPIO.GPIO_AL2 | GPIO.GPIO_AL3;
private static final int MODULE_PRESENT_IOS = MPSSE_GPIO.GPIO_AL0 | MPSSE_GPIO.GPIO_AL1 | MPSSE_GPIO.GPIO_AL2 | MPSSE_GPIO.GPIO_AL3;
private static final int MODULE_PRESENT_SHIFT = 4;
private static final int RX_LOSS_IOS = GPIO.GPIO_AH0 | GPIO.GPIO_AH1 | GPIO.GPIO_AH2 | GPIO.GPIO_AH3;
private static final int RX_LOSS_IOS = MPSSE_GPIO.GPIO_AH0 | MPSSE_GPIO.GPIO_AH1 | MPSSE_GPIO.GPIO_AH2 | MPSSE_GPIO.GPIO_AH3;
private static final int RX_LOSS_SHIFT = 8;
private static final int TX_FAULT_IOS = GPIO.GPIO_AH4 | GPIO.GPIO_AH5 | GPIO.GPIO_AH6 | GPIO.GPIO_AH7;
private static final int TX_FAULT_IOS = MPSSE_GPIO.GPIO_AH4 | MPSSE_GPIO.GPIO_AH5 | MPSSE_GPIO.GPIO_AH6 | MPSSE_GPIO.GPIO_AH7;
private static final int TX_FAULT_SHIFT = 12;
private static final int OUTPUT_MASK = ACTIVE_LED | TX_LED | RX_LED;
private static final int NO_OF_BAYS = 4;
private FTDevice _portA; // FTDI Port A device
private FTDevice _portB; // FTDI Port B device
private FTDIDevice _portA; // FTDI Port A device
private FTDIDevice _portB; // FTDI Port B device
private String _serial;
private I2C _i2c;
private GPIO _gpio;
private MPSSE_I2C _i2c;
private MPSSE_GPIO _gpio;
private MPSSE _mpsseA;
private MPSSE _mpsseB;
private PCA9848 _mux;
......@@ -80,25 +79,21 @@ public class MultiSFPDevice extends SFPDeviceBase {
_monitor = monitor;
try {
_portA = FTDevice.getDevicesBySerialNumber(ftdiSerial + "A").get(0);
_portB = FTDevice.getDevicesBySerialNumber(ftdiSerial + "B").get(0);
} catch (FTD2XXException e) {
throw new IOException("Could not initialize FTDI", e);
}
_portA = FTDIEnumerator.getDefault().getBySerialNumber(ftdiSerial + "A");
_portB = FTDIEnumerator.getDefault().getBySerialNumber(ftdiSerial + "B");
LogManager.getLogManager().getLogger("com.ftdi.FTDevice").setLevel(Level.WARNING);
_mpsseA = new JavaFTD2xxMPSSE(_portA);
_mpsseB = new JavaFTD2xxMPSSE(_portB);
_i2c = new I2C(_mpsseA, I2C.SPEED_NORMAL, false);
_mpsseA = _portA.createMPSSE();
_mpsseB = _portB.createMPSSE();
_i2c = new MPSSE_I2C(_mpsseA, MPSSE_I2C.SPEED_NORMAL, false);
_i2c.setModes(OUTPUT_MASK | PCA_RESET, OUTPUT_MASK | PCA_RESET | RX_LOSS_IOS | TX_FAULT_IOS);
// Reset PCA9848
_i2c.setOutputs(0, PCA_RESET);
_i2c.setOutputs(PCA_RESET, PCA_RESET);
_gpio = new GPIO(_mpsseB);
_gpio = new MPSSE_GPIO(_mpsseB);
_gpio.setModes(0, MODULE_PRESENT_IOS);
setLeds(false, false);
......
......@@ -20,8 +20,9 @@ package nl.nikhef.sfp;
import java.io.IOException;
import java.util.List;
import com.ftdi.DeviceType;
import com.ftdi.FTDevice;
import nl.nikhef.rebus.ftdi.FTDIDevice;
import nl.nikhef.rebus.ftdi.FTDIEnumerator;
import nl.nikhef.rebus.ftdi.FTDIType;
public class MultiSFPProvider extends SFPProviderBase
{
......@@ -41,24 +42,24 @@ public class MultiSFPProvider extends SFPProviderBase
public void scanForNewDevices() {
try {
List<FTDevice> devs;
List<FTDIDevice> devs;
synchronized(this)
{
devs = FTDevice.getDevices(true);
devs = FTDIEnumerator.getDefault().getDevices();
}
for (FTDevice devRaw : devs)
for (FTDIDevice devRaw : devs)
{
// System.out.println("Device: " + devRaw);
// XXX On Linux the MultiSFP A is descriptor is not generated once opened. But B remains. So we sync on that.
//
if (devRaw.getDevType() == DeviceType.DEVICE_2232H && devRaw.getDevDescription().equals("MultiSFP B")) {
if (devRaw.getType() == FTDIType.FT_2232H && devRaw.getDescription().equals("MultiSFP B")) {
// Only get the primary 'A' device, we know the second.
String serial = devRaw.getDevSerialNumber();
// Only get the secondary 'B' device, we know the first being A
String serial = devRaw.getSerial();
// chop of the last part from the serial:
serial = serial.substring(0, serial.length() - 1);
......
......@@ -19,18 +19,18 @@ package nl.nikhef.sfp.i2c;
import java.io.IOException;
import nl.nikhef.rebus.ftdi.I2C;
import nl.nikhef.rebus.ftdi.MPSSE_I2C;
import nl.nikhef.rebus.ftdi.MPSSE;
public class FTI2CLink implements I2CLink {
private MPSSE _mpsse;
private I2C _i2c;
private MPSSE_I2C _i2c;
public FTI2CLink(MPSSE mpsse) throws IOException {
_mpsse = mpsse;
_i2c = new I2C(mpsse, I2C.SPEED_NORMAL, true);
_i2c = new MPSSE_I2C(mpsse, MPSSE_I2C.SPEED_NORMAL, true);
_i2c.wakeI2C();
}
......
......@@ -24,7 +24,7 @@ import javax.xml.stream.XMLStreamException;
import com.ftdi.FTDevice;
import nl.nikhef.rebus.dev.PCA9848;
import nl.nikhef.rebus.ftdi.I2C;
import nl.nikhef.rebus.ftdi.MPSSE_I2C;
import nl.nikhef.rebus.ftdi.JavaFTD2xxMPSSE;
import nl.nikhef.rebus.ftdi.MPSSE;
import nl.nikhef.sfp.ddmi.DDMI;
......@@ -41,7 +41,7 @@ public class Test2 {
MPSSE mpsse = new JavaFTD2xxMPSSE(FTDevice.getDevicesBySerialNumber("NK1BYBILA").get(0));
I2C i2c = new I2C(mpsse, 100000, false);
MPSSE_I2C i2c = new MPSSE_I2C(mpsse, 100000, false);
PCA9848 mux = new PCA9848(i2c, PCA9848.ADDRESS_HHH);
......
......@@ -19,7 +19,7 @@ package nl.nikhef.rebus.dev;
import java.io.IOException;
import nl.nikhef.rebus.ftdi.I2C;
import nl.nikhef.rebus.ftdi.MPSSE_I2C;
public class PCA9848 {
......@@ -43,10 +43,10 @@ public class PCA9848 {
private static final int MASK_CHANNEL_6 = 0x40;
private static final int MASK_CHANNEL_7 = 0x80;
*/
private I2C _i2c;
private MPSSE_I2C _i2c;
private int _addr;
public PCA9848(I2C i2c, int addr)
public PCA9848(MPSSE_I2C i2c, int addr)
{
_i2c = i2c;
_addr = addr;
......
/* *****************************************************************************
* SaFariPark SFP+ editor and support libraries
* Copyright (C) 2017 National Institute for Subatomic Physics Nikhef
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package nl.nikhef.rebus.ftdi;
import java.io.IOException;
public interface FTDIDevice {
public String getSerial();
public String getDescription();
public FTDIType getType();
public MPSSE createMPSSE() throws IOException;
}
/* *****************************************************************************
* SaFariPark SFP+ editor and support libraries
* Copyright (C) 2017 National Institute for Subatomic Physics Nikhef
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package nl.nikhef.rebus.ftdi;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.ftdi.FTD2XXException;
import com.ftdi.FTDevice;
public abstract class FTDIEnumerator {
public static FTDIEnumerator getDefault() {
return DEFAULT_ENUMERATOR;
}
public abstract List<FTDIDevice> getDevices() throws IOException;
private static class FTD2xxDevice implements FTDIDevice
{
private FTDevice _device;
public FTD2xxDevice(FTDevice device) {
_device = device;
}
@Override
public String getSerial() {
return _device.getDevSerialNumber();
}
@Override
public FTDIType getType() {
switch (_device.getDevType()){
case DEVICE_232H: return FTDIType.FT_232H;
case DEVICE_100AX: return FTDIType.FT_100AX;
case DEVICE_2232C: return FTDIType.FT_100AX;
case DEVICE_2232H: return FTDIType.FT_2232H;
case DEVICE_232AM: return FTDIType.FT_232AM;
case DEVICE_232BM: return FTDIType.FT_232BM;
case DEVICE_232R: return FTDIType.FT_232R;
case DEVICE_4232H: return FTDIType.FT_4232H;
default:
return FTDIType.FT_UNKNOWN;
}
}
@Override
public MPSSE createMPSSE() throws IOException {
return new JavaFTD2xxMPSSE(_device);
}
@Override
public String getDescription() {
return _device.getDevDescription();
}
}
private static class FTD2xxEnumerator extends FTDIEnumerator
{
@Override
public List<FTDIDevice> getDevices() throws IOException {
List<FTDIDevice> devices = new ArrayList<FTDIDevice>();
try {
for (FTDevice device : FTDevice.getDevices(true))
{
devices.add(new FTD2xxDevice(device));
}
} catch (FTD2XXException e) {
throw new IOException("Failed to enumerate FTDI devices", e);
}
return devices;
}
@Override
public FTDIDevice getBySerialNumber(String serialNumber) throws IOException {
try {
return new FTD2xxDevice(FTDevice.getDevicesBySerialNumber(serialNumber).get(0));
} catch (FTD2XXException e) {
throw new IOException("Failed to get device", e);
}
}
}
private static FTDIEnumerator DEFAULT_ENUMERATOR = new FTD2xxEnumerator();
public abstract FTDIDevice getBySerialNumber(String string) throws IOException;
}
/* *****************************************************************************
* SaFariPark SFP+ editor and support libraries
* Copyright (C) 2017 National Institute for Subatomic Physics Nikhef
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package nl.nikhef.rebus.ftdi;
public enum FTDIType {
FT_232BM,
FT_232AM,
FT_100AX,
FT_UNKNOWN,
FT_2232C,
FT_232R,
FT_2232H,
FT_4232H,
FT_232H;
}
......@@ -42,7 +42,7 @@ public class I2CTests {
// MPSSE mpsse = new Ftd2xxjMPSSE(findDevice());
I2C i2c = new I2C(mpsse, I2C.SPEED_SLOW, false);
MPSSE_I2C i2c = new MPSSE_I2C(mpsse, MPSSE_I2C.SPEED_SLOW, false);
// set mux to 0
......
......@@ -19,9 +19,9 @@ package nl.nikhef.rebus.ftdi;
import java.io.IOException;
public class GPIO extends BusBase {
public class MPSSE_GPIO extends BusBase {
public GPIO(MPSSE mpsse) throws IOException {
public MPSSE_GPIO(MPSSE mpsse) throws IOException {
super(mpsse);
mpsse.switchMode(0);
}
......
......@@ -24,9 +24,9 @@ import java.util.logging.Logger;
import static nl.nikhef.rebus.ftdi.MPSSE.*;
public class I2C extends BusBase {
public class MPSSE_I2C extends BusBase {
private static final Logger LOG = Logger.getLogger(I2C.class.getSimpleName());
private static final Logger LOG = Logger.getLogger(MPSSE_I2C.class.getSimpleName());
public static final int SPEED_SLOW = 10000;
public static final int SPEED_NORMAL = 100000;
......@@ -55,7 +55,7 @@ public class I2C extends BusBase {
* AD2 -> TDO --+
*/
public I2C(MPSSE mpsse, int speed, boolean ft232h) throws IOException
public MPSSE_I2C(MPSSE mpsse, int speed, boolean ft232h) throws IOException
{
super(mpsse);
......
......@@ -28,7 +28,7 @@ import java.io.IOException;
*
* Note that SPI mode0 and mode2 are supported. Mode1 and 3 are not.
*/
public class SPI extends BusBase {
public class MPSSE_SPI extends BusBase {
public static final int GPIOL0_INPUT = 0x0;
public static final int GPIOL0_OUTPUT = 0x1;
......@@ -64,7 +64,7 @@ public class SPI extends BusBase {
* @param bitRate BitRate (0-30M)
* @param gpioDir Direction of the 4 remaining GPIO ports, see GPIOLn_* defines.
*/
public SPI(MPSSE mpsse, boolean invClk, int bitRate, int gpioDir) throws IOException {
public MPSSE_SPI(MPSSE mpsse, boolean invClk, int bitRate, int gpioDir) throws IOException {
super(mpsse);
_gpioDir = ((gpioDir << SPI_GPIO_SHIFT) & SPI_GPIO_MASK) | SPI_IO_IOCFG;
......
......@@ -20,7 +20,7 @@
<property name="jsfp" location="../jsfp/jsfp.jar" />
<property name="tools" location="../nikhef-tools/nikhef-tools.jar" />
<property name="lua" value="../jsfp/lib/luaj-jse-3.0.1.jar"/>
<property name="jna" value="../rebus/lib/jna-4.3.0.jar"/>
<property name="jna" value="../rebus/lib/jna-4.4.0.jar"/>
<property name="mig" value="lib/miglayout-4.0-swing.jar"/>
......@@ -60,10 +60,10 @@
<fileset dir="overlays"/>
</copy>
<echo file="${dist}/safaripark.bat">@echo off
start /b javaw -cp "rebus.jar;jna-4.3.0.jar;nikhef-tools.jar;luaj-jse-3.0.1.jar;jsfp.jar;safaripark.jar;miglayout-4.0-swing.jar" -splash:splash.png nl.nikhef.safaripark.SaFariPark
start /b javaw -cp "rebus.jar;jna-4.4.0.jar;nikhef-tools.jar;luaj-jse-3.0.1.jar;jsfp.jar;safaripark.jar;miglayout-4.0-swing.jar" -splash:splash.png nl.nikhef.safaripark.SaFariPark
</echo>
<echo file="${dist}/safaripark.sh">#!/bin/bash
java -cp "rebus.jar:jna-4.3.0.jar:nikhef-tools.jar:luaj-jse-3.0.1.jar:jsfp.jar:safaripark.jar:miglayout-4.0-swing.jar" -splash:splash.png nl.nikhef.safaripark.SaFariPark
java -cp "rebus.jar:jna-4.4.0.jar:nikhef-tools.jar:luaj-jse-3.0.1.jar:jsfp.jar:safaripark.jar:miglayout-4.0-swing.jar" -splash:splash.png nl.nikhef.safaripark.SaFariPark
</echo>
<zip destfile="safaripark-${git.branch}-${git.tag}-${git.revision}.zip" basedir="${dist}">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment