timer_avr.h

Go to the documentation of this file.
00001 
00042 /*#*
00043  *#* $Log$
00044  *#* Revision 1.32  2007/10/08 12:14:32  batt
00045  *#* Fix some review issues.
00046  *#*
00047  *#* Revision 1.31  2007/10/07 12:30:55  batt
00048  *#* Add default timer for AVR.
00049  *#*
00050  *#* Revision 1.30  2007/06/07 14:35:12  batt
00051  *#* Merge from project_ks.
00052  *#*
00053  *#* Revision 1.29  2007/03/21 11:01:36  batt
00054  *#* Add missing support for ATMega1281.
00055  *#*
00056  *#* Revision 1.28  2006/07/19 12:56:26  bernie
00057  *#* Convert to new Doxygen style.
00058  *#*
00059  *#* Revision 1.27  2006/05/18 00:38:24  bernie
00060  *#* Use hw_cpu.h instead of ubiquitous hw.h.
00061  *#*
00062  *#* Revision 1.26  2006/02/21 21:28:02  bernie
00063  *#* New time handling based on TIMER_TICKS_PER_SEC to support slow timers with ticks longer than 1ms.
00064  *#*
00065  *#* Revision 1.25  2005/07/19 07:26:37  bernie
00066  *#* Refactor to decouple timer ticks from milliseconds.
00067  *#*
00068  *#* Revision 1.24  2005/04/11 19:10:28  bernie
00069  *#* Include top-level headers from cfg/ subdir.
00070  *#*
00071  *#* Revision 1.23  2005/03/01 23:24:51  bernie
00072  *#* Tweaks for avr-libc 1.2.x.
00073  *#*
00074  *#* Revision 1.21  2004/12/13 12:07:06  bernie
00075  *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE.
00076  *#*
00077  *#* Revision 1.20  2004/11/16 20:59:46  bernie
00078  *#* Include <avr/io.h> explicitly.
00079  *#*
00080  *#* Revision 1.19  2004/10/19 08:56:41  bernie
00081  *#* TIMER_STROBE_ON, TIMER_STROBE_OFF, TIMER_STROBE_INIT: Move from timer_avr.h to timer.h, where they really belong.
00082  *#*
00083  *#* Revision 1.18  2004/09/20 03:31:03  bernie
00084  *#* Fix racy racy code.
00085  *#*/
00086 #ifndef DRV_TIMER_AVR_H
00087 #define DRV_TIMER_AVR_H
00088 
00089 #include <appconfig.h>     /* CONFIG_TIMER */
00090 #include <cfg/compiler.h>  /* uint8_t */
00091 #include <cfg/macros.h>    /* DIV_ROUND */
00092 #include <hw_cpu.h>        /* CLOCK_FREQ */
00093 
00102 #define TIMER_ON_OUTPUT_COMPARE0  1
00103 #define TIMER_ON_OVERFLOW1        2
00104 #define TIMER_ON_OUTPUT_COMPARE2  3
00105 #define TIMER_ON_OVERFLOW3        4
00106 
00107 #define TIMER_DEFAULT TIMER_ON_OUTPUT_COMPARE0 
00108 /* \} */
00109 
00110 /*
00111  * Hardware dependent timer initialization.
00112  */
00113 #if (CONFIG_TIMER == TIMER_ON_OUTPUT_COMPARE0)
00114 
00115     #define TIMER_PRESCALER      64
00116     #define TIMER_HW_BITS        8
00117     #define DEFINE_TIMER_ISR     SIGNAL(SIG_OUTPUT_COMPARE0)
00118     #define TIMER_TICKS_PER_SEC  1000
00119     #define TIMER_HW_CNT         OCR_DIVISOR
00120 
00122     typedef uint8_t hptime_t;
00123 
00124 #elif (CONFIG_TIMER == TIMER_ON_OVERFLOW1)
00125 
00126     #define TIMER_PRESCALER      1
00127     #define TIMER_HW_BITS        8
00128 
00129     #define TIMER_HW_CNT         (1 << TIMER_HW_BITS)
00130     #define DEFINE_TIMER_ISR     SIGNAL(SIG_OVERFLOW1)
00131     #define TIMER_TICKS_PER_SEC  DIV_ROUND(TIMER_HW_HPTICKS_PER_SEC, TIMER_HW_CNT)
00132 
00134     typedef uint16_t hptime_t;
00135 
00136 #elif (CONFIG_TIMER == TIMER_ON_OUTPUT_COMPARE2)
00137 
00138     #define TIMER_PRESCALER      64
00139     #define TIMER_HW_BITS        8
00140     #if CPU_AVR_ATMEGA1281 || CPU_AVR_ATMEGA168
00141         #define DEFINE_TIMER_ISR     SIGNAL(SIG_OUTPUT_COMPARE2A)
00142     #else
00143         #define DEFINE_TIMER_ISR     SIGNAL(SIG_OUTPUT_COMPARE2)
00144     #endif
00145     #define TIMER_TICKS_PER_SEC  1000
00146 
00147     #define TIMER_HW_CNT         OCR_DIVISOR
00148 
00149 
00151     typedef uint8_t hptime_t;
00152 
00153 #elif (CONFIG_TIMER == TIMER_ON_OVERFLOW3)
00154 
00155     #define TIMER_PRESCALER      1
00156     #define TIMER_HW_BITS        8
00157 
00158     #define TIMER_HW_CNT         (1 << TIMER_HW_BITS)
00159     #define DEFINE_TIMER_ISR     SIGNAL(SIG_OVERFLOW3)
00160     #define TIMER_TICKS_PER_SEC  DIV_ROUND(TIMER_HW_HPTICKS_PER_SEC, TIMER_HW_CNT)
00161 
00163     typedef uint16_t hptime_t;
00164 #else
00165 
00166     #error Unimplemented value for CONFIG_TIMER
00167 #endif /* CONFIG_TIMER */
00168 
00169 
00171 #define TIMER_HW_HPTICKS_PER_SEC  DIV_ROUND(CLOCK_FREQ, TIMER_PRESCALER)
00172 
00177 #define OCR_DIVISOR  (DIV_ROUND(DIV_ROUND(CLOCK_FREQ, TIMER_PRESCALER), TIMER_TICKS_PER_SEC) - 1)
00178 
00180 #define timer_hw_irq() do {} while (0)
00181 
00183 #define timer_hw_triggered() (true)
00184 
00185 
00186 #endif /* DRV_TIMER_AVR_H */