1 package com.atmel.fpslic;
3 import edu.berkeley.abits.*;
7 * Implementation of <tt>Board</tt> for Fpslic devices; subclass must
8 * implement methods to wiggle pins on the chip.
10 public abstract class FpslicBoard implements Board {
12 public FpslicBoard() throws IOException { }
14 public void reset() throws IOException {
24 try { Thread.sleep(500); } catch (Exception e) { }
25 if (initPin()) throw new IOException("INIT was still high after pulling RESET low");
28 try { Thread.sleep(500); } catch (Exception e) { }
29 if (!initPin()) throw new IOException("INIT was still low after releasing RESET");
35 public OutputStream getConfigStream() throws IOException {
37 return new OutputStream() {
40 public void write(int in) throws IOException {
41 for(int i=7; i>=0; i--) {
43 sendConfigBits((((in & 0xff) & (1<<i))!=0)?1:0, 1);
46 public void write(byte[] b, int off, int len) throws IOException {
47 for(int i=off; i<off+len; i++)
50 public void flush() throws IOException {
51 FpslicBoard.this.flush();
53 public void close() throws IOException {
57 throw new IOException("initialization failed at " + bytes);
58 for(int i=0; i<100; i++) {
61 throw new IOException("initialization failed at " + bytes);
62 try { Thread.sleep(20); } catch (Exception e) { }
65 FpslicBoard.this.close();
70 public void selfTest(SelfTestResultListener resultListener) throws IOException {
75 sendConfigBits(Integer.parseInt("00000000", 2), 8);
76 sendConfigBits(Integer.parseInt("10110111", 2), 8);
79 try { Thread.sleep(100); } catch (Exception e) { }
81 resultListener.reportTestResult(0, 4, pin);
83 // preamble shifted one bit earlier than it should be
85 sendConfigBits(Integer.parseInt("0000000", 2), 7);
86 sendConfigBits(Integer.parseInt("10110111", 2), 8);
89 try { Thread.sleep(100); } catch (Exception e) { }
91 resultListener.reportTestResult(1, 4, !pin);
93 // preamble shifted one bit later than it should be
95 sendConfigBits(Integer.parseInt("000000000", 2), 9);
96 sendConfigBits(Integer.parseInt("10110111", 2), 8);
97 //sendConfigBits(0, 1);
99 try { Thread.sleep(100); } catch (Exception e) { }
101 resultListener.reportTestResult(2, 4, !pin);
103 // plain 'ol bogus preamble
105 sendConfigBits(Integer.parseInt("00000000", 2), 8);
106 sendConfigBits(Integer.parseInt("11110111", 2), 8);
107 sendConfigBits(0, 1);
109 try { Thread.sleep(100); } catch (Exception e) { }
111 resultListener.reportTestResult(3, 4, !pin);
114 ////////////////////////////////////////////////////////////////////////////////
116 private void sendConfigBits(int bits, int numbits) throws IOException {
117 for(int i=(numbits-1); i>=0; i--) {
118 boolean bit = (bits & (1<<i)) != 0;
125 ////////////////////////////////////////////////////////////////////////////////
127 protected abstract void avrrstPin(boolean on) throws IOException;
128 protected abstract void cclkPin(boolean on) throws IOException;
129 protected abstract void configDataPin(boolean on) throws IOException;
130 protected abstract void resetPin(boolean on) throws IOException;
131 protected abstract boolean initPin() throws IOException;
132 protected abstract void releaseConPin() throws IOException;
133 protected abstract void conPin(boolean on) throws IOException;
135 protected abstract void purge() throws IOException;
136 protected abstract void flush() throws IOException;
137 protected abstract void close() throws IOException;