2 # GoodFET EM260 Radio Client
4 # (C) 2010 Travis Goodspeed <travis at radiantmachines.com>
6 # This code is being rewritten and refactored. You've been warned!
8 # The EM260 is almost textbook SPI, except that the response cannot be
9 # read until after the nHOST_INT pin of the EM260 drops low and a dummy
10 # byte is read. That is, the sequence will look like the following:
12 # Transmit Host->Slave Data
13 # while(nHOST_INT); //Sleep until ready.
15 # Recv Slave->Host Data
17 # The delay is mandatory.
19 import sys, time, string, cStringIO, struct, glob, serial, os;
21 from GoodFETSPI import GoodFETSPI;
23 class GoodFETEM260(GoodFETSPI):
26 def EM260trans(self,data):
27 """Exchange data by EM260 SPI. (Slightly nonstandard.)"""
29 self.writecmd(0x01,0x82,len(data),data);
32 reply=ord(self.data[0]);
34 print "Warning: EM260 rebooted.";
35 return self.EM260trans(data);
37 print "Error: Aborted Transaction.";
38 #return self.EM260trans(data);
40 print "Error: Missing Frame Terminator.";
43 print "Error in EM260trans.";
48 """Read a byte from the given address."""
49 data=self.EM260trans([0xfe,0x01,self.seq,0x00,
54 s=s+"%02x " % ord(foo);
59 """Read the info bytes."""
60 version=self.EM260spiversion();
61 status=self.EM260spistatus();
62 print "Version: %i" % (version);
63 print "Status: %s" % (["dead","alive"][status]);
64 def EM260spiversion(self):
65 """Read the SPI version number from EM260."""
66 data=self.EM260trans([0x0A,0xA7]);
70 return self.EM260spiversion();
72 return self.EM260spiversion();
74 print "Version misread.";
78 def EM260spistatus(self):
79 """Read the status bit."""
80 data=self.EM260trans([0x0B,0xA7]);
84 return self.EM260spistatus();
86 return self.EM260spistatus();
88 print "Status misread.";