checkpoint
authoradam <adam@megacz.com>
Wed, 20 Sep 2006 09:05:31 +0000 (10:05 +0100)
committeradam <adam@megacz.com>
Wed, 20 Sep 2006 09:05:31 +0000 (10:05 +0100)
src/com/atmel/fpslic/Chip.java
src/com/atmel/fpslic/ChipImpl.java
src/com/ftdi/usb/FtdiUart.java
src/com/ftdi/usb/ftdi.i
src/edu/berkeley/obits/device/atmel/AvrDrone.java
src/edu/berkeley/slipway/Board.java
src/edu/berkeley/slipway/FtdiBoard.java

index 23f1be3..3bc97e8 100644 (file)
@@ -5,18 +5,18 @@ import java.io.*;
 
 public interface Chip {
     
-    public void    doReset();
-    public void    reset(boolean on);
-    public void    avrrst(boolean on);
-    public void    config(boolean bit);
-    public void    config(int data, int numbits);
-    public boolean initErr();
+    public void    doReset() throws IOException;
+    public void    reset(boolean on) throws IOException;
+    public void    avrrst(boolean on) throws IOException;
+    public void    config(boolean bit) throws IOException;
+    public void    config(int data, int numbits) throws IOException;
+    public boolean initErr() throws IOException;
 
-    public void    con(boolean b);
-    public boolean con();
-    public boolean rcon();
+    public void    con(boolean b) throws IOException;
+    public boolean con() throws IOException;
+    public boolean rcon() throws IOException;
 
     //remove
-    public void flush();
-    public int readPins();
+    public void flush() throws IOException;
+    public int readPins() throws IOException;
 }
