Hi,
We have been running into a weird bug with the Telos motes, using
msp-gcc 3.2.3 .
We are using for a node election protocol the random generator of
tinyOS, RandomMlcg. (We also tried RandomLfsr, the problem remains).
The motes will crash (hang) after the second call to random. In our
code, we call 32-operations at two different places (random and
distance calculation). We tried several work-arounds and here are the
symptoms:
- Running the code on Micaz, the mote does not crash and the protocol
works fine.
- As well, the protocol runs fine on TOSSIM.
- If we comment out the call to the random generator, or the other
32-bits multiplication (distance computation, see below), the mote
does not crash.
- If we replace the sèpeudo random generator code with a simple one (e.g.
return seed++), the mote does not crash.
- In other pieces of code we have, using the random generator will
lead, as far as we observed, to no crash. So the crash is apparently
specific to the code we have.
And to add some mystery:
- Using the HW multiplier of the Telosb (by changing the compiler
flags), the code runs perfectly fine.
Although, we do not like this solution, as it is said that mspgcc can
generate buggy binary with the HW multiplier. (and therefore is
disabled by default in the tinyOS toolchain)
We believe, that under certain conditions, the code generation for
the multiplication is buggy. Although, the call to the random
generator, and the call to the distance calculation are sequential, so
we do not understand yet why they conflict.
Here are a snippet of the two methods involving 32 bits operations
(See RandomMlcg in tos/system)
void calculateRefCoords(uint16_t p_epochNum, location_t* p_refCoord)
{
atomic
{
call SeedInit.init(p_epochNum);
p_refCoord->x = (call
ReferencePointGenerator.rand16() % (AREA_SIZE / PARTS_NUM));
p_refCoord->y = (call
ReferencePointGenerator.rand16() % (AREA_SIZE / PARTS_NUM));
}
}
distance calculation:
uint32_t Distance(location_t p_locA, location_t p_locB)
{
uint32_t xDiff = p_locA.x < p_locB.x ? p_locB.x -
p_locA.x : p_locA.x - p_locB.x;
uint32_t yDiff = p_locA.y < p_locB.y ? p_locB.y -
p_locA.y : p_locA.y - p_locB.y;
return yDiff * yDiff + xDiff * xDiff;
}
The two methods are called, as said before sequentially. location_t is
a struct with two uint16_t elements. As stated previously, if we
invoke only one of the two methods, the mote will not crash.. I
haven't been looking in the assembly code yet.
Has anyone experienced something like that?
Thank you in advance for the help,
Alban
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help