Moved TXFLUSH strobe from Python to C in CC2420 driver.
[goodfet] / firmware / apps / radios / ccspi.c
index dd86e8c..377a5f0 100644 (file)
@@ -139,14 +139,42 @@ void ccspi_handle_fn( uint8_t const app,
     txdata(app,verb,0);
     break;
   case CCSPI_RX:
     txdata(app,verb,0);
     break;
   case CCSPI_RX:
-    //Get the packet.
-    CLRSS;
-    ccspitrans8(CCSPI_RXFIFO);
-    for(i=0;i<32;i++)
-      cmddata[i]=ccspitrans8(0xde);
-    SETSS;
-    //no break
-    txdata(app,verb,32);
+#ifdef FIFOP
+     //Has there been an overflow?
+    if((!FIFO)&&FIFOP){
+      debugstr("Clearing overflow");
+      CLRSS;
+      ccspitrans8(0x08); //SFLUSHRX
+      SETSS;
+    }
+    
+    //Is there a packet?
+    if(FIFOP&&FIFO){
+      //Wait for completion.
+      while(SFD);
+      
+      //Get the packet.
+      CLRSS;
+      ccspitrans8(CCSPI_RXFIFO | 0x40);
+      //ccspitrans8(0x3F|0x40);
+      cmddata[0]=0xff; //to be replaced with length
+      for(i=0;i<cmddata[0]+2;i++)
+       cmddata[i]=ccspitrans8(0xde);
+      SETSS;
+      
+      //Flush buffer.
+      CLRSS;
+      ccspitrans8(0x08); //SFLUSHRX
+      SETSS;
+      txdata(app,verb,cmddata[0]+2);
+    }else{
+      //No packet.
+      txdata(app,verb,0);
+    }
+#else
+    debugstr("Can't RX a packet with SFD and FIFOP definitions.");
+    txdata(app,NOK,0);
+#endif
     break;
   case CCSPI_RX_FLUSH:
     //Flush the buffer.
     break;
   case CCSPI_RX_FLUSH:
     //Flush the buffer.
@@ -154,13 +182,55 @@ void ccspi_handle_fn( uint8_t const app,
     ccspitrans8(CCSPI_SFLUSHRX);
     SETSS;
     
     ccspitrans8(CCSPI_SFLUSHRX);
     SETSS;
     
-    //Return the packet.
-    txdata(app,verb,32);
+    txdata(app,verb,0);
+    break;
+  case CCSPI_REFLEX:
+    debugstr("Coming soon.");
+    txdata(app,verb,0);
     break;
     break;
-  case CCSPI_TX:
   case CCSPI_TX_FLUSH:
   case CCSPI_TX_FLUSH:
+     //Flush the buffer.
+    CLRSS;
+    ccspitrans8(CCSPI_SFLUSHTX);
+    SETSS;
+    
+    txdata(app,verb,0);
+    break;
+  case CCSPI_TX:
+#ifdef FIFOP
+    
+    //Wait for last packet to TX.
+    //while(ccspi_status()&BIT3);
+    
+    //Load the packet.
+    CLRSS;
+    ccspitrans8(CCSPI_TXFIFO);
+    for(i=0;i<cmddata[0];i++)
+      ccspitrans8(cmddata[i]);
+    SETSS;
+    
+    //Transmit the packet.
+    CLRSS;
+    ccspitrans8(0x04); //STXON
+    SETSS;
+    
+    //Wait for the pulse on SFD, after which the packet has been sent.
+    while(!SFD);
+    while(SFD);
+    
+    //Flush TX buffer.
+    CLRSS;
+    ccspitrans8(0x09); //SFLUSHTX
+    SETSS;
+    
+    txdata(app,verb,0);
+#else
+    debugstr("Can't TX a packet with SFD and FIFOP definitions.");
+    txdata(app,NOK,0);
+#endif
+    break;
   default:
   default:
-    debugstr("Not yet supported.");
+    debugstr("Not yet supported in CCSPI");
     txdata(app,verb,0);
     break;
   }
     txdata(app,verb,0);
     break;
   }