This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Understanding Event_pend Timeout

Hello,

I´m trying to use the Event_pend() function as a timer-watchdog so everytime my Receive_Task successes to receive data, it posts an event RXTIMEOUT which tells my Timeout_Task that reception is working properly. The idea is that if something happens and my Receive_Task stops posting the event within an interval of 100ms, then the Timeout_Task resets the reception buffer.

It sounds clear to me but unfortunatelly it´s not working. What am I doing wrong?

Info: SYS/BIOS 6.40.01.15, TI-RTOS 2.1.0.03, Clock.tickPeriod = 1000 us;

 

Thanks!


USBCDC_handleDataReceived (uint8_t intfNum)() //USB-API { semaphore_post(sem1) //Every time data is received sem1 is posted }

//priority = 3 Task_Receive() { semaphore_pend(sem1); ReceiveData(Buffer); ProcessData(Buffer); Event_post(RXTIMEOUT); SendData(ResponseBuffer); } Task_Timeout() //priority = 5 { timeout = 100; if(Event_pend(RXTIMEOUT, timeout) == 0) ResetBuffer(Buffer); }

  • If I take your code literally, the problem is that there is no loop in either of the task functions. Each function will execute only once and then fall through the bottom, causing the task to terminate.

    I suggest this for Task_Receive():

    Task_Receive()
    {
        while (1) {
            semaphore_pend(sem1);
            ReceiveData(Buffer);
            ProcessData(Buffer);
            Event_post(RXTIMEOUT);
    
            SendData(ResponseBuffer);
        }
    }


    And this for Task_Timeout():

    Task_Timeout() //priority = 5
    {
        timeout = 100;
        while (1) {
            if(Event_pend(RXTIMEOUT, timeout) == 0)
                 ResetBuffer(Buffer);
        }
    }
  • Ops I forgot to type in here the while loops, yo are right.
    I had the loops in my actual code. By chance I just found the problem and in fact it had to do with the while(1) loops. It was something really silly... I had a break statement after my call to the function ResetBuffer(..); so after the first Reset the while was broken and there was no loop anymore. Thanks for the suggestion though!

    Task_Timeout() //priority = 5
    {
       timeout = 100;
       while (1) 
    { if(Event_pend(RXTIMEOUT, timeout) == 0) { ResetBuffer(Buffer); break; // <-------- THE PROBLEM WAS THIS } }

    }