Page 1 of 2

OSCreateMsg

PostPosted: Tue Mar 25, 2008 2:19 am
by Gerald
hi,

how could i pass a struct to a message queue? need one example with OSSignalMsg and OS_WaitMsg!

greets


Re: OSCreateMsg

PostPosted: Tue Mar 25, 2008 5:56 am
by aek
When signaling, you always cast to OStypeMsgP, e.g.
code:
OSSignalMsg(OSECBP(2), (OStypeMsgP) 1);

Otherwise you'll get a compile-time error, etc.

When waiting, you need to derefence based on the type of the message that you have sent ...

Generally, we suggest that you debug into the dereferencing call afetr a successful OS_WaitMsg() ... look at the Salvo user manual, and within one or two tries you'll have successfully dereferenced the message (in your case a struct).

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


Re: OSCreateMsg

PostPosted: Wed Mar 26, 2008 12:57 am
by Gerald
i did, but without any luck;/

typedef struct foo
{
int i;
int j;
}foo;

foo foo1;

void Task1()
{
foo1.i = 2;
foo1.j = 3;

for(;
{
OSSignalMsg(MSG_SIG_RECEIVED_P, (OStypeMsgP)&foo1);
OS_Delay(100);
}
}

void Task2()
{
OStypeMsgP msgP;
foo *foo_ptr;

for(;
{
OS_WaitMsg(MSG_SIG_RECEIVED_P, &msgP, OSNO_TIMEOUT);
message_ptr = (struct foo*)msgP;

OS_Delay(10);
}
}

[This message has been edited by Gerald (edited March 26, 2008).]


Re: OSCreateMsg

PostPosted: Wed Mar 26, 2008 5:50 am
by aek
No, it means that the message has already been signaled and not successfully waited yet -- this is documented in the User Manual.

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


Re: OSCreateMsg

PostPosted: Wed Mar 26, 2008 10:13 am
by Gerald
and what is:

OStypeErr err;
err = OSSignalMsg(MSG_NEW_TARGET_POSITION_P, (OStypeMsgP) &newtargetpos);

returns me err = 4...what does it mean????

i saw #define OSERR_EVENT_FULL 4
right error? is it allowed to OSSignalMsg from an interrupt?

[This message has been edited by Gerald (edited March 26, 2008).]


Re: OSCreateMsg

PostPosted: Thu Mar 27, 2008 12:44 am
by Gerald
hi,
i can reproduce the error now!
if it comes to err = OSSignalMsg(MSG_NEW_TARGET_POSITION_P, (OStypeMsgP) 5); the second time, OSSignalMsg returns me 4! no idea why!?

greets

code:
#include "salvo.h"

#define TASK_COUNT_P OSTCBP(1) /* task #1 */
#define TASK_SHOW_P OSTCBP(2) /* "" #2 */
#define TASK_BLINK_P OSTCBP(3) /* "" #3 */
#define PRIO_COUNT 10 /* task priorities*/
#define PRIO_SHOW 10 /* "" */
#define PRIO_BLINK 10 /* "" */
#define MSG_LIN_SIG_RECEIVED_P OSECBP(4)
#define MSG_NEW_TARGET_POSITION_P OSECBP(5)
#define MSG_TARGET_POSITION_REACHED_1_P (6)
#define MSG_TARGET_POSITION_REACHED_2_P (7)


#define PORT PORTC
#define InitPORT() do { DDRC = 0xFF;
PORT = 0x00;
} while (0)

#define Init() do { TCCR1B = 0x00; /* Stop Timer1 */
TCNT1H = 0x00; /* Clear Timer1 */
OCR1AH = 0x00; /* Set Compare A to 39 */
OCR1AL = 0x26; /* ((4MHz/1024)/39) = 10ms (9.984ms) timer */
TIMSK1 = 0x02; /* Compare A Interrupt enable */
TCCR1B = 0x0D; /* Start Timer1 with clk/1024 */
} while (0)

int received = 0;

void TaskCount( void )
{
OStypeErr err;

for (; ;)
{
if(received == 0)
{
received = 1;
err = OSSignalMsg(MSG_LIN_SIG_RECEIVED_P, (OStypeMsgP) 0);
}

OS_Delay(100);
}
}

