timer_avr.h
Go to the documentation of this file.00001
00043 #ifndef DRV_TIMER_AVR_H
00044 #define DRV_TIMER_AVR_H
00045
00046 #include "hw/hw_cpu.h"
00047
00048 #include "cfg/cfg_timer.h"
00049 #include <cfg/compiler.h>
00050 #include <cfg/macros.h>
00051
00052
00061 #define TIMER_ON_OUTPUT_COMPARE0 1
00062 #define TIMER_ON_OVERFLOW1 2
00063 #define TIMER_ON_OUTPUT_COMPARE2 3
00064 #define TIMER_ON_OVERFLOW3 4
00065
00066 #define TIMER_DEFAULT TIMER_ON_OUTPUT_COMPARE0
00067
00068
00069
00070
00071
00072 #if (CONFIG_TIMER == TIMER_ON_OUTPUT_COMPARE0)
00073
00074 #define TIMER_PRESCALER 64
00075 #define TIMER_HW_BITS 8
00076 #define DEFINE_TIMER_ISR SIGNAL(SIG_OUTPUT_COMPARE0)
00077 #define TIMER_TICKS_PER_SEC 1000
00078 #define TIMER_HW_CNT OCR_DIVISOR
00079
00081 typedef uint8_t hptime_t;
00082
00083 #elif (CONFIG_TIMER == TIMER_ON_OVERFLOW1)
00084
00085 #define TIMER_PRESCALER 1
00086 #define TIMER_HW_BITS 8
00087
00088 #define TIMER_HW_CNT (1 << TIMER_HW_BITS)
00089 #define DEFINE_TIMER_ISR SIGNAL(SIG_OVERFLOW1)
00090 #define TIMER_TICKS_PER_SEC DIV_ROUND(TIMER_HW_HPTICKS_PER_SEC, TIMER_HW_CNT)
00091
00093 typedef uint16_t hptime_t;
00094
00095 #elif (CONFIG_TIMER == TIMER_ON_OUTPUT_COMPARE2)
00096
00097 #define TIMER_PRESCALER 64
00098 #define TIMER_HW_BITS 8
00099 #if CPU_AVR_ATMEGA1281 || CPU_AVR_ATMEGA168
00100 #define DEFINE_TIMER_ISR SIGNAL(SIG_OUTPUT_COMPARE2A)
00101 #else
00102 #define DEFINE_TIMER_ISR SIGNAL(SIG_OUTPUT_COMPARE2)
00103 #endif
00104 #define TIMER_TICKS_PER_SEC 1000
00105
00106 #define TIMER_HW_CNT OCR_DIVISOR
00107
00108
00110 typedef uint8_t hptime_t;
00111
00112 #elif (CONFIG_TIMER == TIMER_ON_OVERFLOW3)
00113
00114 #define TIMER_PRESCALER 1
00115 #define TIMER_HW_BITS 8
00116
00117 #define TIMER_HW_CNT (1 << TIMER_HW_BITS)
00118 #define DEFINE_TIMER_ISR SIGNAL(SIG_OVERFLOW3)
00119 #define TIMER_TICKS_PER_SEC DIV_ROUND(TIMER_HW_HPTICKS_PER_SEC, TIMER_HW_CNT)
00120
00122 typedef uint16_t hptime_t;
00123 #else
00124
00125 #error Unimplemented value for CONFIG_TIMER
00126 #endif
00127
00128
00130 #define TIMER_HW_HPTICKS_PER_SEC DIV_ROUND(CLOCK_FREQ, TIMER_PRESCALER)
00131
00136 #define OCR_DIVISOR (DIV_ROUND(DIV_ROUND(CLOCK_FREQ, TIMER_PRESCALER), TIMER_TICKS_PER_SEC) - 1)
00137
00139 #define timer_hw_irq() do {} while (0)
00140
00142 #define timer_hw_triggered() (true)
00143
00144
00145 #endif