index 5aa9d89..84a41c5 100644 (file)
@@ -14,26 +14,26 @@ public class ChipImpl extends FtdiUart implements Chip {
         (1<<6) |
         (1<<7);
 
-    public ChipImpl() {
+    public ChipImpl() throws IOException {
         super(0x6666, 0x3133, 1500 * 1000);
         doReset();
     }
 
-    public void flush() {
+    public void flush() throws IOException {
         try {
             getOutputStream().flush();
         } catch (Exception e) { throw new RuntimeException(e); }
     }
 
     protected int dbits = 0;
-    protected synchronized void dbang(int bit, boolean val) {
+    protected synchronized void dbang(int bit, boolean val) throws IOException {
         dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit)));
         try {
             getOutputStream().write((byte)dbits);
         } catch (IOException e) { throw new RuntimeException(e); }
     }
 
-    public void doReset() {
+    public void doReset() throws IOException {
 
         dmask =
             (1<<0) |
@@ -72,9 +72,9 @@ public class ChipImpl extends FtdiUart implements Chip {
         con(false);
     }
 
-    public void config(boolean bit) { config(bit?1:0, 1); }
-    public void config(int dat) { config(dat, 8); }
-    public void config(int dat, int numbits) {
+    public void config(boolean bit) throws IOException { config(bit?1:0, 1); }
+    public void config(int dat) throws IOException { config(dat, 8); }
+    public void config(int dat, int numbits) throws IOException {
         for(int i=(numbits-1); i>=0; i--) {
             boolean bit = (dat & (1<<i)) != 0;
             data(bit);
@@ -86,7 +86,7 @@ public class ChipImpl extends FtdiUart implements Chip {
     // 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 reset(boolean on) {
+    public void reset(boolean on) throws IOException {
         uart_and_cbus_mode(1<<1, on ? (1<<1) : 0);
         flush();
         if (on) {
@@ -95,25 +95,25 @@ public class ChipImpl extends FtdiUart implements Chip {
         }
     }
 
-    public void avrrst(boolean on) { dbang(7, on); }
-    public void clk(boolean on)    { dbang(6, on); }
-    public void data(boolean on)   { dbang(5, on); }
+    public void avrrst(boolean on) throws IOException { dbang(7, on); }
+    public void clk(boolean on)    throws IOException { dbang(6, on); }
+    public void data(boolean on)   throws IOException { dbang(5, on); }
 
-    public boolean initErr()       { flush(); return (readPins() & (1<<4))!=0; }
+    public boolean initErr()       throws IOException { flush(); return (readPins() & (1<<4))!=0; }
 
-    public boolean con() {
+    public boolean con() throws IOException {
         flush();
         //dmask &= ~(1<<0);
         dbus_mode(dmask);
         return (readPins() & (1<<0)) != 0;
     }
-    public boolean rcon() {
+    public boolean rcon() throws IOException {
         flush();
         dmask &= ~(1<<0);
         dbus_mode(dmask);
         return (readPins() & (1<<0)) != 0;
     }
-    public void con(boolean on) {
+    public void con(boolean on) throws IOException {
         flush();
         dmask |= (1<<0);
         dbang(0, on);
index a7ad5aa..c897b4e 100644 (file)
@@ -17,7 +17,7 @@ public class FtdiUart {
     public OutputStream getOutputStream() { return out; }
     public InputStream  getInputStream() { return in; }
 
-    public FtdiUart(int vendor, int product, int baud) {
+    public FtdiUart(int vendor, int product, int baud) throws IOException {
         example.ftdi_init(context);
         example.ftdi_usb_open(context, vendor, product);
         example.ftdi_usb_reset(context);
@@ -34,7 +34,7 @@ public class FtdiUart {
      *  @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) {
+    public synchronized void uart_and_cbus_mode(int cbus_mask, int cbus_bits) throws IOException {
         example.ftdi_set_bitmode(context, (short)((cbus_mask << 4) | cbus_bits), (short)0x20);
     }
 
@@ -44,24 +44,20 @@ public class FtdiUart {
      * 
      *  @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) {
+    public synchronized void dbus_mode(int dbus_mask) throws IOException {
         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();
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+    public synchronized int readPins() throws IOException {
+        getOutputStream().flush();
         byte[] b = new byte[1];
         example.ftdi_read_pins(context, b);
         return b[0];
     }
 
     /** purge the on-chip buffers */
-    public synchronized void purge() {
+    public synchronized void purge() throws IOException {
         example.ftdi_usb_purge_buffers(context);
     }
 
index 3fbcc67..0a8bcf7 100644 (file)
@@ -21,7 +21,7 @@ struct ftdi_eeprom *new_ftdi_eeprom() {
 %exception ftdi_init {
   $action
   if (result) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftdi_init() returned nonzero result");
     return $null;
   }
@@ -31,7 +31,7 @@ int ftdi_init(struct ftdi_context *ftdi);
 %exception ftdi_read_data {
   $action
   if (result<0) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftdi_read_data() returned negative result");
     return $null;
   }
@@ -41,7 +41,7 @@ int ftdi_read_data(struct ftdi_context *ftdi, signed char buf[], int size);
 %exception ftdi_write_data {
   $action
   if (result<0) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftdi_write_data() returned negative result");
     return $null;
   }
@@ -51,7 +51,7 @@ int ftdi_write_data(struct ftdi_context *ftdi, signed char buf[], int size);
 %exception ftdi_usb_open {
   $action
   if (result) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftdi_usb_open() returned nonzero result");
     return $null;
   }
@@ -61,7 +61,7 @@ int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
 %exception ftdi_set_baudrate {
   $action
   if (result) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftdftdi_set_baudrate() returned nonzero result");
     return $null;
   }
@@ -71,7 +71,7 @@ int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
 %exception ftdi_set_line_property {
   $action
   if (result) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftdi_set_line_property() returned nonzero result");
     return $null;
   }
@@ -81,7 +81,7 @@ int ftdi_set_line_property(struct ftdi_context *ftdi, int bits, int sbit, int pa
 %exception ftdi_set_bitmode {
   $action
   if (result) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftftdi_set_bitmodeeturned nonzero result");
     return $null;
   }
@@ -91,7 +91,7 @@ int ftdi_set_bitmode(struct ftdi_context *ftdi, unsigned char bitmask, unsigned
 %exception ftdi_read_pins {
   $action
   if (result<0) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftdi_read_pins() returned negative result");
     return $null;
   }
@@ -101,7 +101,7 @@ int ftdi_read_pins(struct ftdi_context *ftdi, signed char pins[]);
 %exception ftdi_setflowctrl {
   $action
   if (result) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftdi_setflowctrl() returned nonzero result");
     return $null;
   }
@@ -111,7 +111,7 @@ int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl);
 %exception ftdi_usb_reset {
   $action
   if (result) {
-    jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+    jclass clazz = (*jenv)->FindClass(jenv, "java/io/IOException");
     (*jenv)->ThrowNew(jenv, clazz, "ftdi_usb_reset() nonzero result");
     return $null;
   }
index 06849cd..6776b8b 100644 (file)
@@ -21,7 +21,13 @@ public class AvrDrone extends AtmelDevice {
         init();
     } 
 
-    public void reset() { board.reset(); }
+    public void reset() throws DeviceException {
+        try {
+            board.reset();
+        } catch (IOException e) {
+            throw new DeviceException(e);
+        }
+    }
 
     private void init() throws IOException {
         Log.debug(this, "waiting for device to identify itself");
index ed0352f..f1c51f9 100644 (file)
@@ -8,7 +8,7 @@ import gnu.io.*;
 
 public abstract class Board {
 
-    public abstract void reset();
+    public abstract void reset() throws IOException;
     public abstract void boot(Reader r) throws Exception;
     public abstract InputStream getInputStream();
     public abstract OutputStream getOutputStream();
index 03b0d93..b32ba76 100644 (file)
@@ -29,7 +29,7 @@ public class FtdiBoard extends Board {
         out.flush();
     }
 
-    public void reset() {
+    public void reset() throws IOException {
         chip.doReset();
     }