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.

About code safety in mutex problem

Hello

When I use the RTC timer interrupt.  I will write the code in interrup function.

Like this:

void rtc_secIntc(void)
{
    CSL_FINST(CSL_RTC_REGS->RTCINTFL, RTC_RTCINTFL_SECFL, SET);

    if (....)

        removeQueue();
}

and in the main function, like this

main()

{

    while(1)

     {

          if(.....)

                 updateQueue();

       }

}

When the program is executed in while{..},  RTC timer interrupted.  This is very dangerous.

But I don't know how to add mutex in my program.

And I want to know whether C55X support mutex lock?

Thanks

William Zhu

  • Hi,

    Your request is taken up and will provide an update as soon as possible.

    Thanks & regards,

    Sivaraj K

  • Mr. Zhu,

    Simply disable global interrupts around the shared resource access.  This can be done with EINT and DINT macros, which expand to:

    #define EINT()    asm(" BCLR INTM")

    #define DINT()    asm(" BSET INTM")

    alternatively you can use the IRQ_globalEnable and IRQ_globalDisable functions, at the cost of a function call.

    So, your main loop code would look like:

    DINT();

    updateQueue();

    EINT();

    Regards,

    Bill Finger

  • Hi Bill

    I have tried this method. The data can be protected.

    But I am not clear whether interrupt will be delayed or just discarded by system,  when interrup should happen.

    For example, when time is 15:01 the RTC interrupt should happen, but main function disable it, and after some work main function enable it.  I want to how the dsp process this situation,  recall it or discard.

    Why I ask this question?  Just because I worry that if we just use enable and disable for interrupt some interrupt will be lost.

    Do you think so?

    Regards

    William Zhu

  • William,

    When you disable global interrupts, no interrupts to the CPU occur, but the interrupt flags are still set when the interrupt condition occurs.  Then, when you re-enable global interrupts, the interrupts take place in priority order.

    So, the simple answer to your question is that interrupts are delayed, not lost.

    A more detailed answer is that you could lose interrupts, if two interrupts of the same kind happen while the interrupts are disabled, because the flag can only be set once.

    E.g., using your RTC example, if you have it set for 1 millisecond interrupts, and then you disable interrupts and do something that take 5 milliseconds, you are going to miss four RTC interrupts.

    In short, only disable interrupts when you really have to, and only for the shortest possible interval.

    Regards,

    Bill