1 package edu.berkeley.obits;
3 import edu.berkeley.obits.device.atmel.*;
4 import org.ibex.util.*;
9 public class AtmelSerial {
11 public static SerialPort detectObitsPort() throws Exception {
12 Enumeration e = CommPortIdentifier.getPortIdentifiers();
13 while(e.hasMoreElements()) {
14 CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
15 Log.info(AtmelSerial.class, "trying " + cpi.getName());
16 if (cpi.getName().startsWith("/dev/cu.usbserial-")) return new RXTXPort(cpi.getName());
17 if (cpi.getName().startsWith("/dev/ttyS0")) return new RXTXPort(cpi.getName());
19 Log.info(AtmelSerial.class, "returning null...");
23 public static void main(String[] s) throws Exception {
24 AvrDrone device = new AvrDrone(detectObitsPort());
25 At40k at40k = new At40k.At40k10(device);
28 long begin = System.currentTimeMillis();
29 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
30 for(String str = br.readLine(); str != null; str = br.readLine()) {
31 long foo = Long.parseLong(str, 16);
32 device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0));
34 if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets");
37 long end = System.currentTimeMillis();
38 Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
40 Log.info(AtmelSerial.class, "issuing command");
42 //at40k.iob_top(2, true).oe(false);
43 //at40k.iob_top(2, false).oe(false);
44 //at40k.iob_top(1, true).oe(false);
46 // this command confirmed to turn *on* led0
47 //at40k.iob_top(1, false).output(0);
49 for(int i=0; i<20; i++) {
50 at40k.iob_bot(i, false).output(0);
51 at40k.iob_bot(i, true).output(0);
55 //System.out.println("tick");
57 //System.out.println("tick");
58 //at40k.cell(0x01, 0x17).xlut((byte)0x);
60 at40k.cell(0x04, 0x17).xlut((byte)~0x10);
61 at40k.cell(0x04, 0x17).ylut((byte)0x10);
62 at40k.cell(0x04, 0x17).xo(true);
66 at40k.cell(0x01, 0x17).xin(4);
67 at40k.cell(0x01, 0x17).yin(4);
68 at40k.cell(0x01, 0x16).ylut((byte)0x00);
69 device.mode4(2, 0x17, 0x01, 0);
71 for(int i=0; i<10; i++) {
73 System.out.println("tick");
74 //at40k.cell(0x01, 0x17).xlut((byte)0xFF);
75 at40k.cell(0x00, 0x17).ylut((byte)0x00);
78 System.out.println("tick");
79 //at40k.cell(0x01, 0x17).xlut((byte)0x00);
80 at40k.cell(0x00, 0x17).ylut((byte)0xFF);
87 at40k.iob_top(0, true).output(0);
88 at40k.iob_top(0, true).oe(false);
89 at40k.iob_top(0, true).pullup();
93 Log.info(AtmelSerial.class, "issuing command");
94 at40k.iob_top(1, true).pulldown();
97 Log.info(AtmelSerial.class, "done");
99 } catch (Exception e) { e.printStackTrace(); }