This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Global Varibale not global? (CC2431 - SimpleApp - 1.4.2-1.1.0)

Other Parts Discussed in Thread: Z-STACK

Using Z-Stack 1.4.2-1.1.0 with modified SimpleApp:

 

I declared a global variable LAST_SMS in SimpleApp.h:

static bool  LAST_SMS;                // indicating that all SMS of the session are sent

 

during the run-time I set this varibale in SimpleCoordinator.c to TRUE:

LAST_SMS = TRUE;

According to the debugger in the watch-window it is changed.

 

It follows a function call to sapi.c:

zb_WriteSmsToUart ( (uint8 *)SmsContext, 5 );

where the SMS is sent out.

 

The response from the modem triggers the UART callback funtion in sapi.c, which checks if LAST_SMS is TRUE or FALSE to see if multiple SMS have to be sent out, but at this point of time the variable has changed to FALSE.There is currently only one command setting the varibale wrong in the entire project and that is during initialisation of the device and that line is not called.

Where or why is the variable set back to FALSE?

Do I use the variable wrongly? When yes, what is the right way of doing it?

 

Thanks. Appreciate EVERY reply, even the smallest!

  • When you declare the static variable in the header file, all the source files that includes the header file will have its own copy of the variable. This is probably not intended, since you want them to modify the same variable. When static is used the variable only has file scope.

    Instead of static I think you need to declare the variable as extern in the same header file. The source file that includes the header file will then need to define the variable again without the extern keyword.

    I hope this helps.

  • I will test it out and will write a feedback here. THX for your help.

     

    UPDATE:

    declaring the variable as

    extern static type var_name;

    has done teh job.

     

    Thanks