Exchange is now explicit; every command must return something.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Fri, 5 Jun 2009 14:00:32 +0000 (14:00 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Fri, 5 Jun 2009 14:00:32 +0000 (14:00 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@28 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/goodfet
firmware/apps/spi/spi.c

index 74c1655..78171b7 100755 (executable)
@@ -30,7 +30,7 @@ class Client:
         
         #Read and handle the initial command.
         time.sleep(1);
-        client.readcmd();
+        client.readcmd(); #Read the first command.
         if(self.verb!=0x7F):
             print "Verb is wrong.  Incorrect firmware?";
         
@@ -44,7 +44,7 @@ class Client:
         if count!=0:
             for d in data:
                 self.serialport.write(chr(d));
-        #self.readcmd();  #Uncomment this later, to ensure a response.
+        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));
@@ -59,7 +59,7 @@ class Client:
         """Read a byte of memory from the monitor."""
         self.data=[address&0xff,address>>8];
         self.writecmd(0,0x02,2,self.data);
-        self.readcmd();
+        #self.readcmd();
         return ord(self.data[0]);
     def peekword(self,address):
         """Read a word of memory from the monitor."""
@@ -68,8 +68,6 @@ class Client:
         """Set a byte of memory by the monitor."""
         self.data=[address&0xff,address>>8,value];
         self.writecmd(0,0x03,3,self.data);
-        self.readcmd();
-        #print "POKE returned %02x" % ord(self.data[0]);
         return ord(self.data[0]);
     
     def monitortest(self):
@@ -89,12 +87,12 @@ class Client:
         """Moved the FET into the SPI application."""
         print "Initializing SPI.";
         self.writecmd(1,0x10,0,self.data); #SPI/SETUP
-        self.readcmd();
+        #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();
+        #self.readcmd();
         
         if self.app!=1 or self.verb!=0:
             print "Error in SPI transaction; app=%02x, verb=%02x" % (self.app, self.verb);
index b0b5323..2b53914 100644 (file)
 #define CLRCLK P5OUT&=~SCK
 #define READMISO (P5IN&MISO?1:0)
 
+
+
 //! Set up the pins for SPI mode.
 unsigned char spisetup(){
   P5DIR|=MOSI+SCK+SS;
   P5DIR&=~MISO;
+  P5OUT|=SS;
 }
 
 //! Read and write an SPI bit.
@@ -39,7 +42,9 @@ unsigned char spitrans8(unsigned char byte){
   unsigned int bit;
   //This function came from the SPI Wikipedia article.
   //Minor alterations.
+  
+  P5OUT&=~SS;
+  
   for (bit = 0; bit < 8; bit++) {
     /* write MOSI on trailing edge of previous clock */
     if (byte & 0x80)
@@ -59,6 +64,8 @@ unsigned char spitrans8(unsigned char byte){
     byte |= READMISO;
     CLRCLK;
   }
+  
+  P5OUT|=SS;
  
   return byte;
 }