Re: [Tinyos-help] Component variable value corrupted without inlining a local function

Flavio Pompermaier fla83tn at libero.it
Mon Mar 24 13:03:40 PDT 2008


I must excuse for this post! I spent about half of the day figuring out this absurd behaviour and indeed it was my fault..
In the initialization phase I was assigning to "epochs" the value 0 and the problem was that in one of the local functions   there was an assignment of another variable to the value of "epochs". The problem was that in the start phase if the application was trying to send a message when epochs was 0, in another check the value 0 of the other variable was meaning "uninitialized", so the solution has just been to make epochs start from 1...
Sorry for the confusion, next time I will try to spend more time debugging my application!
However, I'm very thankful for your interest.
Flavio

> Take a look at the generated app.c file to see if it's maybe being
> optimized out for you. You could try tagging the variable as
> "volatile" as well.
> 
> MS
> 
> Flavio Pompermaier wrote:
> > Hi to all,
> > I have a VERY strange problem with a component variable. 
> > In a component scope of my application (immediately under the implementation keyword) I have defined a uint16_t variable "epochs" that is increased ad each firing of a periodic timer.
> > It is used by the component to clean things up when timeouts expire.
> > After some strange behavior on testing the code on tmote sky (simulation with TOSSIM have always run correctly) I discovered (sending data over the serial) that the value of such variable is corrected almost everywhere in the code, apart in a LOCAL function (called by another LOCAL function) - used to make code simpler to read - where its value is always 0 unless I put the inline keyword before the function. How is it possible and why?? Is it because It is bad to use local functions?? Should all local functions  be declared inline??
> > 
> > For the sake of clarity, 
> > here it is an equivalent (pseudo-code) component describing my problem:
> > 
> > module TestModule{
> >   uses{
> >     interface Timer<TMilli> as EpochTimeout;
> >   }
> > }implementation{
> >    uint16_t epochs;
> > 
> >   event void EpochTimeout.fired(){
> >     epochs++; //here the value is correct
> >   }
> >   
> >   command error_t Send.send(message_t* msg){
> >     processMsg(msg);
> >   }
> >   void processMsg(message_t* msg){
> >      updateTimeouts(msg);
> >   }
> >   void updateTimeouts (message_t* msg){
> >      print(epochs);//here the value of epochs is always 0;
> >        //However, it is correct if I declare function as inline!!
> >    }
> > }
> > 
> > Best regards,
> > Flavio
> > 
> > 
> > 
> > 
> > _______________________________________________
> > Tinyos-help mailing list
> > Tinyos-help at millennium.berkeley.edu
> > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
> 
> -- 
> Platform: WinXP/Cygwin
> TinyOS version: 1.x, Boomerang
> Programmer: MIB510
> Device(s): Mica2, MicaZ, Tmote
> Sensor board: homebrew
> 
> 




More information about the Tinyos-help mailing list