4 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
28 TIMER_IRQ_OUT_PWM0 = 0,
33 // Get the internal IRQ corresponding to the INT
34 #define AVR_IOCTL_TIMER_GETIRQ(_name) AVR_IOCTL_DEF('t','m','r',(_name))
37 avr_timer_wgm_none = 0, // invalid mode
40 avr_timer_wgm_fast_pwm,
42 typedef struct avr_timer_wgm_t {
43 uint32_t top: 8, bottom: 8, size : 8, kind : 8;
46 #define AVR_TIMER_WGM_NORMAL8() { .kind = avr_timer_wgm_normal, .size=8 }
47 #define AVR_TIMER_WGM_NORMAL16() { .kind = avr_timer_wgm_normal, .size=16 }
48 #define AVR_TIMER_WGM_CTC() { .kind = avr_timer_wgm_ctc }
49 #define AVR_TIMER_WGM_FASTPWM() { .kind = avr_timer_wgm_fast_pwm }
51 typedef struct avr_timer_t {
54 avr_regbit_t disabled; // bit in the PRR
56 avr_io_addr_t r_ocra, r_ocrb, r_ocrc, r_tcnt, r_icr;
57 avr_io_addr_t r_ocrah, r_ocrbh, r_tcnth, r_icrh;
60 avr_timer_wgm_t wgm_op[16];
64 avr_regbit_t as2; // asynchronous clock 32khz
66 avr_int_vector_t compa; // comparator A
67 avr_int_vector_t compb; // comparator A
68 avr_int_vector_t overflow; // overflow
69 avr_int_vector_t icr; // input capture
71 uint64_t compa_cycles;
72 uint64_t compb_cycles;
76 void avr_timer_init(avr_t * avr, avr_timer_t * port);
78 #endif /* AVR_TIMER_H_ */