Page 1 of 1

Message Passing

PostPosted: Tue Jun 07, 2005 10:31 am
by david1024
I'm using Salvo Lite/MCC-18/MPLAB v7.01.

I can't seem to get salvo to pass a message from one task to another. Here's a snippit of code..... All tasks have priority '10'

static unsigned int result;
static unsigned int temp;

static OStypeMsgP msgP;
#define MSQ_1 OSECBP(1)
#define MSQ_1CB OSMQCBP(1)
#define SIZEOF_MSQ_1 3
void main( void )
{
Init();
OSInit();
OSCreateTask(ReadData, READDATA_P , READDATA_PRIORITY);
OSCreateTask(Governor, GOVERNOR_P , GOV_PRIORITY );
OSCreateTask(Throttle, THROTTLE_P, THROTTLE_PRIORITY);
OSCreateMsg(MSQ_1,(OStypeMsgP) 0);
counter = 0;
status = 3;
result = 5;
Delay10TCYx(5);
OSEi();
for (;;)
OSSched();
}


...this is how I'm sending the message:

OSSignalMsgQ(MSQ_1,(OStypeMsgP)&result);
temp = (unsigned int) OSReadMsg(MSQ_1);

OSReadMsg returns NULL instead of a pointer to 'result' ('result' and 'temp' are global unsigned int, result is always initilized to 0x05--result is at memory location 0xC1)
MPLAB also says that msgP is 'out of scope' too...

I think that my salvocfg.h is correct (no compilation errors), but there weren't any message passing examples in the tutorials that I could find...So I'm going to include it here too.(MAKE_WITH_FREE_LIB is defined in the IDE)

/* */
/* Salvo Lite build */
/* */
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_GLOBALS OSF
#define OSLIBRARY_CONFIG OSA
#define OSEVENTS 3
#define OSEVENT_FLAGS 1
#define OSMESSAGE_QUEUES 1
#define OSTASKS 3


There are three tasks in the program and they all start, but one task blocks waiting on the message and never continues. (probably because I'm not sending the message properly...)

The Free/Lite version does allow a single message que, right?

[This message has been edited by david1024 (edited June 07, 2005).]

[This message has been edited by david1024 (edited June 07, 2005).]


Re: Message Passing

PostPosted: Wed Jun 08, 2005 12:51 am
by aek
Hi David.

For a message queue (and yes, Salvo Lite supports one message queue) you also need to declare a buffer for the message queue -- see docs for OSCreateMsgQ(). I suspect that you don;t have one defined, and therefore the Salvo message queue functions are choking because they don't have anywhere to place the message.

If you just want to pass a message, then use OSSignalMsg() etc. instead ...

The rest of your code looks fine. Either switch to messages (for now, to get it working) or declare the buffer that the messages will go into ...


Re: Message Passing

PostPosted: Mon Jun 13, 2005 11:00 am
by david1024
Thanks for the help. (and the pointers to the example code in the manual.)

I've set the code up properly for a message que of size = 3, but where do I look to see what the head of the que is pointing to or if there are currently messages in the queue?

(I've been using debug code like
temp = (unsigned int) OSReadMsgQ(MSQ_1); but this is useless if many of the same pointers are in the queue)


Re: Message Passing

PostPosted: Mon Jun 13, 2005 11:11 am
by aek
Hi David.

You don't normally want to know about the "innards" of the message queue, because it's not one where you can extract an arbitrary message.

Rather, it's a FIFO message queue, and you normally get the oldest message when you successfully wait the message queue in a task via OS_WaitMsgQ().

You can always use OSMsgQCount() and OSMsgQEmpty() to get status on the message queue.

Services like OSReadMsgQ() are not normally used -- use OS_WaitMsgQ() instead. OSReadMsgQ() is basically a "peek" function.

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


Re: Message Passing

PostPosted: Mon Jun 13, 2005 11:26 am
by david1024
I agree, but we are still evaluating Salvo and haven't purchased it yet (Every thing looks good so far though). So I'm having to 'multiplex' the single MessageQue-- hence the 'peeking'. That was why I wanted access to the 'head-pointer' of the Que. (so I could see which element was first-out of the FIFO and minimize the ammount of dead-code I'm writing now.) I didn't want access to 'old' messages; I just wanted to see the que status, without debug code, in the simulator.

Anyway,
Once we have the full version, every task that needs messaging should have its own send/rec. as needed. (for this project it'll be about 3-4 total) And the need for this kind of information will go away.


Re: Message Passing

PostPosted: Mon Jun 13, 2005 11:34 am
by aek
Hi David.

OK, thanks, that makes sense!

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


Re: Message Passing

PostPosted: Tue Jun 14, 2005 8:31 am
by aek
David.

Send an email to support with the exact Salvo library name you're testing with and we'll build you a custom Salvo Lite library with more message queues for testing ...

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