Yes the shared header file approach def works. I have included three such header files in various components in my project and it seems to be working smoothly. Just make sure to include the access to the shared data within atomic statements to avoid race conditions.

On 5/9/06, Michael Schippling <[EMAIL PROTECTED]> wrote:
I couldn't make externs work between components either...

So I have used an interface in each component that takes a pointer
to the variable in question and saves it locally. Each component
then does an indirect access to the variable through the pointer.

e.g.:

in comp1 --
        long stuff;

        setup()
        {
                call comp2.setVariable( &stuff );
        }

in comp2 --
        long *stuffp;

        setVariable( long *p )
        {
                // save pointer
                stuffp = p;

                // set variable to something
                *stuffp = 0xDADABABE;
        }


However it has occurred to me that one should be able to do it via
a shared header file, and I just tried it. This actually compiles
and looking at the app.c output it seems ok, but I don't know if it
really works because I haven't run the code...

in header.h --
        #ifndef DEFED
        uint16_t monstate;
        #define DEFED
        #endif // DEFED

        extern uint16_t monstate;

in each component --

        includes header;
              ....

        implementation
        {
                // use "global" variable
                monstate = 0xBEEF;
        }


If you try the header method, let me know how it goes...
MS


[EMAIL PROTECTED] wrote:
> hi,
>
> I m trying how ti share a variable between two components. I m using
> global variable concept, but not working. Did anyone like this or any
> other method is there?
>
> Thanks,
> kiran.
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help



--
regards,
Aditya Bhave
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to