avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] interrupt enable functions


From: Joerg Wunsch
Subject: Re: [avr-libc-dev] interrupt enable functions
Date: Thu, 8 Aug 2002 12:33:38 +0200
User-agent: Mutt/1.2.5i

As E. Weddington wrote:

> As a counter example, it would require a bit more effort but could be 
> implemented in macros:
> 
> // Example for ATmega128
> #define timer_1_IC_interrupt_enable()         (TIMSK |= BV(5))
> #define timer_1_IC_interrupt_disable()        (TIMSK &= ~BV(5))
> #define timer_1_OCA_interrupt_enable()        (TIMSK |= BV(4))
> #define timer_1_OCA_interrupt_disable()       (TIMSK &= ~BV(4))
> #define timer_1_OCB_interrupt_enable()        (TIMSK |= BV(3))
> #define timer_1_OCB_interrupt_disable() (TIMSK &= ~BV(3))

What i don't like with this is the namespace pollution resulting
from it.

Btw., how do other AVR compilers solve this?

Thinking more about it, it's probably best to leave them entirely
away.  If some old code still relies on it, we could perhaps
invent an <avr/compat.h> documenting the obsolete features.  Would
be a good place to also include a #warning statement. ;-)

> Also this brings up another question, in your example Joerg, you do 
> direct-assignment to the registers. I prefer that as well, using the 
> "new headers" from Chris Morse and Don Carveth. This method is used 
> frequently in other cross-compilers (at least on Windows). How about 
> deprecating the io macros? The compiled output is the same for direct-
> assignment vs. macros, and the assignment is easier to read and 
> understand. See the file newhdrs.txt from the above authors for 
> discussion.

Where's that document to be found?

Yes, i'd also prefer that new functionality, but it needs to be
explained in the docs.

As Theodore A. Roth wrote:

> :) However, in the example above, the programmer is still required to
> :) know the structure of the TIMSK register and ensure that s/he is
> :) setting the correct bit.
> 
> I don't think you can escape this.

Me neither.  Btw., the timer bit macros are matching the AVR
documentation which you clearly need anyway.

> :) #define timer_1_IC_interrupt_enable()              (TIMSK |= BV(5))

> Magic numbers! Boo, hiss! :-)

And instead of cryptic timer bit names, you gotta learn cryptic
interrupt enable function names. :)

> First, I think that you should be using _BV() instead of the deprecated (I
> believe) BV(). That's an off topic nit though.

Hmm, i didn't know BV() was deprecated.  Sure, its name is in the
application namespace, but we've got so many other macro names that
pollute the application namespace so that could hardly be an
argument.

All the other macros with leading underscores (like __inw etc.) have
even been removed now, why do we want to make the people move from
BV() to _BV() then?  I can't quite follow this.

> I vaguely remember Marek telling me that some things like this are only in
> there to be used as examples. The documentation should probably say that
> this is an example, note the flaw in it and leave it at that.

Hmm.  Then we should IMHO add examples files instead.  I noticed
doxygen has some support for it (i. e., it can suck in an entire
external file).  I can provide the simple-demo.c that has been
written for Rich's document (a simple PWM ramp-up ramp-down LED
control), as well as my more advanced demo.c based on it (it
basically makes the PWM controllable by a few switches, a
potentiometer, and even by RS-232 commands).

-- 
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/



reply via email to

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