1 package com.atmel.fpslic;
7 * "Raw" access to an <i>unconfigured</i> FPSLIC -- used to load the initial bitstream.
9 public class FpslicRaw {
11 private FpslicPins pins;
13 public FpslicRaw(FpslicPins pins) throws IOException {
18 public void reset() throws IOException {
20 pins.avrrstPin(false);
21 pins.configDataPin(false);
29 try { Thread.sleep(500); } catch (Exception e) { }
30 if (pins.initPin()) throw new RuntimeException("INIT was still high after pulling RESET low");
33 try { Thread.sleep(500); } catch (Exception e) { }
34 if (!pins.initPin()) throw new RuntimeException("INIT was still low after releasing RESET");
40 public OutputStream getConfigStream() throws IOException {
42 return new OutputStream() {
45 public void write(int in) throws IOException {
46 for(int i=7; i>=0; i--) {
48 sendConfigBits((((in & 0xff) & (1<<i))!=0)?1:0, 1);
51 public void write(byte[] b, int off, int len) throws IOException {
52 for(int i=off; i<off+len; i++)
55 public void flush() throws IOException {
58 public void close() throws IOException {
62 // turn off the CON pin we've been pulling low...
66 throw new RuntimeException("initialization failed at " + bytes);
67 for(int i=0; i<100; i++) {
70 throw new RuntimeException("initialization failed at " + bytes);
71 try { Thread.sleep(20); } catch (Exception e) { }
80 public OutputStream getOutputStream() throws IOException { return pins.getUartOutputStream(); }
81 public InputStream getInputStream() throws IOException { return pins.getUartInputStream(); }
83 public void selfTest() throws Exception {
85 System.out.print("smoke check: ");
89 sendConfigBits(Integer.parseInt("00000000", 2), 8);
90 sendConfigBits(Integer.parseInt("10110111", 2), 8);
93 try { Thread.sleep(100); } catch (Exception e) { }
95 System.out.print((pin ? green(" [pass]") : red(" [FAIL]")));
97 // preamble shifted one bit earlier than it should be
99 sendConfigBits(Integer.parseInt("0000000", 2), 7);
100 sendConfigBits(Integer.parseInt("10110111", 2), 8);
101 sendConfigBits(0, 2);
103 try { Thread.sleep(100); } catch (Exception e) { }
104 pin = pins.initPin();
105 System.out.print((pin ? red(" [FAIL]") : green(" [pass]")));
107 // preamble shifted one bit later than it should be
109 sendConfigBits(Integer.parseInt("000000000", 2), 9);
110 sendConfigBits(Integer.parseInt("10110111", 2), 8);
111 //sendConfigBits(0, 1);
113 try { Thread.sleep(100); } catch (Exception e) { }
114 pin = pins.initPin();
115 System.out.print((pin ? red(" [FAIL]") : green(" [pass]")));
117 // plain 'ol bogus preamble
119 sendConfigBits(Integer.parseInt("00000000", 2), 8);
120 sendConfigBits(Integer.parseInt("11110111", 2), 8);
121 sendConfigBits(0, 1);
123 try { Thread.sleep(100); } catch (Exception e) { }
124 pin = pins.initPin();
125 System.out.print((pin ? red(" [FAIL]") : green(" [pass]")));
127 System.out.println();
130 // Private //////////////////////////////////////////////////////////////////////////////
132 private void sendConfigBits(int dat, int numbits) throws IOException {
133 for(int i=(numbits-1); i>=0; i--) {
134 boolean bit = (dat & (1<<i)) != 0;
135 pins.configDataPin(bit);
138 //dbits &= ~(1<<6); // let the clock fall with the next data bit, whenever it goes out
142 private static String red(Object o) { return "\033[31m"+o+"\033[0m"; }
143 private static String green(Object o) { return "\033[32m"+o+"\033[0m"; }