From d44022802297d495dfb0de032251f62d0021a1f6 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 22 Sep 2006 04:04:11 +0100 Subject: [PATCH] checkpoint --- src/com/atmel/fpslic/FpslicPins.java | 23 +++++++++ src/com/atmel/fpslic/FpslicPinsUsb.java | 81 +++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/com/atmel/fpslic/FpslicPins.java create mode 100644 src/com/atmel/fpslic/FpslicPinsUsb.java diff --git a/src/com/atmel/fpslic/FpslicPins.java b/src/com/atmel/fpslic/FpslicPins.java new file mode 100644 index 0000000..36bf651 --- /dev/null +++ b/src/com/atmel/fpslic/FpslicPins.java @@ -0,0 +1,23 @@ +package com.atmel.fpslic; +import com.ftdi.usb.*; +import java.io.*; + +/** + * Exposes the raw pin-level configuration interface to the FPSLIC + */ +public interface FpslicPins { + public void avrrstPin(boolean on) throws IOException; + public void cclkPin(boolean on) throws IOException; + public void configDataPin(boolean on) throws IOException; + public void resetPin(boolean on) throws IOException; + public boolean initPin() throws IOException; + public void releaseConPin() throws IOException; + public void conPin(boolean on) throws IOException; + + public void flush() throws IOException; + public void close() throws IOException; + + public InputStream getUartInputStream() throws IOException; + public OutputStream getUartOutputStream() throws IOException; +} + diff --git a/src/com/atmel/fpslic/FpslicPinsUsb.java b/src/com/atmel/fpslic/FpslicPinsUsb.java new file mode 100644 index 0000000..ebd25d3 --- /dev/null +++ b/src/com/atmel/fpslic/FpslicPinsUsb.java @@ -0,0 +1,81 @@ +package com.atmel.fpslic; +import com.ftdi.usb.*; +import java.io.*; + +/** + * Exposes the raw pin-level configuration interface to the FPSLIC + */ +public class FpslicPinsUsb implements FpslicPins { + + private FtdiUart ftdiuart; + + public FpslicPinsUsb(FtdiUart ftdiuart) { + this.ftdiuart = ftdiuart; + } + + public void avrrstPin(boolean on) throws IOException { setDBusLine(7, on); } + public void cclkPin(boolean on) throws IOException { setDBusLine(6, on); } + public void configDataPin(boolean on) throws IOException { setDBusLine(5, on); } + public boolean initPin() throws IOException { flush(); return (ftdiuart.readPins() & (1<<4))!=0; } + + // tricky: RESET has a weak pull-up, and is wired to a CBUS line. So, + // we can pull it down (assert reset) from uart-mode, or we can + // let it float upward from either mode. + public void resetPin(boolean on) throws IOException { + ftdiuart.uart_and_cbus_mode(1<<1, on ? (1<<1) : 0); + flush(); + if (on) { + ftdiuart.dbus_mode(dmask); + flush(); + } + } + + public void flush() throws IOException { ftdiuart.getOutputStream().flush(); } + + private int dbits = 0; + public void setDBusLine() throws IOException { + ftdiuart.getOutputStream().write((byte)dbits); + } + public void clearDBusLines() throws IOException { + dbits = 0; + setDBusLine(); + } + public void setDBusLine(int bit, boolean val) throws IOException { + dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit))); + setDBusLine(); + } + + public void releaseConPin() throws IOException { + dmask &= ~(1<<0); + ftdiuart.dbus_mode(dmask); + flush(); + } + + public void conPin(boolean on) throws IOException { + dmask |= (1<<0); + ftdiuart.dbus_mode(dmask); + setDBusLine(0, on); + flush(); + } + + public void close() throws IOException { + // switching to uart mode will implicitly release AVRRST + avrrstPin(false); + ftdiuart.purge(); + ftdiuart.uart_and_cbus_mode(1<<1, 1<<1); + } + + private int dmask = + (1<<0) | + (1<<1) | + (1<<2) | + //(1<<3) | + //(1<<4) | + (1<<5) | + (1<<6) | + (1<<7); + + public InputStream getUartInputStream() throws IOException { return ftdiuart.getInputStream(); } + public OutputStream getUartOutputStream() throws IOException { return ftdiuart.getOutputStream(); } +} + -- 1.7.10.4