From: adam Date: Wed, 20 Sep 2006 09:00:39 +0000 (+0100) Subject: checkpoint X-Git-Tag: mpar_demo_release~70 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=eec5429e0e0fd0f3bcbe3dba4f4ed00b4f7db94a;p=slipway.git checkpoint --- diff --git a/src/com/atmel/fpslic/ChipImpl.java b/src/com/atmel/fpslic/ChipImpl.java index f43ae48..5aa9d89 100644 --- a/src/com/atmel/fpslic/ChipImpl.java +++ b/src/com/atmel/fpslic/ChipImpl.java @@ -25,6 +25,14 @@ public class ChipImpl extends FtdiUart implements Chip { } catch (Exception e) { throw new RuntimeException(e); } } + protected int dbits = 0; + protected synchronized void dbang(int bit, boolean val) { + dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit))); + try { + getOutputStream().write((byte)dbits); + } catch (IOException e) { throw new RuntimeException(e); } + } + public void doReset() { dmask = @@ -41,7 +49,7 @@ public class ChipImpl extends FtdiUart implements Chip { flush(); //purge(); - dbangmode(dmask); + dbus_mode(dmask); flush(); clk(false); @@ -79,10 +87,10 @@ public class ChipImpl extends FtdiUart implements Chip { // we can pull it down (assert reset) from uart-mode, or we can // let it float upward from either mode. public void reset(boolean on) { - uart(1<<1, on ? (1<<1) : 0); + uart_and_cbus_mode(1<<1, on ? (1<<1) : 0); flush(); if (on) { - dbangmode(dmask); + dbus_mode(dmask); flush(); } } @@ -96,19 +104,19 @@ public class ChipImpl extends FtdiUart implements Chip { public boolean con() { flush(); //dmask &= ~(1<<0); - dbangmode(dmask); + dbus_mode(dmask); return (readPins() & (1<<0)) != 0; } public boolean rcon() { flush(); dmask &= ~(1<<0); - dbangmode(dmask); + dbus_mode(dmask); return (readPins() & (1<<0)) != 0; } public void con(boolean on) { flush(); dmask |= (1<<0); dbang(0, on); - dbangmode(dmask); + dbus_mode(dmask); } } diff --git a/src/com/ftdi/usb/FtdiUart.java b/src/com/ftdi/usb/FtdiUart.java index a07004a..a7ad5aa 100644 --- a/src/com/ftdi/usb/FtdiUart.java +++ b/src/com/ftdi/usb/FtdiUart.java @@ -1,6 +1,15 @@ package com.ftdi.usb; import java.io.*; +/** + * A Java wrapper around libftdi. + * + * Note: blocking reads are currently implemented by busy-waiting. + * This is really ugly. Check the linux kernel source to see how to + * get libftdi to do it properly. + * + * Flow control is also not properly supported. + */ public class FtdiUart { private SWIGTYPE_p_ftdi_context context = example.new_ftdi_context(); @@ -17,6 +26,29 @@ public class FtdiUart { purge(); } + /** + * Switch to uart mode, with read/write access to four CBUS lines. + * This function is used to write to the CBUS lines (re-invoke it to change their state). + * I think readPins() is used to read from them, but I'm not sure. + * + * @param cbus_mask a four-bit mask; set bit=1 to write to a CBUS line, bit=0 to read from it + * @param cbus_bits a four-bit mask; the bits to assert on the write-enabled CBUS lines + */ + public synchronized void uart_and_cbus_mode(int cbus_mask, int cbus_bits) { + example.ftdi_set_bitmode(context, (short)((cbus_mask << 4) | cbus_bits), (short)0x20); + } + + /** + * Switch to dbus mode; CBUS lines will be released (ie they will float). + * Use getInputStream()/getOutputStream() to read/write the eight DBUS lines. + * + * @param dbus_mask an eight-bit mask; set bit=1 to write to a DBUS line, bit=0 to read from it + */ + public synchronized void dbus_mode(int dbus_mask) { + example.ftdi_set_bitmode(context, (short)dbus_mask, (short)0x01); + } + + /** returns the instantaneous value present on the DBUS pins */ public synchronized int readPins() { try { getOutputStream().flush(); @@ -28,26 +60,11 @@ public class FtdiUart { return b[0]; } + /** purge the on-chip buffers */ public synchronized void purge() { example.ftdi_usb_purge_buffers(context); } - public synchronized void uart(int cbus_mask, int cbus_bits) { - example.ftdi_set_bitmode(context, (short)((cbus_mask << 4) | cbus_bits), (short)0x20); - } - public synchronized void dbangmode(int dmask) { - example.ftdi_set_bitmode(context, (short)dmask, (short)0x01); - } - - protected int dbits = 0; - - protected synchronized void dbang(int bit, boolean val) { - dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit))); - try { - out.write((byte)dbits); - } catch (IOException e) { throw new RuntimeException(e); } - } - private final InputStream in = new InputStream() { public int available() throws IOException { // FIXME diff --git a/src/edu/berkeley/slipway/FtdiBoard.java b/src/edu/berkeley/slipway/FtdiBoard.java index 885aa11..03b0d93 100644 --- a/src/edu/berkeley/slipway/FtdiBoard.java +++ b/src/edu/berkeley/slipway/FtdiBoard.java @@ -135,7 +135,7 @@ public class FtdiBoard extends Board { //System.out.println("avr reset => true"); chip.purge(); - chip.uart(1<<1, 1<<1); + chip.uart_and_cbus_mode(1<<1, 1<<1); //d.avrrst(true); //try { Thread.sleep(500); } catch (Exception e) { }