More EM260 code. RNG works only after another board has initialized the chip.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 8 Jul 2010 19:00:22 +0000 (19:00 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 8 Jul 2010 19:00:22 +0000 (19:00 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@672 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFETEM260.py
client/goodfet.em260

index 0fedd58..6bfb1ed 100644 (file)
@@ -53,33 +53,42 @@ class GoodFETEM260(GoodFETSPI):
     def EZSPtrans(self,frame):
         """Send an EZSP frame."""
         data=self.EM260trans([0xFE,len(frame)+2,
-                              self.seq,0x00,
+                              self.seq&0xFF,0x00,
                               ]+frame+[
                               0xA7]);
-        #s="";
+        #s="EZSP< ";
         #for foo in data:
         #    s=s+"%02x " % ord(foo);
         #print s;
+        
         if ord(data[0])!=0xFE:
             print "EZSP error: 0x%02x" % ord(data[0]);
+        if ord(data[4])==0x58:
+            print "EZSP Invalid Command";
+            return None;
         if frame[0]!=ord(data[4]):
             print "EZSP warning: Command 0x%02x returned type 0x%02x." % (
                 frame[0],ord(data[4]));
         self.seq=self.seq+1;
         return data;
-        #return ord(data[0]);
         
     def peek8(self,adr):
-        """Read a byte from the given address."""
+        """Read a byte from the given address.  Untested."""
         
-        data=self.EZSPtrans([0x47,adr&0xFF]);
+        data=self.EZSPtrans([0x47,adr&0xFF,10]);
         
-        return ord(data[0]);
-    
+        return ord(data[6]);
+    def poke8(self,adr,val):
+        """Poke a value into RAM.  Untested"""
+        self.EZSPtrans([0x46,adr&0xFF,1,val&0xFF]);
+        return val;
     def rand16(self):
         """Read a byte from the given address."""
         
         data=self.EZSPtrans([0x49]);
+        if data==None:
+            print "Insufficient random data.";
+            return 0;
         return ord(data[6])+(ord(data[7])<<8);
     
     def info(self):
index 3ec661a..c792bf6 100755 (executable)
@@ -16,12 +16,14 @@ from intelhex import IntelHex;
 if(len(sys.argv)==1):
     print "Usage: %s verb [objects]\n" % sys.argv[0];
     print "%s info" % sys.argv[0];
-    print "%s dump $foo.rom [0x$start 0x$stop]" % sys.argv[0];
+    print "%s test" % sys.argv[0];
+    print "%s randtest" % sys.argv[0];
+    #print "%s dump $foo.rom [0x$start 0x$stop]" % sys.argv[0];
     #print "%s erase" % sys.argv[0];
     #print "%s flash $foo.rom [0x$start 0x$stop]" % sys.argv[0];
     #print "%s verify $foo.rom [0x$start 0x$stop]" % sys.argv[0];
     print "%s peek 0x$start [0x$stop]" % sys.argv[0];
-    #print "%s poke 0x$adr 0x$val" % sys.argv[0];
+    print "%s poke 0x$adr 0x$val" % sys.argv[0];
     sys.exit();
 
 #Initialize FET and set baud rate
@@ -36,16 +38,24 @@ client.SPIsetup();
 client.EM260spiversion();
 
 if(sys.argv[1]=="info"):
-       client.info();
+    client.info();
 if(sys.argv[1]=="test"):
-       print "Grabbing info three times."
-       client.info();
-       client.info();
-       client.info();
-       
-       print "Some random numbers from EZSP."
-       for foo in range(0,4):
-           print "%04x" % client.rand16();
+    print "Grabbing info three times."
+    client.info();
+    client.info();
+    client.info();
+    
+    print "Some random numbers from EZSP."
+    for foo in range(0,4):
+        print "%04x" % client.rand16();
+if(sys.argv[1]=="randtest"):
+    print "Some random numbers from EZSP."
+    max=2**33;
+    foo=0;
+    while foo<max:
+        print "%08x: %04x" % (foo,client.rand16());
+        sys.stdout.flush()
+        foo=foo+1;
 
 if(sys.argv[1]=="dump"):
     f = sys.argv[2];
@@ -77,3 +87,13 @@ if(sys.argv[1]=="peek"):
     while start<=stop:
         print "%04x: %02x" % (start,client.peek8(start));
         start=start+1;
+if(sys.argv[1]=="poke"):
+    start=0x0000;
+    if(len(sys.argv)>2):
+       start=int(sys.argv[2],16);
+    val=0xde;
+    if(len(sys.argv)>3):
+        val=int(sys.argv[3],16);
+    print "Poking %02x to be %02x." % (start,val);
+    client.poke8(start,val);
+