[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-libc-dev] Disable/Restore all Interrupts
From: |
Geoffrey Wossum |
Subject: |
Re: [avr-libc-dev] Disable/Restore all Interrupts |
Date: |
Fri, 5 Sep 2003 15:56:01 -0500 |
User-agent: |
KMail/1.5 |
On Friday 05 September 2003 10:22 am, E. Weddington wrote:
> And here's the debate:
> 1. It's faster to save all of SREG and then restore all of
> SREG.
> 2. However, when you restore all of SREG, you will
> overwrite all the other flags just to re-enable interrupts.
> Is this acceptable?
The macros that I use for critical sections save and restore all of SREG. In
the 150,000 or so lines of AVR code that I and another programmer here have
written, this has never been the "Wrong Thing" to do. I can imagine
circumstances where it is, but we've never created them. I imagine that it
is the right thing to do 99% of scenarios. If this weren't embedded stuff,
I'd say it would be 100%. But then we wouldn't be disabling and re-enabling
interrupts if this wasn't embedded stuff ^_^ Of course, in all the
situations that I can imagine saving and restoring SREG being the wrong thing
to do, I would hate to be a maintenance engineer on that code!
Going back earlier in this conversation, using sei() and cli() to create
critical sections is, of course, the Wrong Thing to do. Having macros in
avr-libc that do critical sections (push SREG / cli() and restore SREG) might
be nice, since anyone who needs them has to implement them theirselves, and
some beginners might not be savvy enough to know that using sei() and cli()
to implement critical sections is going to cause problems.
If critical section macros were to be added to avr-libc, one solution to the
SREG_I only vs. SREG debate would be to do both. By default, the CS macros
would save and restore all of SREG. By defining something like
AVR_CS_SREG_I_ONLY, the macros would then save only SREG_I.
---
Geoffrey Wossum
Software Engineer
Long Range Systems - http://www.pager.net