This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Switch Statement in ISR

Hello everyone,

I am using the PGA400 from Texas Instruments (an 8051W processor) with uVision V4.02 and have traced an issue back to using a switch statement in the commBuff ISR. It appears to either have corrupted or overflowed some sort of variable (this might not be the case but that's what it appears to have done). I've replaced it from:

        switch (CommandState)
        {
                case (0):
// random code here
                break;
        }

to:

        if(CommandState==0)
        {
// random code here
        }

This seems to have fixed my problem for whatever reason. Is it a common practice to avoid using switch statements in an ISR or is this a Keil related issue? Any help you can give me would be appreciated. Thanks a lot!

Parents
  • It isn't uncommon with switch statements in an ISR, to decide which of sevaral actions to perform, depending on the reason for the interrupt.

    Some hardware devices have a bit field where each bit represents an action that the device (may) need serviced. This means that the ISR may have to look at multiple flags, and perform multiple tasks - so bad mapping to a switch statement.

    But some other devices instead have a numeric value informing about the reason for the interrupt. In this case, the switch statement represents an excellent design construct to route the processor to the specific action to perform.

Reply
  • It isn't uncommon with switch statements in an ISR, to decide which of sevaral actions to perform, depending on the reason for the interrupt.

    Some hardware devices have a bit field where each bit represents an action that the device (may) need serviced. This means that the ISR may have to look at multiple flags, and perform multiple tasks - so bad mapping to a switch statement.

    But some other devices instead have a numeric value informing about the reason for the interrupt. In this case, the switch statement represents an excellent design construct to route the processor to the specific action to perform.

Children
No data