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;
}
(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) |
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);
// 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) {
}
}
- 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);
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);
* @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);
}
*
* @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);
}
%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;
}
%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;
}
%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;
}
%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;
}
%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;
}
%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;
}
%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;
}
%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;
}
%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;
}
%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;
}
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");
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();
out.flush();
}
- public void reset() {
+ public void reset() throws IOException {
chip.doReset();
}