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

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

[avr-gcc-list] Compiler macros and how to define them?


From: Alexander Rice
Subject: [avr-gcc-list] Compiler macros and how to define them?
Date: Mon, 16 Jul 2007 11:25:42 +0100
User-agent: Thunderbird 2.0.0.4 (Macintosh/20070604)

Hi all,

I'm just starting out with AVR micro controllers and the avr-gcc toolchain in the form of WinAVR.

As an exercise I thought I'd try defining my own function for setting up the hardware timers. In a header file I have:

------------

//Timer prescaler definitions
enum{   STOP = 0,
            CLK1 = 1;
            CLK8 = 2;
            CLK32 = 3;
            etc. } __clocksource;


void timer1_clocksource (int __clocksource)
//put the value from the prescaler definition into timer 1's SFR
{
      TCCR1B |=  __clocksource;
}
-----------

This works, however a look at the .lst file seems to suggest that 'clocksource' and the function 'timer1_clocksource' are actually defined in the compiled code.

My question is: what must I do to ensure that the the variable '__clocksource' behaves like a #define statement and the function 'timer1_clocksource' is inlined?

Also, from looking at the math.h library routines I have gathered that the convention seems to be to use two underscore characters for variables defined in header files. Are there any other conventions I should be aware of; or better, a coding style guide for header files?

Setting up timers is a common and somewhat laborious task requiring repeated reference to the datasheet, it would be nice to have a library routine that made things easier. By wrapping some functions similar to the above in some #if defined (__AVR_ATmega32__) etc. statements to deal with specific devices it would seem to be fairly simple, so simple in fact that if I got it working nicely I could contribute it back to the project.

Regards

Alex





reply via email to

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