avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] generic queue library for AVR GCC?


From: Geoffrey Wossum
Subject: Re: [avr-gcc-list] generic queue library for AVR GCC?
Date: Mon, 15 Nov 2004 23:03:18 -0600
User-agent: KMail/1.7.1

On Monday 15 November 2004 6:15 pm, Theodore A. Roth wrote:

> > *Just like Geoffrey's method*, my way also preserves the original
> > state of the interrupt flag, which may be essential, depending
> > upon the circumstance.
>
> Thanks for the clarification. I thought I was going nuts. ;-)

I knew ya'll would sort it out.  

I actually at one time used macros similar to Bruce's second set.  They looked 
something like:

#define enter_cs(_v)  do  { _v = SREG;  cli(); } while (0)
#define exit_cs(_v)  do { SREG = _v; } while (0)

To make a convoluted story short, I thought they were somehow broken at one 
point, and borrowed the critical sections out of NutOS.  Those didn't work 
any better, because my code was broken somewhere else.  However, I never 
switched back and kept using NutOS's.

I much prefer using some macros/inline functions rather than just saving SREG 
and restoring it inline.  Using the macros called enter_cs() and exit_cs() 
make it obvious to the next person who comes along that I was protecting 
access to a given data structure, even if they are not familiar with the AVR.

The NutOS routines, as Bruce pointed out, much more dangerous because if you 
don't balance them correctly -- crash!  On the other hand, it's sometimes 
nice to have a crash rather than odd behavior because your interrupts didn't 
get re-enabled like you intended.

---
Geoffrey Wossum
Long Range Systems - http://www.pager.net


reply via email to

[Prev in Thread] Current Thread [Next in Thread]