Pumpkin, Inc.

Pumpkin User Forums

Messages and MessageQ's

If you can't make Salvo do what you want it to do, post it here.

Messages and MessageQ's

Postby Salvo Tech Support » Tue Feb 13, 2001 6:56 am

Hi ChrisV.

The issue is persistence, and you'll find a discussion of this issue in the User Manual's FAQ, under "I'm using a message event to pass a character variable to a waiting task, but I don't get the right data when I dereference the pointer. What's going on?"

The short answer is "They must be declared global or static to the function."

Think of it this way ... if they were local, and you signaled a message, and then the task that was waiting the message acquired the message via OS_WaitMsg() a long time later, what do you think happened to the local variable in the meantime? You guessed it, since it's an auto variable, it was probably used by some other part of the program, and its value changed.

If PICs had tons of RAM, one could make a copy of the local message ... but PICs have nearly no RAM, so you must live with this requirement. If you're passing something that could be declared as a constant, then of course by all means declare it as const, and save the RAM.

And thanks, Luben, you were right on ...

[This message has been edited by Salvo Tech Support (edited February 13, 2001).]

--------
Salvo Technical Support
Please request all tech support through the Forums.
Salvo Tech Support
 
Posts: 173
Joined: Sun Nov 19, 2000 12:00 am

Re: Messages and MessageQ's

Postby ChrisV » Tue Feb 13, 2001 8:57 am

Hello,
When using variables that are passed from task to task via messages and messageq's, is it neccessary for these variables to be Global or can they be Local to the task and its function.
ChrisV
 
Posts: 10
Joined: Wed Jan 24, 2001 12:00 am
Location: Chandler, AZ

Re: Messages and MessageQ's

Postby luben » Tue Feb 13, 2001 11:52 am

Hello,

I think that the rule is - if you use the variable only in the task and you don't care for its value after returning from scheduler - then this variable could be local.

To protect variables from changing from other tasks you should declare it like global/static. So, when you return the control to scheduler with OS_Yield() OS_WaitXXX and other OS_ZZZZ commands you have to know which variables should keep their value and to declare them like static/global.

And you can return the control to the scheduler only from the main task level, that means - all function calls don't depend on SALVO.

Regards
Luben

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria


Return to Coding

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

cron