Pumpkin, Inc.

Pumpkin User Forums

Using strings in message queues

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

Using strings in message queues

Postby Raj » Thu Nov 20, 2003 6:18 am

Hi,

I am unable to pass strings using message queues in my program. Please help.

The message is signaled this way:

char signal[2] = {0x01, 0x02};
OSSignalMsgQ(MsgQECBP, (OStypeMsgP) &signal);

and I am receiving it this way:-

void task2(void)
{
msgP = OSTryMsgQ(MsgQECBP);
if(msgP)
{
message = (char *) msgP;
putsUSART(message);
}
else
{
OS_Yield(task2LBL);
}
}

Please help.

Regards,
Raj.

Raj
 
Posts: 7
Joined: Wed Nov 19, 2003 12:00 am
Location: Erie, PA, USA

Re: Using strings in message queues

Postby aek » Thu Nov 20, 2003 7:18 am

Hello.

There could be a couple of things wrong -- please .zip up the whole project and email it to support and we'll get it working.

BTW, unless you've coded your example to explcitly handle null-message strings (i.e. you actually enqueue null-strings on purpose), there's no point in checking msgP and conditionally calling OS_Yield(). Do this instead:

code:
char signal[2] = {0x01, 0x02};
OSSignalMsgQ(MsgQECBP, (OStypeMsgP) &signal);


void task2(void)
{
msgP = OSTryMsgQ(MsgQECBP, ...);

message = (char *) msgP;
putsUSART(message);
}


You will only "reach" the dereferencing and putsUSART() when the task successfully waits (i.e. receives) a message. Message queues can carry NULL pointers as messages, but unless you're intentionally are signaling NULL pointers, there's no need to special-case them.

Also, it's not clear exactly how your example is failing -- build time? Run-timne? Did you remember to set OSMESSAGE_QUEUES to 1 in your salvocfg.h?

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

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

Re: Using strings in message queues

Postby Raj » Tue Dec 16, 2003 8:41 am

Hi AEK,

Thanks a lot for your help. I am having some other problems with passing ROM pointers.

I have a message declared in ROM as :

code:
#pragma romdata command = 0x3000
rom unsigned char pragma_ucHeartbeat[3] = {0x01, 0x01, 0x08};
#pragma romdata


...and in an interrupt handler i am signalling this message to a message queue...
code:
iHeartBeatTick++;
if( iHeartBeatTick >= (unsigned) 1000 )
{
iHeartBeatTick = 0;
OSSignalMsgQ(SMSMsgQ_ECBP, (OStypeMsgP) pragma_Heartbeat);
}


...and I am trying the message in a task ...
code:
unsigned char msgByte,msgSource,nBytes;	
static const char *PTR;
for(; ;)
{
msgP = OSTryMsgQ(SMSMsgQ_ECBP);
if(msgP)
{
PTR = (const char *)msgP;
nBytes = *PTR++;
msgSource = *PTR++;
msgByte = *PTR++;
while(BusyUSART());
putcUSART(nBytes);
while(BusyUSART());
putcUSART(msgSource);
while(BusyUSART());
putcUSART(msgByte);
}
}

I am unable to retreive the message. I was expecting the variables to hold the following values:

PTR: 0x3000
nBytes: 0x01
msgSource: 0x01
msgByte: 0x08

but it shows me as follows:

PTR: 0x3000
nBytes: 0x00
msgSource: 0x00
msgByte: 0x01

Please help me,
Raj.

[This message has been edited by aek (edited December 16, 2003).]

Raj
 
Posts: 7
Joined: Wed Nov 19, 2003 12:00 am
Location: Erie, PA, USA

Re: Using strings in message queues

Postby aek » Tue Dec 16, 2003 9:23 am

I don't know exactly why it's not working, but here's something to ponder:

1) You are apparently getting the right pointer value (0x3000) when you receive the message -- so far, so good.

2) You are dereferencing the pointer as a const char *, yet you declared the array as a rom unsigned char. I suspect that the two are not the same, and as a result the compiler is dereferencing PTR incorrectly.

Have you tried declaring pragma_ucHeartBeat[] as const char?

In general, if debugging shows that the pointer is correct (i.e. it's the right address, as you have in this case), then the issue is how the pointer is dereferenced. The declaration and dereferencing should only differ by a * ...

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

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

Re: Using strings in message queues

Postby aek » Tue Dec 16, 2003 9:30 am

BTW, since you don't context-switch between
code:
PTR = (const char *)msgP;

and using PTR, you don't need to declare PTR as static. Though declaring it as static may make debugging easier ...

I'm assuming that msgP is of type OStypeMsgP.

Lastly, why are you using OSTryMsg()? Most likely, you should be using OS_WaitMsg() ... OSTryMsg() is only for very specialized "probing" into the message event, e.g. from within an ISR.

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

[This message has been edited by aek (edited December 16, 2003).]

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


Return to Coding

Who is online

Users browsing this forum: No registered users and 4 guests

cron