]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/cc2420/receive/CC2420ReceiveP.nc
Add a comment about the polarity of FIFOP.
[tinyos-2.x.git] / tos / chips / cc2420 / receive / CC2420ReceiveP.nc
index f7ca6baf9d572d8f0005d9b5eded6f58732045eb..b50ad035a36a93e54086eb8bdaee2f68e1489988 100644 (file)
@@ -40,7 +40,7 @@
 #include "message.h"
 #include "AM.h"
 
-module CC2420ReceiveP {
+module CC2420ReceiveP @safe() {
 
   provides interface Init;
   provides interface StdControl;
@@ -60,7 +60,8 @@ module CC2420ReceiveP {
   uses interface CC2420Packet;
   uses interface CC2420PacketBody;
   uses interface CC2420Config;
-  
+  uses interface PacketTimeStamp<T32khz,uint32_t>;
+
   uses interface Leds;
 }
 
@@ -80,8 +81,8 @@ implementation {
     SACK_HEADER_LENGTH = 7,
   };
 
-  uint16_t m_timestamp_queue[ TIMESTAMP_QUEUE_SIZE ];
-  
+  uint32_t m_timestamp_queue[ TIMESTAMP_QUEUE_SIZE ];
+
   uint8_t m_timestamp_head;
   
   uint8_t m_timestamp_size;
@@ -109,7 +110,7 @@ implementation {
   void receive();
   void waitForNextPacket();
   void flush();
-  bool passesAddressCheck(message_t *msg);
+  bool passesAddressCheck(message_t * ONE msg);
   
   task void receiveDone_task();
   
@@ -125,6 +126,10 @@ implementation {
       reset_state();
       m_state = S_STARTED;
       atomic receivingPacket = FALSE;
+      /* Note:
+         We use the falling edge because the FIFOP polarity is reversed. 
+         This is done in CC2420Power.startOscillator from CC2420ControlP.nc.
+       */
       call InterruptFIFOP.enableFallingEdge();
     }
     return SUCCESS;
@@ -145,7 +150,7 @@ implementation {
    * Start frame delimiter signifies the beginning/end of a packet
    * See the CC2420 datasheet for details.
    */
-  async command void CC2420Receive.sfd( uint16_t time ) {
+  async command void CC2420Receive.sfd( uint32_t time ) {
     if ( m_timestamp_size < TIMESTAMP_QUEUE_SIZE ) {
       uint8_t tail =  ( ( m_timestamp_head + m_timestamp_size ) % 
                         TIMESTAMP_QUEUE_SIZE );
@@ -194,8 +199,7 @@ implementation {
   async event void RXFIFO.readDone( uint8_t* rx_buf, uint8_t rx_len,
                                     error_t error ) {
     cc2420_header_t* header = call CC2420PacketBody.getHeader( m_p_rx_buf );
-    cc2420_metadata_t* metadata = call CC2420PacketBody.getMetadata( m_p_rx_buf );
-    uint8_t tmpLen = sizeof(message_t) - (offsetof(message_t, data) - sizeof(cc2420_header_t));
+    uint8_t tmpLen __DEPUTY_UNUSED__ = sizeof(message_t) - (offsetof(message_t, data) - sizeof(cc2420_header_t));
     uint8_t* COUNT(tmpLen) buf = TCAST(uint8_t* COUNT(tmpLen), header);
     rxFrameLength = buf[ 0 ];
 
@@ -283,12 +287,12 @@ implementation {
       
       if ( m_timestamp_size ) {
         if ( rxFrameLength > 10 ) {
-          metadata->time = m_timestamp_queue[ m_timestamp_head ];
+          call PacketTimeStamp.set(m_p_rx_buf, m_timestamp_queue[ m_timestamp_head ]);
           m_timestamp_head = ( m_timestamp_head + 1 ) % TIMESTAMP_QUEUE_SIZE;
           m_timestamp_size--;
         }
       } else {
-        metadata->time = 0xffff;
+        call PacketTimeStamp.clear(m_p_rx_buf);
       }
       
       // We may have received an ack that should be processed by Transmit
@@ -326,16 +330,17 @@ implementation {
   task void receiveDone_task() {
     cc2420_metadata_t* metadata = call CC2420PacketBody.getMetadata( m_p_rx_buf );
     cc2420_header_t* header = call CC2420PacketBody.getHeader( m_p_rx_buf);
-    uint8_t tmpLen = sizeof(message_t) - (offsetof(message_t, data) - sizeof(cc2420_header_t));
+    uint8_t length = header->length;
+    uint8_t tmpLen __DEPUTY_UNUSED__ = sizeof(message_t) - (offsetof(message_t, data) - sizeof(cc2420_header_t));
     uint8_t* COUNT(tmpLen) buf = TCAST(uint8_t* COUNT(tmpLen), header);
     
-    metadata->crc = buf[ rxFrameLength ] >> 7;
-    metadata->lqi = buf[ rxFrameLength ] & 0x7f;
-    metadata->rssi = buf[ rxFrameLength - 1 ];
+    metadata->crc = buf[ length ] >> 7;
+    metadata->lqi = buf[ length ] & 0x7f;
+    metadata->rssi = buf[ length - 1 ];
     
-    if(passesAddressCheck(m_p_rx_buf)) {
+    if (passesAddressCheck(m_p_rx_buf) && length >= CC2420_SIZE) {
       m_p_rx_buf = signal Receive.receive( m_p_rx_buf, m_p_rx_buf->data, 
-          rxFrameLength );
+                                          length - CC2420_SIZE);
     }
     
     atomic receivingPacket = FALSE;