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.

TMS570LS0432: Can interrupt function of the cpu break the running assembly language?

Part Number: TMS570LS0432

Hello

 Team

 If a global variable is Assignment operating in the main function,the interrupt break that,so this variable is risky

I want to know the cpu ,if can break the code “   A=0X32”?  

  • If you use a global variable in your function (not a ISR) and in an interrupt ISR. You need to mask the interrupt when writing to this global variable in your function.

    If you are modifying a global variable within an interrupt routine and reading it elsewhere, please declare the the variable as volatile

  • Thank you

    If you use a global variable in your function (not a ISR) and in an interrupt ISR. You need to mask the interrupt when writing to this global variable in your function.

    Yes  I need to read and write global variable in function and an interrupt ISR.Now I write some function read function and write function for global variable write and read in (XXX.C).Can this be avoided?because if mask the interrupt may affect system stability.

    Dose The TMS570 cpu’s interrupt can beak an assembly instruction?

  • Hi Whong,

    The ARM assembly instruction can be interrupted by the exception (IRQ, FIQ, SVC, abort,..). I knew that using a global flag is one way of communicating from the ISR but you should be careful of race conditions between the two. You need to disable the INT or implement mutex for writing the global variable in your function (for example main()). 

    volatile char gcFlag;

    int main(void)

    {

        // Initialise global variables in case of reset

        gcFlag = 0;

        while(1)

        {

             if (gcFlag) {

                // you may need to implement some kind of mutex here, or disable

                // interrupts until you have finished. 

               gcFlag = 0;

               ….

            }

            ….

      }
     
    ISR()
    {
         gcFlag = 1;
         ….
     }
     

  • Hello

    Based on your code

    A.C

    static uint8_t gcFlag;

    ISR()
    {
         gcFlag = 1;
         ….
     }
    uint8_t read()
    {
    return gcFlag
    }
    uint8_t set(uint8_t  value)
    {
    gcFlag=value
    }

    main.C

    int main(void)

    {

        // Initialise global variables in case of reset

       

    set(0)

    ;

        while(1)

        {

             if (read())


    {

                // you may need to implement some kind of mutex here, or disable

                // interrupts until you have finished. 

               set(0)

    ;

               ….

            }

            ….

      }

    Now I want to use this way for the program.Is it ok, what will happen.
    some cpu when run a assembly instruction,An instruction,the IRQ, can not break the
    instruction,After executing this instruction,that into the interrupt function
     
  • Hi,

    You need to disable the interrupt before calling set(0) in main(), or you call call set(0) before enabling the interrupt during the system powering-up. After that, this global variable should be written only in the ISR.