Pumpkin, Inc.

Pumpkin User Forums

OS_WaitMsg

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

OS_WaitMsg

Postby aek » Sun Oct 07, 2001 3:51 am

OS_WaitMsg() is more like "a block in the code that must be executed before moving on."

Another way to think of OS_WaitMsg() is that it's a function that returns when the message is received.

If you were waiting with a timeout, then it would return either i) if the message were received or ii) if it timed out waiting for the message.

I think in the code example you meant to type MSG_GET_COUNT and not MSG_GET_TIME (or vise versa). You can edit your original message if you like ...

Here's a solution to your problem:

code:
for(;;)  {
OS_WaitMsg(MSG_SET_COUNT, &msgP, Task1);
count = *(char *) msgP;
msgP = OSTryMsg(MSG_GET_TIME)
if ( msgP ) {
localtime = count;
count++;
}
}

This works as follows: The task waits for MSG_SET_COUNT as usual. After this message arrives, it tries to get MSG_GET_TIME. If this message exists, then msgP is non-zero and the message is cleared (this happens inside OSTryMsg()), and localtime gets updated. If the message does not exist, then localtime is left alone, etc. This way, MSG_GET_TIME is checked as often as MSG_SET_COUNT is signaled.

------------------

[This message has been edited by aek (edited October 07, 2001).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OS_WaitMsg

Postby kiddster » Sun Oct 07, 2001 7:16 am

Does the OS_WaitMsg function like a goto, or is it simply a block in the code that must be executed before moving on? Maybe I can illustrate my question better with an example.

I have task where I want to have two separate blocks of code that will affect the same static variables.


code:
TaskCounter{}
{
static OStypeMsgP msgP;
static char count;
static char localcount;

OSCreateMsg(MSG_SET_COUNT, (OStypeMsgP) 0);
OSCreateMsg(MSG_GET_COUNT, (OStypeMsgP) 0);

for(;;)
{
OS_WaitMsg(MSG_SET_COUNT, &msgP, Task1);

count = *(char *) msgP;

OS_WaitMsg(MSG_GET_TIME, &msgP, Task2);

localtime = count;

count++;
}


Now, if I want to get the value of the counter every second and I will be setting the counter value once in a great while (every hour), will such a scheme as described above work? Or, will the task be locked into waiting for MSG_SET_COUNT?

-bk

[This message has been edited by aek (edited October 07, 2001).]

kiddster
 
Posts: 5
Joined: Fri Sep 21, 2001 11:00 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron