]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/rf2xx/rf212/RF212DriverLayerP.nc
fix the max packet length assert
[tinyos-2.x.git] / tos / chips / rf2xx / rf212 / RF212DriverLayerP.nc
index 616292dfd2920433839be253df1d9d23bb812298..43cf19cb078ad62aa2d40238845be7664dba197e 100644 (file)
@@ -24,7 +24,7 @@
 #include <RF212DriverLayer.h>
 #include <Tasklet.h>
 #include <RadioAssert.h>
-#include <GenericTimeSyncMessage.h>
+#include <TimeSyncMessageLayer.h>
 #include <RadioConfig.h>
 
 module RF212DriverLayerP
@@ -457,7 +457,7 @@ implementation
                atomic
                {
                        call SLP_TR.set();
-                       time = call RadioAlarm.getNow() + TX_SFD_DELAY;
+                       time = call RadioAlarm.getNow();
                }
                call SLP_TR.clr();
 
@@ -487,15 +487,13 @@ implementation
                }
                while( --header != 0 );
 
-               time32 += (int16_t)(time) - (int16_t)(time32);
+               time32 += (int16_t)(time + TX_SFD_DELAY) - (int16_t)(time32);
 
                if( timesync != 0 )
                        *(timesync_relative_t*)timesync = (*(timesync_absolute_t*)timesync) - time32;
 
-               do {
+               while( length-- != 0 )
                        call FastSpiByte.splitReadWrite(*(data++));
-               }
-               while( --length != 0 );
 
                // wait for the SPI transfer to finish
                call FastSpiByte.splitRead();
@@ -516,24 +514,25 @@ implementation
                // go back to RX_ON state when finished
                writeRegister(RF212_TRX_STATE, RF212_RX_ON);
 
+               if( timesync != 0 )
+                       *(timesync_absolute_t*)timesync = (*(timesync_relative_t*)timesync) + time32;
+
+               call PacketTimeStamp.set(msg, time32);
+
 #ifdef RADIO_DEBUG_MESSAGES
                if( call DiagMsg.record() )
                {
                        length = getHeader(msg)->length;
 
-                       call DiagMsg.str("tx");
-                       call DiagMsg.uint16(time);
-                       call DiagMsg.uint8(length);
+                       call DiagMsg.str('t');
+                       call DiagMsg.uint32(call PacketTimeStamp.isValid(rxMsg) ? call PacketTimeStamp.timestamp(rxMsg) : 0);
+                       call DiagMsg.uint16(call RadioAlarm.getNow());
+                       call DiagMsg.int8(length);
                        call DiagMsg.hex8s(getPayload(msg), length - 2);
                        call DiagMsg.send();
                }
 #endif
 
-               if( timesync != 0 )
-                       *(timesync_absolute_t*)timesync = (*(timesync_relative_t*)timesync) + time32;
-
-               call PacketTimeStamp.set(msg, time32);
-
                // wait for the TRX_END interrupt
                state = STATE_BUSY_TX_2_RX_ON;
                cmd = CMD_TRANSMIT;
@@ -569,7 +568,7 @@ implementation
        inline void downloadMessage()
        {
                uint8_t length;
-               uint8_t crc = 0;
+               bool crcValid = FALSE;
 
                call SELN.clr();
                call FastSpiByte.write(RF212_CMD_FRAME_READ);
@@ -588,7 +587,6 @@ implementation
 
                        data = getPayload(rxMsg);
                        getHeader(rxMsg)->length = length;
-                       crc = 0;
 
                        // we do not store the CRC field
                        length -= 2;
@@ -614,7 +612,7 @@ implementation
 
                                call PacketLinkQuality.set(rxMsg, call FastSpiByte.splitReadWrite(0));
                                call FastSpiByte.splitReadWrite(0);     // ED
-                               crc = call FastSpiByte.splitRead() & RF212_RX_CRC_VALID;        // RX_STATUS
+                               crcValid = call FastSpiByte.splitRead() & RF212_RX_CRC_VALID;   // RX_STATUS
                        }
                }
 
@@ -626,12 +624,13 @@ implementation
                {
                        length = getHeader(rxMsg)->length;
 
-                       call DiagMsg.str("rx");
+                       call DiagMsg.str('r');
                        call DiagMsg.uint32(call PacketTimeStamp.isValid(rxMsg) ? call PacketTimeStamp.timestamp(rxMsg) : 0);
                        call DiagMsg.uint16(call RadioAlarm.getNow());
-                       call DiagMsg.uint8(crc != 0);
-                       call DiagMsg.uint8(length);
+                       call DiagMsg.int8(crcValid ? length : -length);
                        call DiagMsg.hex8s(getPayload(rxMsg), length - 2);
+                       call DiagMsg.int8(call PacketRSSI.isSet(rxMsg) ? call PacketRSSI.get(rxMsg) : -1);
+                       call DiagMsg.uint8(call PacketLinkQuality.isSet(rxMsg) ? call PacketLinkQuality.get(rxMsg) : 0);
                        call DiagMsg.send();
                }
 #endif
@@ -639,7 +638,7 @@ implementation
                cmd = CMD_NONE;
 
                // signal only if it has passed the CRC check
-               if( crc != 0 )
+               if( crcValid )
                        rxMsg = signal RadioReceive.receive(rxMsg);
        }
 
@@ -689,6 +688,17 @@ implementation
                        }
 #endif
 
+#ifdef RF212_RSSI_ENERGY
+                       if( irq & RF212_IRQ_TRX_END )
+                       {
+                               if( irq == RF212_IRQ_TRX_END || 
+                                       (irq == (RF212_IRQ_RX_START | RF212_IRQ_TRX_END) && cmd == CMD_NONE) )
+                                       call PacketRSSI.set(rxMsg, readRegister(RF212_PHY_ED_LEVEL));
+                               else
+                                       call PacketRSSI.clear(rxMsg);
+                       }
+#endif
+
                        if( irq & RF212_IRQ_PLL_LOCK )
                        {
                                if( cmd == CMD_TURNON || cmd == CMD_CHANNEL )
@@ -771,12 +781,7 @@ implementation
                                else if( cmd == CMD_RECEIVE )
                                {
                                        ASSERT( state == STATE_RX_ON || state == STATE_PLL_ON_2_RX_ON );
-#ifdef RF212_RSSI_ENERGY
-                                       if( irq == RF212_IRQ_TRX_END )
-                                               call PacketRSSI.set(rxMsg, readRegister(RF212_PHY_ED_LEVEL));
-                                       else
-                                               call PacketRSSI.clear(rxMsg);
-#endif
+
                                        if( state == STATE_PLL_ON_2_RX_ON )
                                        {
                                                ASSERT( (readRegister(RF212_TRX_STATUS) & RF212_TRX_STATUS_MASK) == RF212_PLL_ON );
@@ -861,7 +866,7 @@ implementation
 
        async command uint8_t RadioPacket.maxPayloadLength()
        {
-               ASSERT( call Config.maxPayloadLength() <= 125 );
+               ASSERT( call Config.maxPayloadLength() - sizeof(rf230_header_t) <= 125 );
 
                return call Config.maxPayloadLength() - sizeof(rf212_header_t);
        }
@@ -959,10 +964,6 @@ implementation
 
        async command uint8_t PacketLinkQuality.get(message_t* msg)
        {
-               // we have some bug in BLIP, so fix it here
-               if( getMeta(msg)->lqi > 120 )
-                       return 120;
-
                return getMeta(msg)->lqi;
        }