X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fslipway%2FFtdiBoard.java;h=7c83724300f3a6e37eca2b9c78b0a1c3ccb7ed31;hb=57f6ad104a6e2bf0433a86f5c8e1f31c1715dab9;hp=fc705a7b7f22f472baf1cf3acb7286b0e3419bfd;hpb=c5cb5a0f50df5816263d178e761256b7907a9460;p=slipway.git diff --git a/src/edu/berkeley/slipway/FtdiBoard.java b/src/edu/berkeley/slipway/FtdiBoard.java index fc705a7..7c83724 100644 --- a/src/edu/berkeley/slipway/FtdiBoard.java +++ b/src/edu/berkeley/slipway/FtdiBoard.java @@ -1,112 +1,182 @@ package edu.berkeley.slipway; +import com.ftdi.usb.*; import com.atmel.fpslic.*; import edu.berkeley.obits.*; -import org.ibex.util.Log; +import org.ibex.util.*; import java.io.*; import java.util.*; import gnu.io.*; -public class FtdiBoard extends Board { +public class FtdiBoard extends Fpslic implements Board { static { System.load(new File("build/"+System.mapLibraryName("FtdiUartNative")).getAbsolutePath()); } - private final Chip chip; - private final InputStream in; - private final OutputStream out; + private final FpslicBoot chip; + private final DataInputStream in; + private final DataOutputStream out; public InputStream getInputStream() { return in; } public OutputStream getOutputStream() { return out; } public FtdiBoard() throws Exception { - chip = new ChipImpl(); + super(24, 24); + chip = new FpslicBoot(new FpslicBootPinsUsb(new FtdiUart(0x6666, 0x3133, 1500 * 1000))); String bstFile = this.getClass().getName(); bstFile = bstFile.substring(0, bstFile.lastIndexOf('.')); bstFile = bstFile.replace('.', '/')+"/slipway_drone.bst"; boot(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(bstFile))); - in = chip.getInputStream(); - out = chip.getOutputStream(); + in = new DataInputStream(chip.getInputStream()); + out = new DataOutputStream(chip.getOutputStream()); for(int i=0; i<255; i++) out.write(0); out.flush(); + init(); } - public void reset() throws IOException { - chip.doReset(); - } + public void reset() throws IOException { chip.reset(); } public void boot(Reader r) throws Exception { - Chip d = chip; - - //d.buffered(false); - - d.selfTest(); - - d.doReset(); - - d.config(0,10); - d.con(); - //d.config(Integer.parseInt("10110111", 2)); - //d.config(0); + chip.selfTest(); + int total = 75090/9; + OutputStream os = new ProgressOutputStream("bootstrap bitstream:", chip.getConfigStream(), total); BufferedReader br = new BufferedReader(r); - br.readLine(); + int bytes = 0; - //System.out.println("cts="+""+" pins=" + pad(Integer.toString(d.readPins()&0xff,2),8)); while(true) { String s = br.readLine(); if (s==null) break; - int in = Integer.parseInt(s, 2); bytes++; - for(int i=7; i>=0; i--) { - d.config((((in & 0xff) & (1< false"); - d.avrrst(false); - try { Thread.sleep(500); } catch (Exception e) { } - //System.out.println("cts="+""+" pins=" + pad(Integer.toString(d.readPins()&0xff,2),8)); - - //((Chip)d).avr(); - - //System.out.println("avr reset => true"); - ((ChipImpl)chip).purge(); - ((ChipImpl)chip).uart_and_cbus_mode(1<<1, 1<<1); - - //d.avrrst(true); - //try { Thread.sleep(500); } catch (Exception e) { } - //System.out.println("cts="+""+" pins=" + pad(Integer.toString(d.readPins()&0xff,2),8)); + // Callbacks ////////////////////////////////////////////////////////////////////////////// + + private Vector callbacks = new Vector(); + + public static abstract class ByteCallback { + public int result; + public abstract void call(byte b) throws Exception; + } + + public synchronized int readCount() { + try { + ByteCallback bc = new ByteCallback() { + public synchronized void call(byte b) throws Exception { + result = + ((b & 0xff) << 24) | + ((in.read() & 0xff) << 16) | + ((in.read() & 0xff) << 8) | + ((in.read() & 0xff) << 0); + this.notify(); + } + }; + synchronized(bc) { + callbacks.add(bc); + out.writeByte(3); + out.flush(); + bc.wait(); + } + return bc.result; + } catch (Exception e) { throw new RuntimeException(e); } } + public synchronized void readBus(ByteCallback bc) throws IOException { + callbacks.add(bc); + out.writeByte(2); + out.flush(); + } + + public synchronized void readInterrupts(ByteCallback bc) throws IOException { + callbacks.add(bc); + out.writeByte(3); + out.flush(); + } + + + // Util ////////////////////////////////////////////////////////////////////////////// + + private String pad(int i, String s) { if (s.length()>i) return s; return "0"+pad((i-1),s); } public static String pad(String s, int i) { if (s.length() >= i) return s; return "0"+pad(s, i-1); } + }