timer_xmega.h
Go to the documentation of this file.00001
00045 #ifndef DRV_TIMER_XMEGA_H
00046 #define DRV_TIMER_XMEGA_H
00047
00048 #include <hw/hw_cpufreq.h>
00049
00050 #include "cfg/cfg_timer.h"
00051 #include <cfg/compiler.h>
00052 #include <cfg/macros.h>
00053
00054 #include <avr/io.h>
00055 #include <avr/interrupt.h>
00056
00057
00058
00059
00060
00061
00062
00063 #define TIMER_USE_TCC0 1
00064 #define TIMER_USE_TCC1 2
00065 #define TIMER_USE_TCD0 3
00066 #define TIMER_USE_TCE0 4
00067
00068 #ifdef CPU_AVR_XMEGA_A
00069 #define TIMER_USE_TCD1 5
00070 #endif
00071
00072 #define TIMER_DEFAULT TIMER_USE_TCC1 ///< Default system timer
00073
00074
00075
00076
00077 #if (CONFIG_TIMER == TIMER_USE_TCC0)
00078 #define TIMER_OVF_VECT TCC0_OVF_vect
00079 #define TIMERCOUNTER TCC0
00080 #elif (CONFIG_TIMER == TIMER_USE_TCC1)
00081 #define TIMER_OVF_VECT TCC1_OVF_vect
00082 #define TIMERCOUNTER TCC1
00083 #elif (CONFIG_TIMER == TIMER_USE_TCD0)
00084 #define TIMER_OVF_VECT TCD0_OVF_vect
00085 #define TIMERCOUNTER TCD0
00086 #elif (CONFIG_TIMER == TIMER_USE_TCE0)
00087 #define TIMER_OVF_VECT TCE0_OVF_vect
00088 #define TIMERCOUNTER TCE0
00089 #elif (CONFIG_TIMER == TIMER_USE_TCD1)
00090 #define TIMER_OVF_VECT TCD1_OVF_vect
00091 #define TIMERCOUNTER TCD1
00092 #else
00093 #error Unimplemented value for CONFIG_TIMER
00094 #endif
00095
00096
00097 #define DEFINE_TIMER_ISR DECLARE_ISR_CONTEXT_SWITCH(TIMER_OVF_VECT)
00098
00099 #define TIMER_TICKS_PER_SEC 1000
00100
00101
00102
00103
00104
00105 #define TIMER_PRESCALER 1
00106
00107 #define TIMER_PERIOD_VALUE DIV_ROUND(DIV_ROUND(CPU_FREQ, TIMER_PRESCALER), TIMER_TICKS_PER_SEC)
00108
00109 #if TIMER_PERIOD_VALUE > 0xFFFF
00110 #error Timer cannot generate the required Ticks per second, please adjust TIMER_PRESCALER
00111 #endif
00112
00113 #define TIMER_HW_CNT TIMER_PERIOD_VALUE
00114
00115 #define TIMER_HW_HPTICKS_PER_SEC DIV_ROUND(CPU_FREQ, TIMER_PRESCALER)
00116
00117
00118 typedef uint16_t hptime_t;
00119 #define SIZEOF_HPTIME_T 2
00120
00121 INLINE hptime_t timer_hw_hpread(void)
00122 {
00123 return (TIMERCOUNTER).CNT;
00124 }
00125
00126
00127 #define timer_hw_irq() do {} while (0)
00128
00129
00130 #define timer_hw_triggered() (true)
00131
00132 void timer_hw_init(void);
00133
00134 #endif