unsigned long i;
u8 j;
- //debugstr("Chipcon SPI handler.");
-
switch(verb){
case PEEK:
cmddata[0]|=0x40; //Set the read bit.
);
txdata(app,verb,0);
break;
+ case CCSPI_REPEAT_RX:
+
+ /* CCSPI_REPEAT_RX repeatedly requests new packets, forwarding
+ them to the server without waiting for the next request. This
+ allows for sniffing of packets that would otherwise overflow
+ the buffer.
+ */
+
+ //debugstr("Looping CCSPI_RX.");
+
+ //Loop forever in RX mode.
+ while(1){
+ ccspi_handle_fn(app,CCSPI_RX,0);
+ }
+ break;
case CCSPI_RX:
#ifdef FIFOP
//Has there been an overflow?
+
if((!FIFO)&&FIFOP){
debugstr("Clearing overflow");
CLRSS;
ccspitrans8(0x08); //SFLUSHRX
+ ccspitrans8(0x08); //SFLUSHRX
SETSS;
txdata(app,verb,0); //no packet
return;
}
-
+
+ /* Uncomment this to wait around a bit for the packet.
+ Might reduce dropped packet count.
+ i=1000; //Number of tries.
+ while(!(FIFOP&&FIFO) && i--);
+ */
+
//Is there a packet?
- if(FIFOP&&FIFO){
+ if (FIFOP && FIFO){
//Wait for completion.
while(SFD);
A software fix is to reset the CC2420 between packets. This
works, but a better solution is desired.
*/
- for(i=0;i<cmddata[0]+1;i++)
- //for(i=0;FIFO && i<0x80;i++)
+ //for(i=0;i<cmddata[0]+1;i++)
+ for(i=0;FIFO && i<0x80;i++)
cmddata[i]=ccspitrans8(0x00);
SETSS;
*/
//Only transmit a packet if the length is legal.
- if(cmddata[0]&0x80) i=0;
+ if(cmddata[0]&0x80 || cmddata[0]==0) i=0;
txdata(app,verb,i);
}else{
+
//No packet.
txdata(app,verb,0);
}