Pumpkin, Inc.

Pumpkin User Forums

Head of Message Queue

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

Head of Message Queue

Postby Bummibaer » Tue Dec 04, 2007 1:18 am

Hello,

where do I get the head of a message queue
for signaling(!)?
Here is a snippet from my code:

code:
MSD_Frame_t*  MsgQBuff_RX[SIZEOF_MSGQ_ECB_RX];
OSCreateMsgQ(MSGQ_ECB_RX, MSGQ_ECB_RX_P, (OStypeMsgP)MsgQBuff_RX, SIZEOF_MSGQ_ECB_RX);
...
MSD_Frame_t *GetMSDFrame( OStypeEcbP ecbP , FrameBuffer_t *msgq ) {
MSD_Frame_t *p_rc;
OStypeMsgQSize count = OSMsgQCount(ecbP);
// @TODO // if Queue full
p_rc = msgq->test.frame+count;
assert( p_rc ) ;
if ( p_rc == NULL ) {
puts("Queue Error");
NOP;
}

return p_rc;
}


This looks weird.
Is there a better solution?

Thanks,

Steffen

[This message has been edited by aek (edited December 05, 2007).]

Bummibaer
 
Posts: 15
Joined: Thu Sep 13, 2007 11:00 pm
Location: Dresden,Germany

Re: Head of Message Queue

Postby Bummibaer » Tue Dec 04, 2007 7:36 am

Hi,

I have programmed the following function,
and it does work:

code:
OSMONITOR_KEYWORD_PRE
OStypeMsgP OSMsgQHeader ( OStypeEcbP ecbP )
OSMONITOR_KEYWORD_POST
OSMSGQCOUNT_ATTR
{
static OStypeMsgP header_p;

OSBeginCriticalSection();
OSIncCallDepth();

header_p = ecbP->event.mqcbP->inPP;

OSDecCallDepth();
OSEndCriticalSection();

return header_p;
}


Steffen

[This message has been edited by aek (edited December 05, 2007).]

Bummibaer
 
Posts: 15
Joined: Thu Sep 13, 2007 11:00 pm
Location: Dresden,Germany

Re: Head of Message Queue

Postby aek » Tue Dec 04, 2007 9:24 am

Can you explain in words what you want to be able to do?

inP points to the next (empty) message. I think you want outP...

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

Re: Head of Message Queue

Postby Bummibaer » Tue Dec 04, 2007 11:39 am

quote:
Originally posted by aek:
Can you explain in words what you want to be able to do?

inP points to the next (empty) message. I think you want outP...


Yes, I have some sources for the queue, and
one receiver.
Every source repeatly does:

code:
while(true)
{
// get next Queue-Entry/ my solution
data = OSMsgQHeader(MSGQ);
// write some stuff
data.foo = var++;
// send data
OSSendMsgQ(MSGQ,&data);
}

How does this routine know, which Adress:
&data
to use?
data
has to be static, and in the Array
MSD_Frame_t* MsgQBuff_RX[SIZEOF_MSGQ_ECB_RX];
or not?
Therefore my Routine.

Thanks,

Steffen

BTW: How does work the UBB Code?
Do you see formatted output?
Me not.

[This message has been edited by aek (edited December 05, 2007).]

Bummibaer
 
Posts: 15
Joined: Thu Sep 13, 2007 11:00 pm
Location: Dresden,Germany

Re: Head of Message Queue

Postby aek » Wed Dec 05, 2007 3:55 am

Ouch!

There's no need to do that. Just force the raw data into the message queue by appropriate casting. Since you can put a message pointer into the queue, that also means you can put any raw data into the queue that will fit within sizeof(msgP).

What you're doing has a lot of dangers, not the least of which is the lack of protection.

I have no idea why this particular thread isn't using the code tag properly ...

Let me look at the count issue more closely -- that may indeed be a bug when OSENABLE_FAST_SIGNALING is set.

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

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

Re: Head of Message Queue

Postby aek » Wed Dec 05, 2007 4:08 am

quote:
I have no idea why this particular thread isn't using the code tag properly ...
Be sure to use the forward-slash ('/') for embedded tags ...

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

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

Re: Head of Message Queue

Postby Bummibaer » Wed Dec 05, 2007 8:31 am

Hello,

What's about OSMsgQCount?
When OSENABLE_FAST_SIGNALING
is set, the count-variable will incremented
by MsgQSend, but not decremented (!) by MsgQWait!

Is this a bug or a feature?

Thanks,

Steffen

Bummibaer
 
Posts: 15
Joined: Thu Sep 13, 2007 11:00 pm
Location: Dresden,Germany

Re: Head of Message Queue

Postby aek » Thu Dec 06, 2007 2:57 am

I think this is what you were after ...
code:
void task_provide1 (void)
{
static int i = 0;
static char code[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};


OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i++%10]);
OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i++%10]);
OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i++%10]);

user_msg(STR_TASK_PROVIDE1 STR_TABS "Starting.");
while (1) {
OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i%10]);
sprintf(strTmp, STR_TASK_PROVIDE1 STR_TABS "Sent %c", code[i++%10]);
user_msg(strTmp);
OS_Delay(17);
}
}

