]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
RF230: timesync changes to lower memory usage
authormmaroti <mmaroti>
Thu, 5 Jun 2008 20:44:21 +0000 (20:44 +0000)
committermmaroti <mmaroti>
Thu, 5 Jun 2008 20:44:21 +0000 (20:44 +0000)
tos/chips/rf230/RF230LayerP.nc
tos/chips/rf230/RF230Packet.h
tos/chips/rf230/RF230PacketP.nc
tos/chips/rf230/TimeSyncMessage.h
tos/chips/rf230/TimeSyncMessageP.nc

index 85058a77ae29271d2bf52797a55947a62ab0623c..a6acb2b34ab2a77d90a33f066f50a207ce49bc99 100644 (file)
@@ -25,6 +25,7 @@
 #include <HplRF230.h>
 #include <Tasklet.h>
 #include <RadioAssert.h>
+#include <TimeSyncMessage.h>
 
 module RF230LayerP
 {
@@ -392,17 +393,11 @@ implementation
                uint8_t* data;
                uint8_t header;
                uint32_t time32;
+               void* timesync;
 
                if( cmd != CMD_NONE || state != STATE_RX_ON || ! isSpiAcquired() || radioIrq )
                        return EBUSY;
 
-               if( call RF230Config.requiresRssiCca(msg) 
-                               && (readRegister(RF230_PHY_RSSI) & RF230_RSSI_MASK) > ((rssiClear + rssiBusy) >> 3) )
-                       return EBUSY;
-
-               writeRegister(RF230_TRX_STATE, RF230_PLL_ON);
-
-               // do something useful, just to wait a little
                length = (call PacketTransmitPower.isSet(msg) ?
                        call PacketTransmitPower.get(msg) : RF230_DEF_RFPOWER) & RF230_TX_PWR_MASK;
 
@@ -412,7 +407,15 @@ implementation
                        writeRegister(RF230_PHY_TX_PWR, RF230_TX_AUTO_CRC_ON | txPower);
                }
 
+               if( call RF230Config.requiresRssiCca(msg) 
+                               && (readRegister(RF230_PHY_RSSI) & RF230_RSSI_MASK) > ((rssiClear + rssiBusy) >> 3) )
+                       return EBUSY;
+
+               writeRegister(RF230_TRX_STATE, RF230_PLL_ON);
+
+               // do something useful, just to wait a little
                time32 = call LocalTime.get();
+               timesync = call PacketTimeSyncOffset.isSet(msg) ? msg->data + call PacketTimeSyncOffset.get(msg) : 0;
 
                // we have missed an incoming message in this short amount of time
                if( (readRegister(RF230_TRX_STATUS) & RF230_TRX_STATUS_MASK) != RF230_PLL_ON )
@@ -458,8 +461,8 @@ implementation
 
                time32 += (int16_t)(time) - (int16_t)(time32);
 
-               if( call PacketTimeSyncOffset.isSet(msg) )
-                       ((timesync_footer_t*)(msg->data + call PacketTimeSyncOffset.get(msg)))->time_offset += time32;
+               if( timesync != 0 )
+                       *(timesync_relative_t*)timesync = (*(timesync_absolute_t*)timesync) - time32;
 
                do {
                        call HplRF230.spiSplitReadWrite(*(data++));
@@ -498,8 +501,8 @@ implementation
                }
 #endif
 
-               if( call PacketTimeSyncOffset.isSet(msg) )
-                       ((timesync_footer_t*)(msg->data + call PacketTimeSyncOffset.get(msg)))->time_offset -= time32;
+               if( timesync != 0 )
+                       *(timesync_absolute_t*)timesync = (*(timesync_relative_t*)timesync) + time32;
 
                call PacketTimeStamp.set(msg, time32);
 
index ab020b5e4993ad0abe5b47b921495f9d3f9c9f9e..7d952fe13c55941ad5af9ea602727621c207f408 100644 (file)
 #define __RF230PACKET_H__
 
 #include <IEEE154Packet.h>
-#include <TimeSyncMessage.h>
 
 typedef ieee154_header_t rf230packet_header_t;
 
 typedef nx_struct rf230packet_footer_t
 {
-       timesync_footer_t timesync;
+       // the time stamp is not recorded here, time stamped messaged cannot have max length
 } rf230packet_footer_t;
 
 typedef struct rf230packet_metadata_t
