1 package edu.berkeley.slipway;
3 import edu.berkeley.abits.*;
4 import org.ibex.util.Log;
9 * This class is obsolete; it used to be an implementation intended
10 * for an RS-232 interface to Atmel's development kit board.
12 public abstract class SerialBoard implements Board {
15 private final SerialPort sp;
16 private final DataInputStream in;
17 private final DataOutputStream out;
19 public SerialBoard(SerialPort sp) throws IOException, UnsupportedCommOperationException, InterruptedException {
21 sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
22 sp.setFlowControlMode(sp.FLOWCONTROL_RTSCTS_OUT);
23 sp.setInputBufferSize(1024);
24 this.out = new DataOutputStream(sp.getOutputStream());
25 this.in = new DataInputStream(sp.getInputStream());
26 Log.debug(this, "consuming any leftover data on the serial port");
27 while(in.available() > 0) in.read();
33 Log.info(this, "resetting device");
37 Log.info(this, "deasserting reset signal");
41 } catch (InterruptedException e) { throw new RuntimeException(e); }
44 public void boot(Reader r) throws Exception {
45 throw new Error("not implemented");
48 public InputStream getInputStream() { return in; }
49 public OutputStream getOutputStream() { return out; }
52 public static SerialPort detectObitsPort() throws Exception {
53 Enumeration e = CommPortIdentifier.getPortIdentifiers();
54 while(e.hasMoreElements()) {
55 CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
56 Log.info(Demo.class, "trying " + cpi.getName());
57 if (cpi.getName().startsWith("/dev/cu.usbserial-"))
58 return new RXTXPort(cpi.getName());
59 if (cpi.getName().startsWith("/dev/ttyS0"))
60 return new RXTXPort(cpi.getName());
62 Log.info(Demo.class, "returning null...");