[Tinyos-devel] Testing FTSP
Miklos Maroti
mmaroti at math.u-szeged.hu
Thu Aug 14 14:17:40 PDT 2008
>>
>> uint32_t m_timestamp;
>> uint8_t m_timestamp_count;
>>
>> async command void CC2420Receive.sfd( uint32_t time ) {
>> if( ++m_timestamp_count == 1 )
>> m_timestamp = time;
>> else if( m_timestamp_count == 2 )
>> m_timestamp_count = 3;
>> }
>>
>> async command void CC2420Receive.sfd_dropped() {
>> if ( m_timestamp_count > 3 )
>> --m_timestamp_count;
>> else
>> m_timestamp_count = 0;
>> }
>>
>> async event void RXFIFO.readDone ...
>> if ( m_timestamp_count == 1 && rxFrameLength > 10 )
>> call PacketTimeStamp.set(m_p_rx_buf, m_timestamp);
>> else
>> call PacketTimeStamp.clear(m_p_rx_buf);
>>
>> if ( m_timestamp_count > 3 )
>> --m_timestamp_count;
>> else
>> m_timestamp_count = 0;
>>
>> void reset_state() {
>> m_bytes_left = RXFIFO_SIZE;
>> atomic receivingPacket = FALSE;
>> m_timestamp_count = 0;
>> m_missed_packets = 0;
>> }
>
> i don't quite understand this...
count 0 = no message
count 1 = we switched from 0 to 1 message
count 2 = we switched from 2 to 1 message
count 3 = we have 2 messages in the queue
count 4 = we have 3 messages in the queue
etc.
>> inline uint32_t time16to32(uint16_t time, uint32_t recent_time)
>> {
>> return recent_time + ((int16_t)time - (int16_t)receint_time);
>> }
>
> this will not work, for example for recent_time=0x18001 and time=0x7FFF, perhaps, you meant to say
> return recent_time + (int16_t)(time - recent_time);
These two are the same by the C conversion rules. Probably yours is
more readable, but there first the time is converted to 32 bits then
the 32-bit subtraction occurs then the result is converted to 16 bit
signed value which is extended to 32bit signed back (ignoring the high
2 bytes) and added to the 32-bit signed value. Mine does a 16-bit
subtration, but I guess GCC optimizes both to the same OP codes.
By the way, with your numbers:
receint_time = 0x18001 uint32_t
time = 0x7FFF uint16_t
(int16_t)receint_time = 0x8001 int16_t
(int16_t)time = 0x7FFF int16_t
(int16_t)time - (int16_t)receint_time = 0xFFFE int16_t
before the + the (int16_t)time - (int16_t)receint_time is converted to
0xFFFFFFFE int32_t
recent_time + ((int16_t)time - (int16_t)receint_time) = 0x00017FFF int32_t
which is converted to uint32_t
> so why the 2^16 errors then? do you suspect that LocalTime implementation has a race condition somewhere?
Maybe there is, I do not know. Try to do the 16to32 bit conversion
multiple times one after the other immediately, and compare the two
results. The should be always equal.
Miklos
More information about the Tinyos-devel
mailing list