void TaskShow( void )
{
OStypeErr err;
OStypeMsgP msgP;

for (; ;)
{
OS_WaitMsg(MSG_LIN_SIG_RECEIVED_P, &msgP, OSNO_TIMEOUT);

err = OSSignalMsg(MSG_NEW_TARGET_POSITION_P, (OStypeMsgP) 5);

OS_WaitMsg(MSG_TARGET_POSITION_REACHED_2_P, &msgP, OSNO_TIMEOUT);
received = 0;

OS_Delay(1000);
}
}

static void init_timer2()
{
TCCR2A = 0x00; // disable PWM and Compare Output Mode
TCCR2B = (1 << CS22)|(1 << CS21)|(0 << CS20); // use CLK/256 prescale value

// enable OutputCompareA Interrupt for Timer1
TIMSK2 |= 1 << OCIE2A;
}

static void start_timer2()
{
OCR2B = 255;//39;
TCNT2 = 0; // Timer Startwert
}

int counter = 0;

ISR(SIG_OUTPUT_COMPARE2A)
{
TCNT2=0x00;

counter++;

if(counter == 10)
{
// disable OutputCompareA Interrupt f�r Timer1
TIMSK2 &= ~(1 << OCIE2A);

OSSignalMsg(MSG_TARGET_POSITION_REACHED_2_P, 5);
}

OSTimer(); // call scheduler
}

void TaskBlink( void )
{
OStypeMsgP msgP;
OStypeErr err;
unsigned char targetpos = 0;

for (; ;)
{
OS_WaitMsg(MSG_NEW_TARGET_POSITION_P, &msgP, OSNO_TIMEOUT);
targetpos = (unsigned char)msgP;
init_timer2();
start_timer2();

OS_Delay(50);
}
}

void main( void )
{
Init();
OSInit();
OSCreateMsg(MSG_LIN_SIG_RECEIVED_P, (OStypeMsgP) 0);
OSCreateMsg(MSG_NEW_TARGET_POSITION_P, (OStypeMsgP) 0);
OSCreateMsg(MSG_TARGET_POSITION_REACHED_1_P, (OStypeMsgP) 0);
OSCreateMsg(MSG_TARGET_POSITION_REACHED_2_P, (OStypeMsgP) 0);

OSCreateTask(TaskCount, TASK_COUNT_P, PRIO_COUNT);
OSCreateTask(TaskShow, TASK_SHOW_P, PRIO_SHOW);
OSCreateTask(TaskBlink, TASK_BLINK_P, PRIO_BLINK);
sei();
for (; ;)
OSSched();
}

ISR(TIMER1_COMPA_vect)
{
OSTimer();
}



i used the following config:
code:

#define OSEVENTS 1
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 4
#define OSTASKS 3

[This message has been edited by aek (edited March 27, 2008).]


Re: OSCreateMsg

PostPosted: Thu Mar 27, 2008 3:19 am
by Gerald
ok, solved! i increased number of OSEVENTS!

is it possible with salvo to wait for multiple events or messages or semaphores in one thread like WaitForMultipleObjects -> under win32 http://msdn2.microsoft.com/en-us/library/ms687025(VS.85).aspx
??

i want to wait for 2 events or semaphores or messages in one thread...if one of them is set it should continue the task...

bye

[This message has been edited by Gerald (edited March 27, 2008).]


Re: OSCreateMsg

PostPosted: Thu Mar 27, 2008 4:53 am
by aek
quote:
the second time
Because you haven't waited it yet .. you signaled, and signaled again without having waited (i.e. without having "received") the message. You need to signal .. wait successfully ... signal ... wait successfully ...

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


Re: OSCreateMsg

PostPosted: Thu Mar 27, 2008 4:56 am
by aek
Also, you salvocfg.h is not the one you think you're using ... please show the _whole_ salvocfg.h, plus you need to increase OSEVENTS, etc.

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


Re: OSCreateMsg

PostPosted: Fri Mar 28, 2008 4:17 am
by aek
quote:
i want to wait for 2 events or semaphores or messages in one thread...if one of them is set it should continue the task...
With binSems, sems, msgs and msgQs, a task can wait multiple events, but only sequentially ... i.e. it can wait for a binSem to be signaled, then for a message to be signaled, etc.

To have multiple tasks wait "together", or to have a single task wait on (near-)simultaneous signals from a multitude of places, use Salvo's event flags (eFlags).

Something like WaitForMultipleObjects for binSems, sems, msgs and msgQs wuld take a large amount of RAM or a very susbstantial run-time performance hit, neither of which are compatible with Salvo's design.

In summary, use event flags for something like WaitForMultipleObjects.

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