Compiler deleting code in isr.c

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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` */

}

0 Likes
1 Solution
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

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

pastedImage_0.png

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);

}

View solution in original post

0 Likes
3 Replies
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

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.

0 Likes
Panometric
Level 5
Level 5
100 sign-ins 100 replies posted 10 solutions authored

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());

    }

}

0 Likes
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

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

pastedImage_0.png

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);

}

0 Likes