Enough NRF support to packet sniff.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 20 May 2010 07:23:05 +0000 (07:23 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 20 May 2010 07:23:05 +0000 (07:23 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@534 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

firmware/apps/radios/nrf.c
firmware/include/nrf.h

index f65d2e5..1e1f937 100644 (file)
 //BIT0 should be SS, but in point of fact it is IRQ.
 //BIT4 is actually SS, BIT5 is CE.
 #define SS BIT4
+#define CE BIT5;
 
-//This could be more accurate.
-//Does it ever need to be?
-#define NRFSPEED 0
-#define NRFDELAY(x)
-//delay(x)
+#define RADIOACTIVE  P5OUT|=CE
+#define RADIOPASSIVE P5OUT&=~CE
 
 
 //! Set up the pins for NRF mode.
 void nrfsetup(){
   P5OUT|=SS;
   P5DIR&=~MISO;
-  P5DIR|=MOSI+SCK+SS;
+  P5DIR|=MOSI+SCK+SS+CE;
   
   
   //Begin a new transaction.
@@ -73,6 +71,7 @@ u8 nrf_regwrite(u8 reg, const u8 *buf, int len){
     nrftrans8(*buf++);
   
   P5OUT|=SS;
+  return reg;//status
 }
 //! Reads a register
 u8 nrf_regread(u8 reg, u8 *buf, int len){
@@ -83,6 +82,7 @@ u8 nrf_regread(u8 reg, u8 *buf, int len){
     *buf++=nrftrans8(0);
   
   P5OUT|=SS;
+  return reg;//status
 }
 
 //! Handles a Nordic RF command.
@@ -91,6 +91,8 @@ void nrfhandle(unsigned char app,
               unsigned long len){
   unsigned long i;
   
+  RADIOPASSIVE;
+  
   //Raise !SS to end transaction, just in case we forgot.
   P5OUT|=SS;
   nrfsetup();
@@ -123,11 +125,38 @@ void nrfhandle(unsigned char app,
     P5OUT|=SS;  //Raise !SS to end transaction.
     txdata(app,verb,len);
     break;
-    
   case SETUP:
     nrfsetup();
     txdata(app,verb,0);
     break;
+  case NRF_RX:
+    RADIOPASSIVE;
+    
+    //Get the packet.
+    P5OUT&=~SS;
+    nrftrans8(NRF_R_RX_PAYLOAD);
+    for(i=0;i<32;i++)
+      cmddata[i]=nrftrans8(0xde);
+    P5OUT|=SS;
+    //no break
+    txdata(app,verb,32);
+    break;
+  case NRF_RX_FLUSH:
+    //Flush the buffer.
+    P5OUT&=~SS;
+    nrftrans8(NRF_FLUSH_RX);
+    P5OUT|=SS;
+    
+    //Return the packet.
+    txdata(app,verb,32);
+    break;
+  case NRF_TX:
+  default:
+    debugstr("Not yet supported.");
+    txdata(app,verb,0);
+    break;
   }
   
+  P5OUT|=SS;//End session
+  RADIOACTIVE;
 }
index dd901b1..7abdf36 100644 (file)
@@ -3,18 +3,26 @@
   \brief Constants for NRF Driver
 */
 
-//Nordic RF Instructions
+//Nording RF Commands
+
+//Grab a packet, if one is available.
+#define NRF_RX 0x80
+//Send a packet.
+#define NRF_TX 0x81
+//Flsuh RX
+#define NRF_RX_FLUSH 0x82
+
+//Nordic RF SPI Instructions
 #define NRF_R_REGISTER   0x00
 #define NRF_W_REGISTER   0x20
-#define NRF_R_RX_PAYLOAD 0x60
+#define NRF_R_RX_PAYLOAD 0x61
 #define NRF_W_TX_PAYLOAD 0xA0
-#define NRF_FLUSH_TX     0xE0
-#define NRF_FLUSH_RX     0xE1
-#define NRF_REUSE_TX_PL  0xE2
+#define NRF_FLUSH_TX     0xE1
+#define NRF_FLUSH_RX     0xE2
+#define NRF_REUSE_TX_PL  0xE3
 #define NRF_NOP          0xFF
 
 
-
 //NRF24L01+ Registers
 //These aren't yet used, but are included for later
 //translation to XML.