Page 1 of 1

Signaling from ISR and Task

PostPosted: Tue May 20, 2008 12:34 am
by Gerald
hi,

when i have the following example...
ISR and Task1 is signaling a message with different content!
if Task1 is signaling a message and task2 waits for receiving...the ISR might overwrite the num? Is there a solution from Salvo for this special case?

bye

static unsigned int num = 0;

ISR(SIG_OUTPUT_COMPARE1A)
{
//....

/* get message pointer (may be 0). */
while((msgP = OSTryMsg(MSG1_P)) != NULL)
{
OS_Delay(1);
}
num = 1;
OSSignalMsg(MSG1_P, (OStypeMsgP) &num);
}

void Task1()
{
while(1)
{
//....

/* get message pointer (may be 0). */
while((msgP = OSTryMsg(MSG1_P)) != NULL)
{
OS_Delay(1);
}
num = 2;
OSSignalMsg(MSG1_P, (OStypeMsgP) &num);
}
}

void Task2()
{
while(1)
{
//....

/* wait forever for a message. */
OS_WaitMsg(MSGQ1_P, &msgP);

receivednum = (unsigned int) msgP;
printf("received %d
", receivednum);
}
}