void task_provide2 (void)
{
static int i = 0;
static char code[6] = {'A', 'B', 'C', 'D', 'E', 'F'};


OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i++%6]);
OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i++%6]);
OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i++%6]);
OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i++%6]);
OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i++%6]);

user_msg(STR_TASK_PROVIDE2 STR_TABS "Starting.");
while (1) {
OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) code[i%6]);
sprintf(strTmp, STR_TASK_PROVIDE2 STR_TABS "Sent %c", code[i++%6]);
user_msg(strTmp);
OS_Delay(43);
}
}


code:
void task_consume (void)
{
OStypeMsgP msgP;
char code;

user_msg(STR_TASK_CONSUME STR_TABS "Starting.");
while (1) {
OS_WaitMsgQ(MSGQ1_P, &msgP, OSNO_TIMEOUT);
code = (char) ((int) msgP & 0xFF);

sprintf(strTmp, STR_TASK_CONSUME STR_TABS "Received %c", code);
user_msg(strTmp);
}
}


and here's the timestamped output:
code:
init: Starting

1:0000000000 task_provide1: Starting.
1:0000000000 task_provide1: Sent 3
1:0000000000 task_consume: Starting.
1:0000000000 task_consume: Received 0
1:0000000000 task_consume: Received 1
1:0000000000 task_consume: Received 2
1:0000000000 task_consume: Received 3
1:0000000000 task_provide2: Starting.
1:0000000000 task_provide2: Sent F
1:0000000000 task_consume: Received A
1:0000000000 task_consume: Received B
1:0000000000 task_consume: Received C
1:0000000000 task_consume: Received D
1:0000000000 task_consume: Received E
1:0000000000 task_consume: Received F
1:0000000017 task_provide1: Sent 4
1:0000000017 task_consume: Received 4
1:0000000034 task_provide1: Sent 5
1:0000000034 task_consume: Received 5
1:0000000043 task_provide2: Sent A
1:0000000043 task_consume: Received A
1:0000000051 task_provide1: Sent 6
1:0000000051 task_consume: Received 6
1:0000000068 task_provide1: Sent 7
1:0000000068 task_consume: Received 7
1:0000000085 task_provide1: Sent 8
1:0000000085 task_consume: Received 8
1:0000000086 task_provide2: Sent B
1:0000000086 task_consume: Received B
1:0000000102 task_provide1: Sent 9
1:0000000102 task_consume: Received 9
1:0000000119 task_provide1: Sent 0
1:0000000119 task_consume: Received 0
1:0000000129 task_provide2: Sent C
1:0000000129 task_consume: Received C
1:0000000136 task_provide1: Sent 1
1:0000000136 task_consume: Received 1
1:0000000153 task_provide1: Sent 2
1:0000000153 task_consume: Received 2
1:0000000170 task_provide1: Sent 3
1:0000000170 task_consume: Received 3
1:0000000172 task_provide2: Sent D
1:0000000172 task_consume: Received D


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

[This message has been edited by aek (edited December 06, 2007).]

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

Re: Head of Message Queue

Postby aek » Thu Dec 06, 2007 3:05 am

The startup order of the tasks is of course dictated by their priorities:
code:

#define TASK_PROVIDE1_P OSTCBP(1)
#define TASK_PROVIDE2_P OSTCBP(2)
#define TASK_CONSUME_P OSTCBP(3)

#define PRIO_TASK_PROVIDE1 4
#define PRIO_TASK_PROVIDE2 14
#define PRIO_TASK_CONSUME 11


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

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

Re: Head of Message Queue

Postby Bummibaer » Thu Dec 06, 2007 4:04 am

Hi aek

I have asynchronous incomes, which go into
the Queue and a somewhat synchronous
Read-Routine. Therefore I need a static pointer
to a array, in which the data will be stored:
-----------------------------------------

code:
void Send0(void)
{
static char data= 0x30;
static char *p_data = &data;
data++;
printf("Send %c
",*p_data);
OSSignalMsgQ(MSGQ_ECB_SEND,(OStypeMsgP)p_data);

}
void Send1(void)
{
static char data[10]= {0x30,0x31,0x32,0x33,0x34,0x35,6,7,8,9};
static char *p_data = data;
printf("Send %c
",*p_data);
OSSignalMsgQ(MSGQ_ECB_SEND,(OStypeMsgP)p_data++);

}
void TaskTx(void)
{
char *p_data;
for(; ;)
{
OS_WaitMsgQ(MSGQ_ECB_SEND,(OStypeMsgPP)&p_data,OSNO_TIMEOUT);
printf("Got %c
",*p_data);

}
}


from send0 I get ( right):
Send 0
Send 1
Send 2
Send 3
Send 4
Send 5
Got 0
Send 
Send 
Got 1
Send 
Send
Got 2
Send
Send
Got 3
...


from send1 I get ( wrong):

Send 0
Send 1
Send 2
Send 3
Send 4
Send 5
Got 5
Send 6
Send 7
Got 7

You see the point?
But as easy, as Send0 it isn't.
I have to write to the Head of the queue,
because I don't know, how many RX it serves
between Sends!

regards,

Steffen

[This message has been edited by aek (edited December 06, 2007).]

Bummibaer
 
Posts: 15
Joined: Thu Sep 13, 2007 11:00 pm
Location: Dresden,Germany

Next

Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron