1 package com.atmel.fpslic;
6 public class FpslicUtil {
8 public static int lutSwap(int x) {
20 public static void readMode4(InputStream in, Fpslic fpslic) throws IOException {
22 BufferedReader br = new BufferedReader(new InputStreamReader(in));
23 for(String str = br.readLine(); str != null; str = br.readLine()) {
24 long foo = Long.parseLong(str, 16);
25 fpslic.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0));
32 public static void writeMode4(Writer w, Fpslic fpslic) throws IOException {
33 for(int x=0; x<fpslic.getWidth(); x++)
34 for(int y=0; y<fpslic.getWidth(); y++)
35 for(int z=0; z<255; z++) {
36 if ((z > 0x09 && z < 0x10) ||
37 (z > 0x11 && z < 0x20) ||
38 (z > 0x29 && z < 0x30) ||
39 (z > 0x39 && z < 0x40) ||
40 (z > 0x41 && z < 0x60) ||
41 (z > 0x67 && z < 0x70) ||
42 (z > 0x77 && z < 0xD0) ||
48 w.write(hex2(fpslic.mode4(z, y, x) & 0xff));
54 private static String hex2(int i) {
55 String ret = Integer.toString(i, 16);
56 while(ret.length() < 2) ret = "0"+ret;
57 return ret.toUpperCase();
60 public static synchronized String printLut(int lut, String xn, String yn, String zn) {
62 File f = File.createTempFile("mvsis", ".mvs");
65 FileOutputStream fos = new FileOutputStream(f);
66 PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos));
67 pw.println(".model clb");
68 pw.println(".inputs "+xn+" "+yn+" "+zn);
69 pw.println(".outputs O");
70 pw.println(".table "+xn+" "+yn+" "+zn+/*("X_xor_Y X_xor_Z Y_xor_Z")+*/ " -> O");
71 for(int i=8; i>=0; i--) {
72 int x = ((i & 0x01)!=0 ? 1 : 0);
73 int y = ((i & 0x02)!=0 ? 1 : 0);
74 int z = ((i & 0x04)!=0 ? 1 : 0);
78 //pw.print(" "+(x ^ y)+" ");
79 //pw.print(" "+(y ^ z)+" ");
80 //pw.print(" "+(z ^ y)+" ");
81 pw.print((lut & (1<<i))==0 ? 0 : 1);
87 Process p = Runtime.getRuntime().exec(new String[] { "mvsis", "-c", "simplify;print_factor", f.getAbsolutePath() });
88 new Gobble("mvsis: ", p.getErrorStream()).start();
89 //new Gobble("mvsis: ", p.getInputStream()).start();
90 BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
91 String ret = br.readLine();
94 } catch (Exception e) {
96 return "*mvsis_error*";
100 public static class Gobble extends Thread {
101 private final String header;
102 private final BufferedReader br;
103 public Gobble(String header, BufferedReader br) { this.br = br; this.header = header; }
104 public Gobble(String header, Reader r) { this(header, new BufferedReader(r)); }
105 public Gobble(String header, InputStream is) { this(header, new InputStreamReader(is)); }
108 for(String s = br.readLine(); s!=null; s=br.readLine())
109 System.err.println(header + s);
110 } catch (Exception e) {