Pumpkin, Inc.

Pumpkin User Forums

Problem with OS_WaitBinSem

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

Problem with OS_WaitBinSem

Postby carlgonz » Tue Dec 27, 2011 2:08 pm

I need start a task that send some telemetry (once) by rs232 only when recive some char by the UART module. So, I created a task, initially waiting for a binary semaphore and this semaphore is signaled by the ISR when a new char has been recived. The problem: when the char arrives the semaphore is signaled, then the task starts but it continues the execution ignoring the 'wait sema' instruction. ¿What is the problem? ¿Is it the correct behavior?

The code is the following:

Code: Select all
void _ISR _U1RXInterrupt(void)
{
    OSSignalBinSem(BINSEM_BUFFER_RS232);
    IFS0bits.U1RXIF = 0;
}   

void ReadCommand(void)
{
    static unsigned char read[]="READ_";
    while(1)
    {   
        OS_WaitBinSem(BINSEM_BUFFER_RS232,OSNO_TIMEOUT);
        LedE9_TOGGLE;
        SendRS232(read,5,M_UART1);
        //OS_Yield();
    }// END WHILE(1)
}


And as result, when I send a char, I receive: "READ_", "READ_, "READ_" ... forever, I mean, the task will never stop again.
Thanks and best regards!
Carlos G.
SUCHAI
carlgonz
 
Posts: 2
Joined: Mon Dec 12, 2011 8:58 am
Location: Santiago, Chile

Re: Problem with OS_WaitBinSem

Postby Andrew » Tue Dec 27, 2011 2:57 pm

1. You should always clear an interrupt flag as the first thing in the ISR ...

2. ReadCommand() has to be a task ... it cannot be a function.

Other than that, this looks OK. No need for OS_Yield() when OS_WaitBinSem() is present.

If the task is not "waiting", it means that the incoming characters at ISR_U1Rx are coming in faster than you are stripping them out via successful OS_WaitBinSems() ...

You could check for different behavior by using a semaphore instead of a binSem ...
Andrew
Site Admin
 
Posts: 68
Joined: Mon Nov 30, 2009 6:43 pm

Re: Problem with OS_WaitBinSem

Postby carlgonz » Tue Dec 27, 2011 6:41 pm

Thanks for the answer Andrew,

- Actually 'ReadCommand' is a task, and as first thing I do is initialize all events and task.
- The task really waits the semaphore but only the first time, then it continues active and running. Is it correct? It seems to me, that when the task checks for the sema condition again, the sema will be in 0, so the task will wait for a new SignalSem, rigth? But... it doesn't happen.
- The incoming characters aren't the problem becouse I have tried with individual sendings.
- I'll try another resource, like semaphore or messages.

My question basically is: what should be the correct behavior of this code?

In aditions, I'm working with a PIC24FJ256GA110 using the MPLAB C30 compiler.

Best regards!
Carlos G.
SUCHAI
carlgonz
 
Posts: 2
Joined: Mon Dec 12, 2011 8:58 am
Location: Santiago, Chile

Re: Problem with OS_WaitBinSem

Postby Andrew » Wed Dec 28, 2011 10:17 am

You asked
carlgonz wrote:My question basically is: what should be the correct behavior of this code?


and I (previously) wrote
Other than that, this looks OK. No need for OS_Yield() when OS_WaitBinSem() is present.


So yes, that is the correct code, and it will wait each time until the binary semaphore has been signaled.

Since the behavior you describe is not correct, there is some other issue in your code. I suspect a fault in your ISR.
Andrew
Site Admin
 
Posts: 68
Joined: Mon Nov 30, 2009 6:43 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 0 guests

cron