Problems with GLOBAL VARIABLES

HI!,
I have a big problem when i define global variables, because the execution programs is doing extranges things.

I have 2 task. READ and WRITE

void Read (void) _task_ READ _priority_ 0 {


        unsigned int ReceivedMessage;

        while(1){

           ReceivedMessage=_getkey();
           os_send_message (MAILBOX, ReceivedMessage, WAIT_FOREVER);

        }
}
void Write (void) _task_ WRITE _priority_ 1 {

               unsigned int Message[6];
               while(1){

                  P2=0x01;
                  for(i=0;i<6;i++){

                        os_wait (K_MBX + MAILBOX, WAIT_FOREVER, &Message[i]);
                        P2<<=1;

                  }
                  /* ACCIONS */

but i need 3 variables for to save the results of the ACCIONS for share with others task.
At the top i declared the variables:

int ax,bx,cx


it is ok??
Maybe can do it others way??

Thanks

Parents
  • First off: Yes, you can declare your three global variables as you suggested. But you say you have a problem - but no description about that the problem is. What happens and what did you expect should happen?

    Note that this is an 8-bit processor, variables larger than 8 bits may be only partially updated if you eccess them from both interrupt handlers and normal code, or from two different tasks.

    Another thing: Why you you have the internal loop in the Write task, to wait for 6 mails? Shouldn't you process the mails one-by-one when you get them, or look into a different message model where you get one mail with all information? Is it six separate threads that should send one mail each before you start processing or? If you have multiple tasks that sends mails, you can't know in which order they will be received, so the index into the Message array can't be used to distinguish the mail source or mail type.

Reply
  • First off: Yes, you can declare your three global variables as you suggested. But you say you have a problem - but no description about that the problem is. What happens and what did you expect should happen?

    Note that this is an 8-bit processor, variables larger than 8 bits may be only partially updated if you eccess them from both interrupt handlers and normal code, or from two different tasks.

    Another thing: Why you you have the internal loop in the Write task, to wait for 6 mails? Shouldn't you process the mails one-by-one when you get them, or look into a different message model where you get one mail with all information? Is it six separate threads that should send one mail each before you start processing or? If you have multiple tasks that sends mails, you can't know in which order they will be received, so the index into the Message array can't be used to distinguish the mail source or mail type.

Children
More questions in this forum