Skip to main content
Arduino

Timeline for Breaking a switch case from an ISR

Current License: CC BY-SA 3.0

9 events
when toggle format what by license comment
Apr 16, 2016 at 8:07 vote accept makepeace
Apr 15, 2016 at 10:13 comment added Edgar Bonet @JRobert: I fully agree with you. I posted this because I think it's a fun hack worth sharing. I already stated in the answer I do not consider this a clean programming technique. I just expanded on that consideration, just in case it was not already extra clear.
Apr 15, 2016 at 10:13 history edited Edgar Bonet CC BY-SA 3.0
Addendum about the clean solution: no busy waits.
Apr 14, 2016 at 23:53 comment added JRobert Longjmp restores the context as it was at the setjmp call. It may be; I just don't know. It sounds like you had similar concerns in your caveat to inspect the assembly code and to test carefully. It's quite possible it will work as expected/desired. On the other hand, allowing the ISR to return first gives me a lot more confidence in the outcome.
Apr 14, 2016 at 18:41 history edited Edgar Bonet CC BY-SA 3.0
No need to sei(), as longjmp() restores SREG.
Apr 14, 2016 at 18:33 comment added Edgar Bonet @JRobert: "longjmp() may return to the mainline but with the ISR's context" I don't understand what you mean by "ISR context". setjmp() and longjmp() save and restore quite a bit of context, including all the call-saved registers and the stack pointer.
Apr 14, 2016 at 17:39 comment added JRobert ... You'll probably want to abstract away as much of the case code as possible into small functions where the actual work and the flag-testing will be done. This way, both setjmp() and longjmp() will have (had) the same context.
Apr 14, 2016 at 17:39 comment added JRobert I think longjmp() may return to the mainline but with the ISR's context; I'd expect some surprising behavior. But if you call setjmp() prior to the switch statement (or higher, if appropriate), and the ISR sets a (volatile!) flag to indicate it has been called, then each case could do if( flag ) longjmp(); as frequently as it is appropriate to do without leaving some operation partially completed. ...
Apr 14, 2016 at 16:01 history answered Edgar Bonet CC BY-SA 3.0

AltStyle によって変換されたページ (->オリジナル) /