[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/vu/tos/platform/mica2
ClockTimeStampingM.nc, 1.2, 1.3 SysTimeStampingM.nc, 1.7, 1.8
Brano Kusy
kusyb at users.sourceforge.net
Tue Jul 4 06:55:28 PDT 2006
Update of /cvsroot/tinyos/tinyos-1.x/contrib/vu/tos/platform/mica2
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv13029
Modified Files:
ClockTimeStampingM.nc SysTimeStampingM.nc
Log Message:
Index: ClockTimeStampingM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/vu/tos/platform/mica2/ClockTimeStampingM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ClockTimeStampingM.nc 17 Jun 2005 15:15:00 -0000 1.2
--- ClockTimeStampingM.nc 4 Jul 2006 13:55:26 -0000 1.3
***************
*** 62,68 ****
norace uint32_t receiveTime;
! command uint32_t TimeStamping.getStamp()
{
! return receiveTime;
}
--- 62,76 ----
norace uint32_t receiveTime;
! command uint32_t TimeStamping.getStamp2()
{
! uint32_t time = 0;
!
! atomic
! {
! if( receiveMsg == msg )
! time = receiveTime;
! }
!
! return time;
}
***************
*** 91,94 ****
--- 99,103 ----
#endif
receiveTime = stamp;
+ receiveMsg = msg;
}
***************
*** 106,112 ****
#endif
! norace TOS_MsgPtr ptosMsg;
!
! command result_t TimeStamping.addStamp(int8_t offset)
{
// if correct value (negative value turns it off)
--- 115,123 ----
#endif
! TOS_MsgPtr sendMsg = 0;
! TOS_MsgPtr receiveMsg = 0;
!
!
! command result_t TimeStamping.addStamp2(TOS_MsgPtr msg, int8_t offset)
{
// if correct value (negative value turns it off)
***************
*** 114,118 ****
{
sendStampOffset = offset;
! ptosMsg = 0;
return SUCCESS;
}
--- 125,129 ----
{
sendStampOffset = offset;
! sendMsg = msg;
return SUCCESS;
}
***************
*** 124,148 ****
}
- command result_t TimeStamping.addStamp2(TOS_MsgPtr msg, int8_t offset)
- {
- // if correct value (negative value turns it off)
- if( 0 <= offset && offset <= MAX_OFFSET )
- {
- sendStampOffset = offset;
- ptosMsg = msg;
- return SUCCESS;
- }
- else
- {
- sendStampOffset = -1;
- return FAIL;
- }
- }
-
async event void RadioSendCoordinator.startSymbol(uint8_t bitsPerBlock, uint8_t offset, TOS_MsgPtr msgBuff)
{
! if (ptosMsg != 0 && ptosMsg != msgBuff)
! return;
!
if( sendStampOffset >= 0 )
{
--- 135,143 ----
}
async event void RadioSendCoordinator.startSymbol(uint8_t bitsPerBlock, uint8_t offset, TOS_MsgPtr msgBuff)
{
! if (sendMsg != 0 && sendMsg != msgBuff)
! return;
!
if( sendStampOffset >= 0 )
{
Index: SysTimeStampingM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/vu/tos/platform/mica2/SysTimeStampingM.nc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** SysTimeStampingM.nc 4 Dec 2005 07:44:58 -0000 1.7
--- SysTimeStampingM.nc 4 Jul 2006 13:55:26 -0000 1.8
***************
*** 1,217 ****
! /*
! * Copyright (c) 2002, Vanderbilt University
! * All rights reserved.
! *
! * Permission to use, copy, modify, and distribute this software and its
! * documentation for any purpose, without fee, and without written agreement is
! * hereby granted, provided that the above copyright notice, the following
! * two paragraphs and the author appear in all copies of this software.
! *
! * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
! * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
! * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
! * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! *
! * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
! * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
! * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
! * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
! * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
! *
! * Author: Miklos Maroti
! * Date last modified: 12/11/03
! */
!
! #include "AM.h"
!
! module SysTimeStampingM
! {
! provides
! {
! interface TimeStamping;
! #ifdef TIMESTAMPING_CALIBRATE
! command uint8_t getBitOffset();
! #endif
! }
! uses
! {
! interface RadioCoordinator as RadioSendCoordinator;
! interface RadioCoordinator as RadioReceiveCoordinator;
! interface SysTime;
! }
! }
!
! implementation
! {
! #if defined(PLATFORM_MICA2)
! /* These are the calibrated bit offsets on the MICA2 for 38.4 Kbps transmit
! * rate, Manchester Encoding, using the systime with 921.6 KHz frequency.
! * The actual values have been multiplied by two because we substract
! * them before dividing by two. There is a noticable +-0.5 microsec bias
! * for the bits 5 and 6 for unknown reasons, which is corrected here.
! */
! // static const int16_t BIT_CORRECTION[8] = { 1289, 1337, 1385, 1433, 1481, 1529, 1577, 1625 };
! // enum { BYTE_TIME = 192 };
!
! /* if your radio stack runs 19.2 kbps, use the following settings: */
! static const int16_t BIT_CORRECTION[8] = { 2555, 2651, 2747, 2843, 2939, 3036, 3130, 3227 };
! enum { BYTE_TIME = 384 };
! #elif defined(PLATFORM_XSM)
! static const int16_t BIT_CORRECTION[8] = { 2553, 2649, 2745, 2841, 2935, 3033, 3127, 3225 };
! enum { BYTE_TIME = 384 };
! #elif defined(PLATFORM_MICA2DOT)
! /* These are the calibrated bit offsets on the MICA2DOR for 19.2 Kbps
! * transmit rate, Manchester Encoding, using the systime with 500 KHz
! * frequency.
! */
! static const int16_t BIT_CORRECTION[8] = { 1388, 1442, 1492, 1545, 1598, 1651, 1702, 1754 };
! enum { BYTE_TIME = 209 };
! #endif
!
! norace uint16_t interruptTime;
! norace TOS_MsgPtr ptosMsg = 0;
!
! async event void RadioSendCoordinator.blockTimer()
! {
! interruptTime = call SysTime.getTime16();
! }
!
! // both of these are called, so we just ignore the second
! async event void RadioReceiveCoordinator.blockTimer() { }
!
! // the time stamp of the last received message
! norace uint32_t receiveTime;
!
! command uint32_t TimeStamping.getStamp()
! {
! return receiveTime;
! }
!
! norace uint8_t bitOffset;
!
! #ifdef TIMESTAMPING_CALIBRATE
! command uint8_t getBitOffset()
! {
! return bitOffset;
! }
! #endif
!
! async event void RadioReceiveCoordinator.startSymbol(uint8_t bitsPerBlock, uint8_t offset, TOS_MsgPtr msgBuff)
! {
! bitOffset = offset;
! }
!
! norace int16_t avgCorrection;
! norace uint16_t referenceTime;
!
! async event void RadioReceiveCoordinator.byte(TOS_MsgPtr msg, uint8_t byteCount)
! {
! uint16_t time = interruptTime;
!
! if( byteCount == 0 )
! {
! receiveTime = call SysTime.castTime16(time);
! referenceTime = time;
! }
! else if( byteCount == 3 )
! {
! avgCorrection = referenceTime - (uint16_t)receiveTime;
! referenceTime = time;
! }
! else if( byteCount < 6 )
! {
! referenceTime += BYTE_TIME;
! if( (int16_t)(time - referenceTime) < 0 )
! referenceTime = time;
!
! if( byteCount == 5 )
! {
! avgCorrection += referenceTime - (uint16_t)receiveTime;
! #ifndef TIMESTAMPING_CALIBRATE
! avgCorrection -= BIT_CORRECTION[bitOffset];
! #endif
! receiveTime += (avgCorrection >> 1);
! }
! }
! }
!
! // the offset of the time-stamp field in the message,
! // or -1 if no stamp is necessariy.
! norace int8_t sendStampOffset = -1;
!
! command result_t TimeStamping.addStamp(int8_t offset)
! {
! // if correct value (negative value turns it off)
! if( 1 <= offset && offset <= TOSH_DATA_LENGTH-4 )
! {
! sendStampOffset = offset;
! ptosMsg = 0;
! return SUCCESS;
! }
! else
! {
! sendStampOffset = -1;
! return FAIL;
! }
! }
!
! command result_t TimeStamping.addStamp2(TOS_MsgPtr msg, int8_t offset)
! {
! // if correct value (negative value turns it off)
! if( 1 <= offset && offset <= TOSH_DATA_LENGTH-4 )
! {
! sendStampOffset = offset;
! ptosMsg = msg;
! return SUCCESS;
! }
! else
! {
! sendStampOffset = -1;
! return FAIL;
! }
! }
!
!
! norace uint32_t sendTime;
!
! async event void RadioSendCoordinator.startSymbol(uint8_t bitsPerBlock, uint8_t offset, TOS_MsgPtr msgBuff) { }
!
! async event void RadioSendCoordinator.byte(TOS_MsgPtr msg, uint8_t byteCount)
! {
! uint16_t time;
!
! if (ptosMsg != 0 && ptosMsg != msg)
! return;
!
! if( sendStampOffset < 0 )
! return;
!
! time = interruptTime;
!
! if( byteCount == 0 )
! {
! sendTime = call SysTime.castTime16(time);
! referenceTime = time;
! }
! else if( byteCount == 3 )
! {
! avgCorrection = referenceTime - (uint16_t)sendTime;
! referenceTime = time;
! }
! else if( byteCount < 6 )
! {
! referenceTime += BYTE_TIME;
! if( (int16_t)(time - referenceTime) < 0 )
! referenceTime = time;
!
! if( byteCount == 5 )
! {
! avgCorrection += referenceTime - (uint16_t)sendTime;
! sendTime += (avgCorrection >> 1);
!
! *(uint32_t*)((int8_t*)msg->data + sendStampOffset) += sendTime;
! sendStampOffset = -1;
! }
! }
! }
! }
--- 1,211 ----
! /*
! * Copyright (c) 2002, Vanderbilt University
! * All rights reserved.
! *
! * Permission to use, copy, modify, and distribute this software and its
! * documentation for any purpose, without fee, and without written agreement is
! * hereby granted, provided that the above copyright notice, the following
! * two paragraphs and the author appear in all copies of this software.
! *
! * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
! * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
! * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
! * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! *
! * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
! * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
! * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
! * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
! * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
! *
! * Author: Miklos Maroti
! * Date last modified: 12/11/03
! */
!
! #include "AM.h"
!
! module SysTimeStampingM
! {
! provides
! {
! interface TimeStamping;
! #ifdef TIMESTAMPING_CALIBRATE
! command uint8_t getBitOffset();
! #endif
! }
! uses
! {
! interface RadioCoordinator as RadioSendCoordinator;
! interface RadioCoordinator as RadioReceiveCoordinator;
! interface SysTime;
! }
! }
!
! implementation
! {
! #if defined(PLATFORM_MICA2)
! /* These are the calibrated bit offsets on the MICA2 for 38.4 Kbps transmit
! * rate, Manchester Encoding, using the systime with 921.6 KHz frequency.
! * The actual values have been multiplied by two because we substract
! * them before dividing by two. There is a noticable +-0.5 microsec bias
! * for the bits 5 and 6 for unknown reasons, which is corrected here.
! */
! // static const int16_t BIT_CORRECTION[8] = { 1289, 1337, 1385, 1433, 1481, 1529, 1577, 1625 };
! // enum { BYTE_TIME = 192 };
!
! /* if your radio stack runs 19.2 kbps, use the following settings: */
! static const int16_t BIT_CORRECTION[8] = { 2555, 2651, 2747, 2843, 2939, 3036, 3130, 3227 };
! enum { BYTE_TIME = 384 };
! #elif defined(PLATFORM_XSM)
! static const int16_t BIT_CORRECTION[8] = { 2553, 2649, 2745, 2841, 2935, 3033, 3127, 3225 };
! enum { BYTE_TIME = 384 };
! #elif defined(PLATFORM_MICA2DOT)
! /* These are the calibrated bit offsets on the MICA2DOR for 19.2 Kbps
! * transmit rate, Manchester Encoding, using the systime with 500 KHz
! * frequency.
! */
! static const int16_t BIT_CORRECTION[8] = { 1388, 1442, 1492, 1545, 1598, 1651, 1702, 1754 };
! enum { BYTE_TIME = 209 };
! #endif
!
! int8_t sendStampOffset = -1;
! TOS_MsgPtr sendMsg = 0;
! TOS_MsgPtr receiveMsg = 0;
!
! norace uint16_t interruptTime;
!
! // the offset of the time-stamp field in the message,
! // or -1 if no stamp is necessariy.
! command result_t TimeStamping.addStamp2(TOS_MsgPtr msg, int8_t offset)
! {
! uint8_t ret = FAIL;
!
! if( 0 <= offset && offset <= TOSH_DATA_LENGTH - 4 )
! {
! atomic
! {
! sendStampOffset = offset;
! sendMsg = msg;
! ret = SUCCESS;
! }
! }
! return ret;
! }
!
! async event void RadioSendCoordinator.blockTimer()
! {
! interruptTime = call SysTime.getTime16();
! }
!
! norace uint32_t sendTime;
! norace uint16_t referenceTime;
! norace int16_t avgCorrection;
!
! async event void RadioSendCoordinator.startSymbol(uint8_t bitsPerBlock, uint8_t offset, TOS_MsgPtr msgBuff) { }
!
! async event void RadioSendCoordinator.byte(TOS_MsgPtr msg, uint8_t byteCount)
! {
! uint16_t time;
!
! if (sendMsg != 0 && sendMsg != msg)
! return;
!
! if( sendStampOffset < 0 )
! return;
!
! time = interruptTime;
!
! if( byteCount == 0 )
! {
! sendTime = call SysTime.castTime16(time);
! referenceTime = time;
! }
! else if( byteCount == 3 )
! {
! avgCorrection = referenceTime - (uint16_t)sendTime;
! referenceTime = time;
! }
! else if( byteCount < 6 )
! {
! referenceTime += BYTE_TIME;
! if( (int16_t)(time - referenceTime) < 0 )
! referenceTime = time;
!
! if( byteCount == 5 )
! {
! avgCorrection += referenceTime - (uint16_t)sendTime;
! sendTime += (avgCorrection >> 1);
!
! *(uint32_t*)((int8_t*)msg->data + sendStampOffset) += sendTime;
! sendStampOffset = -1;
! }
! }
! }
!
!
! // both of these are called, so we just ignore the second
! async event void RadioReceiveCoordinator.blockTimer() { }
!
! // the time stamp of the last received message
! norace uint32_t receiveTime;
! norace uint8_t bitOffset;
!
! #ifdef TIMESTAMPING_CALIBRATE
! command uint8_t getBitOffset()
! {
! return bitOffset;
! }
! #endif
!
! async event void RadioReceiveCoordinator.startSymbol(uint8_t bitsPerBlock, uint8_t offset, TOS_MsgPtr msgBuff)
! {
! bitOffset = offset;
! }
!
! async event void RadioReceiveCoordinator.byte(TOS_MsgPtr msg, uint8_t byteCount)
! {
! uint16_t time = interruptTime;
!
! if( byteCount == 0 )
! {
! receiveTime = call SysTime.castTime16(time);
! referenceTime = time;
! }
! else if( byteCount == 3 )
! {
! avgCorrection = referenceTime - (uint16_t)receiveTime;
! referenceTime = time;
! }
! else if( byteCount < 6 )
! {
! referenceTime += BYTE_TIME;
! if( (int16_t)(time - referenceTime) < 0 )
! referenceTime = time;
!
! if( byteCount == 5 )
! {
! avgCorrection += referenceTime - (uint16_t)receiveTime;
! #ifndef TIMESTAMPING_CALIBRATE
! avgCorrection -= BIT_CORRECTION[bitOffset];
! #endif
! receiveTime += (avgCorrection >> 1);
! receiveMsg = msg;
! }
! }
! }
!
! command uint32_t TimeStamping.getStamp2(TOS_MsgPtr msg)
! {
! uint32_t time = 0;
!
! atomic
! {
! if( receiveMsg == msg )
! time = receiveTime;
! }
!
! return time;
! }
!
!
! }
More information about the Tinyos-contrib-commits
mailing list