From ba0e5551e39ee0d35f21cf42dfc8d645dfe63b79 Mon Sep 17 00:00:00 2001 From: travisutk Date: Mon, 21 Feb 2011 03:51:48 +0000 Subject: [PATCH] Improving CC2420 packet reception. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@929 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- firmware/apps/radios/ccspi.c | 34 ++++++++++++++++++++++++++-------- firmware/include/ccspi.h | 2 ++ firmware/platforms/telosb.h | 3 +++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/firmware/apps/radios/ccspi.c b/firmware/apps/radios/ccspi.c index dd86e8c..cc44d4b 100644 --- a/firmware/apps/radios/ccspi.c +++ b/firmware/apps/radios/ccspi.c @@ -139,14 +139,28 @@ void ccspi_handle_fn( uint8_t const app, 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 + //Wait for any incoming packet to finish. + while(SFD); + + //Is there a packet? + if((!SFD)&FIFOP){ + //Get the packet. + CLRSS; + ccspitrans8(CCSPI_RXFIFO); + for(i=0;i<32;i++) + cmddata[i]=ccspitrans8(0xde); + SETSS; + //no break + txdata(app,verb,32); + }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. @@ -157,6 +171,10 @@ void ccspi_handle_fn( uint8_t const app, //Return the packet. txdata(app,verb,32); break; + case CCSPI_REFLEX: + debugstr("Coming soon."); + txdata(app,verb,0); + break; case CCSPI_TX: case CCSPI_TX_FLUSH: default: diff --git a/firmware/include/ccspi.h b/firmware/include/ccspi.h index a0e787e..a8f948f 100644 --- a/firmware/include/ccspi.h +++ b/firmware/include/ccspi.h @@ -20,6 +20,8 @@ #define CCSPI_RX_FLUSH 0x82 //Flush TX #define CCSPI_TX_FLUSH 0x83 +//Reflexive jam. +#define CCSPI_REFLEX 0xA0 //Bit fields for command word. diff --git a/firmware/platforms/telosb.h b/firmware/platforms/telosb.h index 98b94bc..e69faa7 100644 --- a/firmware/platforms/telosb.h +++ b/firmware/platforms/telosb.h @@ -65,6 +65,9 @@ #define CLRCE P4OUT&=~BIT6 #define DIRCE P4DIR|=BIT6 +//CC2420 signals +#define SFD (P4IN&BIT1) +#define FIFOP (P4IN&BIT0) // network byte order converters #define htons(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \ -- 2.20.1