[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] generic queue library for AVR GCC?
From: |
E. Weddington |
Subject: |
Re: [avr-gcc-list] generic queue library for AVR GCC? |
Date: |
Mon, 15 Nov 2004 16:42:42 -0700 |
User-agent: |
Mozilla Thunderbird 0.7.3 (Windows/20040803) |
Rusty Wright wrote:
Eric, wouldn't it be safer to disable interrupts before you copy the
SREG? I.e., isn't it possible for an interrupt to occur between the
copy of SREG and the cli?
Yes, it's possible. But no, you don't want to disable interrupts before
saving SREG.
The whole point of saving SREG and restoring SREG is to restore the
state of global interrupts. Remember, when you clear global interrupts
(CLI) it changes a flag (bit) in the SREG register. This is why you want
to save the SREG register *before* doing the cli(). When you restore the
SREG register, you restore the state of the global interrupts after the
"critical section" is done, *regardless of whether the global interrupts
were enabled or disabled*.
For example, you do a critical section like:
cli();
// critical section
sei();
However, this enables global interrupts after the critical section. The
problem is: were global interrupts enabled, or disabled before the cli()
and the critical section? Saving and restoring the status register
handles both cases:
sreg = SREG;
cli();
// critical section
SREG = sreg;
It doesn't matter whether there is an interrupt between the sreg = SREG;
and the cli();. The point is that the state, no matter what it is, has
been preseved and subsequently restored.
Also, regarding the push/pop, most c compilers store local variables
on the stack so with your method you'll end up pushing and popping
anyhow.
You're absolutely right. I misspoke. My main point was really that one
does not have to do this in inline assembly, that it can be done just as
well in pure C.
Eric
PS, Don't forget to respond to the *list* and not just personally.
- Re: [avr-gcc-list] generic queue library for AVR GCC?, (continued)
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Bruce D. Lightner, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Andy Warner, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, rusty+avr-gcc-list, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Bruce D. Lightner, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Ben L. Titzer, 2004/11/17
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Ben L. Titzer, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, E. Weddington, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Ben L. Titzer, 2004/11/18
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Theodore A. Roth, 2004/11/17
- Message not available
- Re: [avr-gcc-list] generic queue library for AVR GCC?,
E. Weddington <=
- Re: [avr-gcc-list] generic queue library for AVR GCC?, rusty+avr-gcc-list, 2004/11/15
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Theodore A. Roth, 2004/11/15
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Bruce D. Lightner, 2004/11/15
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Theodore A. Roth, 2004/11/15
- Re: [avr-gcc-list] generic queue library for AVR GCC?, Geoffrey Wossum, 2004/11/16
Re: [avr-gcc-list] generic queue library for AVR GCC?, Dave Hansen, 2004/11/17