3 Replies Latest reply on Aug 16, 2018 7:52 PM by LinglingG_46

    Compiler deleting code in isr.c

    augo_1321816

      Hi all,

      Im having the strangest problem with the Compiler removing my code in ISR.c. It only happens when you change the hardware layer, just software rebuild doesnt do it.

      Before anyone asks, The code is squarely within the "Place user code here" statements... Has anyone else seen this?

       

       

      ISR code below:

       

      CY_ISR(isr_switch_Interrupt)

      {

          #ifdef isr_switch_INTERRUPT_INTERRUPT_CALLBACK

              isr_switch_Interrupt_InterruptCallback();

          #endif /* isr_switch_INTERRUPT_INTERRUPT_CALLBACK */

       

       

          /*  Place your Interrupt code here. */

       

       

          /* `#START isr_switch_Interrupt` */

          isr_switch_ClearPending();

          int cmp=0;

          cmp = PWM_ReadCompare();

         

         

          if (cmp == 100)

          {

              PWM_WriteCompare(150);

              LED_REG_Write(!LED_REG_Read());

          }

          else if (cmp == 150)

          {

              PWM_WriteCompare(200);

              LED_REG_Write(!LED_REG_Read());

          }

          else if (cmp == 200)

          {

              PWM_WriteCompare(100);

              LED_REG_Write(!LED_REG_Read());

          }

          /* `#END` */

      }

        • 1. Re: Compiler deleting code in isr.c
          LinglingG_46

          Can you clarify that how you change the hardware layer?

          If you don't process "isr_switch_Interrupt", I think the code you said will not be changed.

          In addition, whether you can reproduce this problem in a high probability, please attached your test project here and tell us which version of the creator you use.

          • 2. Re: Compiler deleting code in isr.c
            mimi_1891471

            If your isr.c is in the generated code directory, my experience is that it is unreliable about preserving it. IF you are very careful and don't mess up the comment blocks, it usually works, but not always. It also means you are committing allot of generated files to version control which is messy.   A better practice is to define the variable and function by the same name. So instead of inserting between the comments, you would, in your own file:

             

            #define isr_switch_INTERRUPT_INTERRUPT_CALLBACK

            void isr_switch_Interrupt_InterruptCallback()

            {

                isr_switch_ClearPending();

                int cmp = 0;

                cmp = PWM_ReadCompare();

                if (cmp == 100)

                {

                    PWM_WriteCompare(150);

                    LED_REG_Write(!LED_REG_Read());

                }

                else if (cmp == 150)

                {

                    PWM_WriteCompare(200);

                    LED_REG_Write(!LED_REG_Read());

                }

                else if (cmp == 200)

                {

                    PWM_WriteCompare(100);

                    LED_REG_Write(!LED_REG_Read());

                }

            }

            • 3. Re: Compiler deleting code in isr.c
              LinglingG_46

              You can  do " #define isr_switch_INTERRUPT_INTERRUPT_CALLBACK" in the project Header Files ->cyapicallback.h

              And in the main.c, call  "isr_switch_start();" to start the interrupt.

               

              In addition to: You can use the "void Isr_TC_StartEx(cyisraddress address);" to refine the interrupt handle API.

              Like:

                  isr_switch_StartEx(Isr_TC_Handler);

               

               

               

              CY_ISR(Isr_TC_Handler)

              {  

              // /* Clear the TC Interrupt */

              //    PWM_ClearInterrupt(PWM_INTR_MASK_TC);

              //   

              //    /* Decrement the PWM Compare value to increase the LED brightness */

              //    PWM_WriteCompare(PWM_ReadCompare() - BRIGHTNESS_CHANGE);

              }