timer_avr.h
Go to the documentation of this file.00001
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #ifndef DRV_TIMER_AVR_H
00087 #define DRV_TIMER_AVR_H
00088
00089 #include <appconfig.h>
00090 #include <cfg/compiler.h>
00091 #include <cfg/macros.h>
00092 #include <hw_cpu.h>
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
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
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