[Top][All Lists]

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

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

From: Theodore A. Roth
Subject: Re: [avr-libc-dev] interrupt enable functions
Date: Wed, 7 Aug 2002 16:43:19 -0700 (PDT)

On Wed, 7 Aug 2002, E. Weddington 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. All you need to know is which macro to
use from the device specific header (iom128.h for example). That should be
enough to hide which bit to use, but you still need to know what you are

:) 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))

Magic numbers! Boo, hiss! :-)

:) These macros take care of a single source interrupt.
:) This could be taken a step further and the numbers for the bit values
:) could be gotten from the #defines in the processor-specific header
:) files (i.e. iom128.h, and for that matter these macros could be
:) placed in the processor-specific files.

And Joerg's interface using the #defines is essentially the same thing you
have done, but without all the extra work. ;-)

Also, Joerg's proposal could be tweaked to be just as efficient as the

reply via email to

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