X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2Fgoodfet;h=74c16559899095cc0f21b74ecc1ecef4b9af674e;hp=155247589fbd3c4bacd2b74dfefacc98b9fc7233;hb=0652c424f95ebdb6c9be17edc0a4d1057432142f;hpb=ccd3ebd9ecb44556ecd91f11d16596c409982f44 diff --git a/client/goodfet b/client/goodfet index 1552475..74c1655 100755 --- a/client/goodfet +++ b/client/goodfet @@ -29,36 +29,32 @@ class Client: self.serialport.flushOutput() #Read and handle the initial command. + time.sleep(1); client.readcmd(); - client.handlecmd(); + if(self.verb!=0x7F): + print "Verb is wrong. Incorrect firmware?"; + - time.sleep(1); def writecmd(self, app, verb, count, data): + """Write a command and some data to the GoodFET.""" self.serialport.write(chr(app)); self.serialport.write(chr(verb)); self.serialport.write(chr(count)); - print "count=%02x, len(data)=%04x" % (count,len(data)); - for d in data: - self.serialport.write(chr(d)); + #print "count=%02x, len(data)=%04x" % (count,len(data)); + if count!=0: + for d in data: + self.serialport.write(chr(d)); + #self.readcmd(); #Uncomment this later, to ensure a response. def readcmd(self): + """Read a reply from the GoodFET.""" self.app=ord(self.serialport.read(1)); self.verb=ord(self.serialport.read(1)); self.count=ord(self.serialport.read(1)); if self.count>0: self.data=self.serialport.read(self.count); - print "%02x %02x %02x" % (self.app, self.verb, self.count); - def handlemonitor(self): - if self.verb==0x7E: - print "Monitor: NOK"; - if self.verb==0x7F: - print "Monitor: OK"; - def handlecmd(self): - if self.app==0: - #print "Monitor command." - self.handlemonitor(); - else: - print "Unknown application %02x." % self.app + #print "%02x %02x %02x" % (self.app, self.verb, self.count); + #Monitor stuff def peekbyte(self,address): """Read a byte of memory from the monitor.""" self.data=[address&0xff,address>>8]; @@ -73,7 +69,7 @@ class Client: self.data=[address&0xff,address>>8,value]; self.writecmd(0,0x03,3,self.data); self.readcmd(); - print "POKE returned %02x" % ord(self.data[0]); + #print "POKE returned %02x" % ord(self.data[0]); return ord(self.data[0]); def monitortest(self): @@ -85,13 +81,31 @@ class Client: self.pokebyte(0x0021,0); #Drop LED if self.peekbyte(0x0021)!=0: print "ERROR, P1OUT not cleared."; + self.pokebyte(0x0021,1); #Light LED print "Self-test complete."; + + def spisetup(self): + """Moved the FET into the SPI application.""" + print "Initializing SPI."; + self.writecmd(1,0x10,0,self.data); #SPI/SETUP + self.readcmd(); + def spitrans8(self,byte): + """Read and write 8 bits by SPI.""" + self.data=[byte]; + self.writecmd(1,0,1,self.data); #SPI exchange + self.readcmd(); + + if self.app!=1 or self.verb!=0: + print "Error in SPI transaction; app=%02x, verb=%02x" % (self.app, self.verb); + return ord(self.data[0]); client=Client(); client.serInit("/dev/ttyUSB0") - - client.monitortest(); +client.spisetup(); +while 1: + print "%02x" % client.spitrans8(5); + time.sleep(0.1);