Working Simpliciti implementation.
[goodfet] / shellcode / chipcon / cc1110 / rxpacket.c
index 9bea242..0535f0b 100644 (file)
@@ -1,20 +1,42 @@
 #include <cc1110.h>
 #include "cc1110-ext.h"
 
-char __xdata at 0xfe00 packet[256] ;
-
+#define MAXLEN 0xFF
+char __xdata at 0xfe00 packet[MAXLEN] ;
 
 //! Receives a packet out of the radio from 0xFE00.
 void main(){
-  unsigned char len=100, i=0;
-  RFST=RFST_SRX;     //Begin to receive.
-  while(i!=len+1){
-    while(RFTXRXIF); //Wait for byte to be ready.
+  unsigned char len=16, i=0;
+  
+  do{
+    //1-out the buffer.
+    for(i=0;i<64;i++)
+      packet[i]=0xFF;
+    i=0;
+    
+    //Disable interrupts.
+    RFTXRXIE=0;
+    
+    //idle a bit.
+    RFST=RFST_SIDLE;
+    while(MARCSTATE!=MARC_STATE_IDLE);
     
-    RFTXRXIF=0;      //Clear the flag.
-    packet[i++]=RFD; //Grab the next byte.
-    len=packet[0];   //First byte of the packet is the length.
-  }
-  RFST = RFST_SIDLE; //End transmit.
+    //Begin to receive.
+    RFST=RFST_SRX;
+    while(MARCSTATE!=MARC_STATE_RX);
+  
+    while(i<len+3){ //len+3 if status is appended.
+      while(!RFTXRXIF); //Wait for byte to be ready.
+      RFTXRXIF=0;      //Clear the flag.
+      
+      packet[i++]=RFD; //Grab the next byte.
+      len=packet[0];   //First byte of the packet is the length.
+    }
+    RFST = RFST_SIDLE; //End receive.
+    
+    //This while loop can be used for filtering.  Unused for now.
+  }while(0); //packet[0]==(char) 0x0f || packet[1]==(char) 0xFF || packet[9]==(char) 0x03);
+  
   HALT;
 }
+