SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By sdisselhorst
#103261
What command will stop the ISR and return to the main loop?
By stevech
#103281
sdisselhorst wrote:What command will stop the ISR and return to the main loop?
In most dialects of C, you code nothing special. The compiler knows you declared the function as an ISR. It generates the correct code to restore used registers and pop the PC from the stack. Your ISR code must do the right thing to clear the interrupt cause, or there will be another immediate interrupt (a loop).
By sdisselhorst
#103335
What I needed was a way to stop the ISR before it reached the end. Thanks!
By stevech
#103458
sdisselhorst wrote:What I needed was a way to stop the ISR before it reached the end. Thanks!
use
Code: Select all

    if (condition)  {
       code here
    }
    else  {
       more code
    }
  }
} // end of ISR

just like you'd do in an ordinary function.
Using
Code: Select all
return;
at several places in the ISR is not good form.
By SFE-Nate
#106165
stevech wrote:Using
Code: Select all
return;
at several places in the ISR is not good form.
Why is that? Is that because return statements are effectively branch statements and you don't want to the program to get messy? Or is it something to do with processing time and how long you want to stay in the interrupt. Or did I totally miss the point.
By rrpilot
#106199
Its just a coding standard that people claim makes code more readable but I highly disagree and think multiply returns is far more easy to follow.
By Polux rsv
#106205
rrpilot wrote:Its just a coding standard that people claim makes code more readable but I highly disagree and think multiply returns is far more easy to follow.
Multiple return in many portion of code means:
- poor conception
- good conception but bad coding
- hard to debug
- hard to read for a majority of people
- impossible to modify without unwanted side effects.

Angelo
By rrpilot
#106211
- poor conception
- good conception but bad coding
- hard to debug
- hard to read for a majority of people
- impossible to modify without unwanted side effects.
If you get a coder that writes messy code you are going to have these issues regardless. Every instance that is necessary to bail out of the function your going to need to surround your code with if..then..else statements. Now all is fine and dandy when you only have 1 or 2 conditions but even 2 if..then..else blocks starts to get messy. In my opinion it all comes down to organizing your code and using comments to explain flow.

I don't mean to highjack this thread so I'll stop there, it just cheeses me off when people say that if you use multiple returns your code is bad.
By stevech
#106397
rrpilot wrote:
- poor conception
- good conception but bad coding
- hard to debug
- hard to read for a majority of people
- impossible to modify without unwanted side effects.
If you get a coder that writes messy code you are going to have these issues regardless. Every instance that is necessary to bail out of the function your going to need to surround your code with if..then..else statements. Now all is fine and dandy when you only have 1 or 2 conditions but even 2 if..then..else blocks starts to get messy. In my opinion it all comes down to organizing your code and using comments to explain flow.

I don't mean to highjack this thread so I'll stop there, it just cheeses me off when people say that if you use multiple returns your code is bad.
Multiple return() statements in one function makes code hard to debug. Quite like goto's. I use both, very sparingly. I prefer, in a deeply nested situation, to use a goto labelxx instead of a return(), as a rule. Usually the goto is due to an unexpected condition.