index 6bfb2c2d903cde59f684b3ddad7ee526c6f618b6..d2f2c150af9d5580b2e3f9e4ad975bd22c91f388 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include <RF230Packet.h>
+#include <TimeSyncMessage.h>
 
 module RF230PacketP
 {
@@ -250,7 +251,7 @@ implementation
 
        async command uint8_t PacketTimeSyncOffset.get(message_t* msg)
        {
-               return call IEEE154Packet.getLength(msg) - PACKET_LENGTH_INCREASE - sizeof(timesync_footer_t);
+               return call IEEE154Packet.getLength(msg) - PACKET_LENGTH_INCREASE - sizeof(timesync_absolute_t);
        }
 
        async command void PacketTimeSyncOffset.clear(message_t* msg)
index 2ef2fb024bc2bebf7213e2905de678f00f71ec75..38fba022cf691955c64570099d3af09a554d0bd8 100644 (file)
 #ifndef __TIMESYNCMESSAGE_H__
 #define __TIMESYNCMESSAGE_H__
 
-typedef nx_struct timesync_footer_t
-{
-       nx_int32_t time_offset; // in micorsec
-} timesync_footer_t;
+// this value is sent in the air
+typedef nx_int32_t timesync_relative_t;
+
+// this value is stored in memory
+typedef uint32_t timesync_absolute_t;
 
 #endif//__TIMESYNCMESSAGE_H__
index a80906a6d2d125b1a7d2dbb66179381a3dbeb8c6..a586b23a19d103a0bce9dbe16fc2e30caa04e6c4 100644 (file)
@@ -54,10 +54,10 @@ module TimeSyncMessageP
 implementation
 {
        // TODO: change the Packet.payloadLength and Packet.maxPayloadLength commands to async
-       inline timesync_footer_t* getFooter(message_t* msg)
+       inline void* getFooter(message_t* msg)
        {
-               // we use the payload length we export (the smaller one)
-               return (timesync_footer_t*)(msg->data + call Packet.payloadLength(msg));
+               // we use the payload length that we export (the smaller one)
+               return msg->data + call Packet.payloadLength(msg);
        }
 
 /*----------------- Packet -----------------*/
@@ -69,34 +69,33 @@ implementation
 
        command void Packet.setPayloadLength(message_t* msg, uint8_t len) 
        {
-               call SubPacket.setPayloadLength(msg, len + sizeof(timesync_footer_t));
+               call SubPacket.setPayloadLength(msg, len + sizeof(timesync_relative_t));
        }
 
        command uint8_t Packet.payloadLength(message_t* msg) 
        {
-               return call SubPacket.payloadLength(msg) - sizeof(timesync_footer_t);
+               return call SubPacket.payloadLength(msg) - sizeof(timesync_relative_t);
        }
 
        command uint8_t Packet.maxPayloadLength()
        {
-               return call SubPacket.maxPayloadLength() - sizeof(timesync_footer_t);
+               return call SubPacket.maxPayloadLength() - sizeof(timesync_relative_t);
        }
 
        command void* Packet.getPayload(message_t* msg, uint8_t len)
        {
-               return call SubPacket.getPayload(msg, len + sizeof(timesync_footer_t));
+               return call SubPacket.getPayload(msg, len + sizeof(timesync_relative_t));
        }
 
 /*----------------- TimeSyncAMSendRadio -----------------*/
 
        command error_t TimeSyncAMSendRadio.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len, uint32_t event_time)
        {
-               timesync_footer_t* footer = (timesync_footer_t*)(msg->data + len);
-               footer->time_offset = (nx_int32_t)event_time;
+               *(timesync_absolute_t*)(msg->data + len) = event_time;
 
                call PacketTimeSyncOffset.set(msg, len);
 
-               return call SubSend.send[id](addr, msg, len + sizeof(timesync_footer_t));
+               return call SubSend.send[id](addr, msg, len + sizeof(timesync_relative_t));
        }
 
        command error_t TimeSyncAMSendRadio.cancel[am_id_t id](message_t* msg)
@@ -110,12 +109,12 @@ implementation
 
        command uint8_t TimeSyncAMSendRadio.maxPayloadLength[am_id_t id]()
        {
-               return call SubSend.maxPayloadLength[id]() - sizeof(timesync_footer_t);
+               return call SubSend.maxPayloadLength[id]() - sizeof(timesync_relative_t);
        }
 
        command void* TimeSyncAMSendRadio.getPayload[am_id_t id](message_t* msg, uint8_t len)
        {
-               return call SubSend.getPayload[id](msg, len + sizeof(timesync_footer_t));
+               return call SubSend.getPayload[id](msg, len + sizeof(timesync_relative_t));
        }
 
 /*----------------- TimeSyncAMSendMilli -----------------*/
@@ -159,31 +158,31 @@ implementation
 
        async command bool TimeSyncPacketRadio.isValid(message_t* msg)
        {
-               timesync_footer_t* footer = getFooter(msg);
+               timesync_relative_t* timesync = getFooter(msg);
 
-               return call PacketTimeStampRadio.isValid(msg) && footer->time_offset != 0x80000000L;
+               return call PacketTimeStampRadio.isValid(msg) && *timesync != 0x80000000L;
        }
 
        async command uint32_t TimeSyncPacketRadio.eventTime(message_t* msg)
        {
-               timesync_footer_t* footer = getFooter(msg);
+               timesync_relative_t* timesync = getFooter(msg);
 
-               return (int32_t)(footer->time_offset) + call PacketTimeStampRadio.timestamp(msg);
+               return (*timesync) + call PacketTimeStampRadio.timestamp(msg);
        }
 
        /*----------------- TimeSyncPacketMilli -----------------*/
 
        async command bool TimeSyncPacketMilli.isValid(message_t* msg)
        {
-               timesync_footer_t* footer = getFooter(msg);
+               timesync_relative_t* timesync = getFooter(msg);
 
-               return call PacketTimeStampMilli.isValid(msg) && footer->time_offset != 0x80000000L;
+               return call PacketTimeStampMilli.isValid(msg) && *timesync != 0x80000000L;
        }
 
        async command uint32_t TimeSyncPacketMilli.eventTime(message_t* msg)
        {
-               timesync_footer_t* footer = getFooter(msg);
+               timesync_relative_t* timesync = getFooter(msg);
 
-               return ((int32_t)(footer->time_offset) << 10) + call PacketTimeStampMilli.timestamp(msg);
+               return ((int32_t)(*timesync) << 10) + call PacketTimeStampMilli.timestamp(msg);
        }
 }