Pumpkin, Inc.

Pumpkin User Forums

MsgQ

If you have a general question or comment regarding Salvo, post it here.

MsgQ

Postby Justin » Thu Jul 17, 2008 3:09 am

Hello,

Could u take a look at my msgq example:

code:
// Compiled with IAR
#include <ioavr.h>
#include <intrinsics.h>

#include <salvo.h>
#include "os.h"

#define InitTimer2() do { TCCR2A = 0x00;
TCCR2B = (0 << CS22)|(1 << CS21)|(1 << CS20);
TIMSK2 |= 1 << OCIE2A;
OCR2A = 250;/*0x07;*/
TCNT2 = 0;
} while (0)


_OSLabel(TaskRcv_)
_OSLabel(TaskSend1_)
_OSLabel(TaskRcv2_)

struct foo
{
int flag;
};

void TaskRcv( void )
{
static struct foo *message_ptr;
static OStypeMsgP msgP;

while (1)
{
/* Wait forever for a message. */
OS_WaitMsgQ(MSGQ1_P, &msgP, OSNO_TIMEOUT, TaskRcv_);

/* A message has arrived – get it. */
message_ptr = (struct foo*) msgP;
printf("flag: %d
", message_ptr->flag);

OS_Delay(100, TaskRcv_);
}
}

void TaskSend1( void )
{
OStypeMsgP msgP;

while (1)
{
struct foo foo1;

// wait for a free slot
while(OSMsgQEmpty(MSGQ1_P) == false)
{
OS_Delay(1, TaskSend1_);
}

foo1.flag = 1;
// send as long as OSSignalMsgQ succeeds
while(OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) &foo1) != OSNOERR);

OS_Delay(47, TaskSend1_);
}
}

void TaskSend2( void )
{
OStypeMsgP msgP;

while (1)
{
struct foo foo2;

// wait for a free slot
while(OSMsgQEmpty(MSGQ1_P) == false) {
OS_Delay(1, TaskSend1_);
}

foo2.flag = 0;
// send as long as OSSignalMsgQ succeeds
while(OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) &foo2) != OSNOERR);

OS_Delay(63, TaskSend2_);
}
}

/* allocate memory for buffers */
OSgltypeMsgQP MsgQBuff1[SIZEOF_MSGQ1];
/* create message queues from existing */
/* buffers and mqcbs. */

void main()
{
int x = 0;
OStypeErr err;

__enable_interrupt();
/* Timer 2 init */
InitTimer2();
/* Salvo Init */
OSInit();

err = OSCreateMsgQ(MSGQ1_P, MQCB1_P, MsgQBuff1, SIZEOF_MSGQ1);
x++;
if(err != OSNOERR)
goto os_error;

err = OSCreateTask(TaskRcv, Task_Rcv_P, Prio_TaskRcv);
x++;
if(err != OSNOERR)
goto os_error;

err = OSCreateTask(TaskSend1, Task_Send1_P, Prio_TaskSend1);
x++;
if(err != OSNOERR)
goto os_error;

err = OSCreateTask(TaskSend2, Task_Send2_P, Prio_TaskSend2);
x++;
if(err != OSNOERR)
goto os_error;

/* Sched */
for (; ;)
{
OSSched();
}

os_error:
for (; ;)
{
asm("nop");
}
}

/* OS Timer Tick */
__interrupt void Timer2Interrupt( void )
{
// OS Timer Tick for Salvo
OSTimer();
}


is this the right way to work with msgq, is it allowed to pass a local struct to a OSSignalMsgQ? is the delay necessary at wait "for a free slot"? is there some delay neccessary? -> while(OSSignalMsgQ(MSGQ1_P, (OStypeMsgP) &foo1) != OSNOERR);

greets

[This message has been edited by Justin (edited July 17, 2008).]

[This message has been edited by aek (edited July 17, 2008).]

Justin
 
Posts: 5
Joined: Wed Jul 16, 2008 11:00 pm

Re: MsgQ

Postby aek » Thu Jul 17, 2008 3:52 am

1) You don't have to wait for anything -- you could always just send the message via OSSignalMsgQ(), and check its return code (success or was full), and act on that. That sort of thing is entirely up to you.

2) Passing a local struct is likely not going to work because the struct itself is not copied into memory ... i.e. you signal with a pointer to the struct, and if said struct changes before you dereference the pointer upon a successful wait of the message, you won't be happy. So either you must accept that there is no persistence to your struct (the pointer persists, but the struct can change), or you push your structs into a (ring) buffer that your pointers point to. In the latter case, signaling adds a copy of the struct to the buffer (via your code) and a (copy of the) pointer to the msgQ (OSSignalMsgQ()), and successfully waiting the msgQ removes the pointer from the msgQ (OS_WaitMsgQ()) and removes the struct from your buffer (your code).

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

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

Re: MsgQ

Postby tbims23822 » Tue Jul 07, 2009 7:02 am

[www.drop-shopping.com is a premium website for cheap air jordans shoes and other more really nike air jordan shoes.We have varity of cheap air jordan shoes available for wholesale.Cheap China wholesale shoes including cheap Nike shoes and cheap jordan shoes,nike sneakers,nike sneakers discount,air jordan sneakers,air force sneakers.We supply nike sneakers,jordan sneakers,air jordan sneakers,air force sneakers wholesale.You can buy very cheap jordans shoes including cheap women shoes,cheap nike shoes,cheap running shoes from us.
tbims23822
 


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron