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.

Reentrant function in SYSBIOS??

Other Parts Discussed in Thread: TMS320C6746, SYSBIOS

Hi all,

currently i am working on TMS320C6746 with CCSv5 IDE. can i use single function in all the tasks. all the functions by default reentrant in SYSBIOS??

  • MSR,

    SYS/BIOS APIs are documented as to which context they may be used. For example, you shouldn't use a Sempahore_pend() within a Hwi.

    Unless noted otherwise in the API documentation, they should be reentrant.

  • for example i have written string copy function, can i call this function from all the tasks, swi, hwi. please explain me if am wrong..

  • MSR,

    it really depends on the nature on who owns the memory that your operating on.

    Variables declared within a Task context are stored on the Task stack and will be reentrant. If variables are globally defined and shared between Tasks, you will probably need some sort of lock around the variable (or the function call) to keep it reentant.

    The type of lock you need; depends on the context that the memory will be shared with. If a Hwi can modify a variable that also gets modified within a Task/Swi, then you'll need a Hwi lock in the Task or Swi. If only a Swi and Task access that variable, then a Swi lock would probably be sufficient.

    If you used memory that you allocated from the heap (e.g. Memmory_alloc(); a call which is reentrant), then your task also owns that memory and therefore is reentrant. If the memory allocated is shared between tasks, swis and hwis, then again a lock will be needed.

    Within the TI's runtime support library we also put in a lock around cricital code sections. (spnu151i.pdf section 7.3) The generally applied to function calls such as malloc() and free().

    I hope this helps.

  • it means if i declare more stack for each task i can call single function from multiple tasks..??

  • No.

    Variables declared in the function will be allocated in the Task's stack and aren't accessible by other tasks. Increaseing the stack size doesn't make a call to a function reentrant. The example below might help.

    // Global variable
    Int needAlockTotalSumVar;

    Void add(UInt x, UInt y)
    {
        // Variable allocated on the Task's stack

        Int reentranceVar;

        // This variable is static variable, so the same instance is always used.
        static UInt anotherNeedAlockVariable;

        // No lock needed as the variable is stored on the Task's stack
        reentranceVar = x;

        reentranceVar += y;

        // Variable is shared between tasks. Each time add() is called, it
        // sums up the total.
        key = Hwi_disable();

        needAlockTotalSumVar += reentranceVar;
        anotherNeedAlockVariable += reentranceVar;

        Hwi_restore(key);

        return(reentranceVar);
    }

    Void Task0(UArg...)
    {
        add(1, 2);
    }

    Void Task1(UArg...)
    {
        add(5, 6);
    }

  • thanks for your information Tom Kopriva.