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.

CCS/TMS320F28379D: Function timeout

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

Hello there
I am using TMS28F379D. I am currently setting up the SCI infrastructure. But I have a problem. I am currently using the SCI_readCharArray and SCI_writeCharArray functions together with the interrupt. But these functions block code that if don't receive this data . I want to pass the this function after certain time. How can I do this?

Thank you answer...

  • Hello,

    Thanks for your question! To answer, if your application requires polling, you could make your own "new" version of SCI_readCharArray, which adds another check to the while loop in the function. In particular, you would need to modify this while loop here:

    //
    // Wait until a character is available in the receive FIFO.
    //
    while(SCI_getRxFIFOStatus(base) == SCI_FIFO_RX0) // <- add another check here (&&) to check for a timer reaching a certain value (that you choose)
    {
    }
    

    You will have to make your own timer function for this. See C2000Ware example "timer_ex1_cputimers.c" in C2000Ware_version#\driverlib\f2837xd\examples\cpu1\timer\ and chapter 3.8 of the Technical Reference Manual for details on how to make a timer.

    If you are able to use interrupts instead of polling, I would recommend to instead use interrupts (see the example "sci_ex2_loopback_interrupts.c" in C2000Ware for implementing interrupts). This would avoid the need for a timeout on the communications (preventing the blocking call), and a timeout can still be implemented if needed with a timer.

    Let me know if that answers your question!

    Regards,

    Vince

  • Hello 

    Thanks for your answer! I have created a structure in my mind.But there's a point I don't understand. I am currently building a private SCI infrastructure for myself.I collected all SCI structures into header files by making them modular.I only use one of these header files for SCI interrupts. I am currently receiving data with interrupts, but at this point the device always enters while loop that  awaits data. I wanted to set a timeout from that. So I want it to exit the while structure used to wait for data after a certain period of time. If I use the timer structure, can I just exit the function without resetting the device? Or can I use the interrupt structure differently?

    Thank you in advance for your answer !!! 

  • Hello,

    Thanks for the clarification! The way to do this with interrupts is to instead only call the "SCI_readCharArray" function inside the interrupt function. This way, the function (where your code is getting stuck in a while loop) will not get stuck. This should also avoid the need for a timeout at all. I would recommend tying out the example "sci_ex2_loopback_interrupts.c" (C2000Ware location mentioned in the previous post), as this would give a good example of the interrupt working (and show that the code won't hang at the while loop). Let me know if you are instead implementing this as an "edge-case" handler or for another reason!

    And let me know if that example helps avoid the infinite while loop (and allows you to not need a timeout)!

    Regards,

    Vince

  • Hello

    Thanks for your answer! As you can see in the picture below, I used the code structure in the example you have say.

    But the structure you are talking about is waiting for a certain amount of data. Initially the loop size of the for loop is given as the input parameter to the function. If the device receives less data than this amount, it is blocked by entering the while loop.

    Normally, a certain amount of data should be received, but when a malfunction occurs, it can cause the device to crash.That's why I want to set a timeout so that in case of a glitch, the device can exit without locking.

     

  • Hello,

    Awesome, thanks for the follow up. That makes sense for the reasoning behind it then! In this case, then using interrupt or polling will be equivalent, as you are wanting to handle potential malfunctions in the code.

    In summary, you will need a timeout, and to do so, you will have to change the circled while statement as I mentioned in the first post (clarified below for more detail):

    // you will have to implement a start timeout function using
    // the timer example in C2000Ware. 
    start_timeout_function(...)
    {
        // FILL THIS OUT TO START THE TIMER AND RESET EVERYTHING
        // SEE C2000Ware example for how to do this
    }
    // Then in the interrupt for the timer, you  will change a global variable 
    // (called timeout_variable) to be nonzero.
    // For example:
    __interrupt void
    cpuTimer0ISR(void)
    {
        //...
        // SET UP THE REST OF THE ISR BEFORE THIS
        
        timeout_variable = 1; //or whatever error code you would like to throw
        
        // SET UP THE REST OF THE ISR AFTER THIS
        //...
    }
    
    // start the timer before the wait statement
    start_timeout_function()
    //
    // As soon as there is data -OR- the timeout limit was passed, then exit the
    // loop
    //
    while(SCI_getRxFIFOStatus(base) == SCI_FIFO_RX0 && timeout_variable == 0)
    {
    }

    By doing the above, you will be able to implement a timeout to the interrupt in case of a malfunction!

    Let me know if you have any follow up questions!

    Regards,

    Vince

  • Thank you for your answer. My problem has been resolved.