SimAVR
AVR Simulator
avr_timer.h
Go to the documentation of this file.
1 /*
2  * avr_timer.h
3  *
4  * Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5  *
6  * This file is part of simavr.
7  *
8  * simavr is free software: you can redistribute it and/or modify it under the terms of the GNU
9  * General Public License as published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * simavr is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
13  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with simavr. If not, see
17  * <http://www.gnu.org/licenses/>.
18  */
19 
25 #ifndef __AVR_TIMER_H__
26 #define __AVR_TIMER_H__
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 #include "sim_avr.h"
34 
35  enum
36  {
40 
42  };
43 
44  enum
45  {
49 
51  };
52 
54 #define AVR_IOCTL_TIMER_GETIRQ(_name) AVR_IOCTL_DEF('t','m','r',(_name))
55 
57  enum
58  {
59  avr_timer_wgm_none = 0, // invalid mode
65  };
66 
68  enum
69  {
74  };
75 
76  enum
77  {
81  };
82  typedef struct avr_timer_wgm_t
83  {
84  uint32_t top:8, bottom:8, size:8, kind:8;
86 
87 #define AVR_TIMER_WGM_NORMAL8() { .kind = avr_timer_wgm_normal, .size=8 }
88 #define AVR_TIMER_WGM_NORMAL16() { .kind = avr_timer_wgm_normal, .size=16 }
89 #define AVR_TIMER_WGM_CTC() { .kind = avr_timer_wgm_ctc, .top = avr_timer_wgm_reg_ocra }
90 #define AVR_TIMER_WGM_ICCTC() { .kind = avr_timer_wgm_ctc, .top = avr_timer_wgm_reg_icr }
91 #define AVR_TIMER_WGM_FASTPWM8() { .kind = avr_timer_wgm_fast_pwm, .size=8 }
92 #define AVR_TIMER_WGM_FASTPWM9() { .kind = avr_timer_wgm_fast_pwm, .size=9 }
93 #define AVR_TIMER_WGM_FASTPWM10() { .kind = avr_timer_wgm_fast_pwm, .size=10 }
94 #define AVR_TIMER_WGM_FCPWM8() { .kind = avr_timer_wgm_fc_pwm, .size=8 }
95 #define AVR_TIMER_WGM_FCPWM9() { .kind = avr_timer_wgm_fc_pwm, .size=9 }
96 #define AVR_TIMER_WGM_FCPWM10() { .kind = avr_timer_wgm_fc_pwm, .size=10 }
97 #define AVR_TIMER_WGM_OCPWM() { .kind = avr_timer_wgm_pwm, .top = avr_timer_wgm_reg_ocra }
98 #define AVR_TIMER_WGM_ICPWM() { .kind = avr_timer_wgm_pwm, .top = avr_timer_wgm_reg_icr }
99 
100  typedef struct avr_timer_comp_t
101  {
103  struct avr_timer_t *timer;
108  uint64_t comp_cycles;
110 
111  typedef struct avr_timer_t
112  {
114  char name;
115 
117 
120 
126 
129  uint8_t cs_div[16];
130  uint32_t cs_div_clock;
131 
134 
136 
139 
140  uint64_t tov_cycles;
141  uint64_t tov_base;
142  uint16_t tov_top;
143  } avr_timer_t;
144 
145  void avr_timer_init (avr_t * avr, avr_timer_t * port);
146 
147 #ifdef __cplusplus
148 };
149 #endif
150 
151 #endif /*__AVR_TIMER_H__*/
152 
Definition: avr_timer.h:78
Definition: avr_timer.h:62
Definition: avr_timer.h:47
avr_io_addr_t r_tcnth
Definition: avr_timer.h:119
avr_io_t io
Definition: avr_timer.h:113
avr_int_vector_t icr
input capture
Definition: avr_timer.h:138
uint32_t cs_div_clock
Definition: avr_timer.h:130
Definition: avr_timer.h:60
uint16_t avr_io_addr_t
Definition: sim_avr_types.h:37
avr_regbit_t disabled
bit in the PRR
Definition: avr_timer.h:116
avr_regbit_t cs[4]
Definition: avr_timer.h:128
avr_t * avr
Definition: run_avr.c:54
Toggle OCnx on compare match.
Definition: avr_timer.h:71
uint32_t kind
Definition: avr_timer.h:84
struct avr_timer_comp_t * avr_timer_comp_p
avr_io_addr_t r_ocrh
comparator register hi byte
Definition: avr_timer.h:105
uint64_t tov_base
when we last were called
Definition: avr_timer.h:141
avr_io_addr_t r_ocr
comparator register low byte
Definition: avr_timer.h:104
Definition: avr_timer.h:39
Definition: avr_timer.h:63
avr_regbit_t com
comparator output mode registers
Definition: avr_timer.h:106
set OCnx on compare match
Definition: avr_timer.h:73
interrupt vector for the IO modules
Definition: sim_interrupts.h:37
avr_regbit_t ices
input capture edge select
Definition: avr_timer.h:133
uint8_t cs_div[16]
Definition: avr_timer.h:129
This 'structure' is a packed representation of an IO register 'bit' (or consecutive bits)...
Definition: sim_avr_types.h:47
struct avr_timer_t avr_timer_t
Definition: avr_timer.h:59
int wgm_op_mode_kind
Definition: avr_timer.h:124
avr_regbit_t as2
asynchronous clock 32khz
Definition: avr_timer.h:127
Definition: avr_timer.h:80
Definition: avr_timer.h:46
avr_regbit_t icp
input capture pin, to link IRQs
Definition: avr_timer.h:132
Definition: avr_timer.h:64
avr_regbit_t com_pin
where comparator output is connected
Definition: avr_timer.h:107
uint64_t comp_cycles
Definition: avr_timer.h:108
avr_regbit_t wgm[4]
Definition: avr_timer.h:121
uint64_t tov_cycles
Definition: avr_timer.h:140
Definition: avr_timer.h:61
struct avr_timer_wgm_t avr_timer_wgm_t
Definition: avr_timer.h:79
uint32_t top
Definition: avr_timer.h:84
Definition: avr_timer.h:100
avr_timer_comp_t comp[AVR_TIMER_COMP_COUNT]
Definition: avr_timer.h:135
avr_io_addr_t r_icrh
Definition: avr_timer.h:119
struct avr_timer_comp_t avr_timer_comp_t
uint32_t size
Definition: avr_timer.h:84
Definition: avr_timer.h:37
Definition: avr_timer.h:111
uint32_t wgm_op_mode_size
Definition: avr_timer.h:125
comparator pins output IRQ
Definition: avr_timer.h:48
avr_io_addr_t r_icr
Definition: avr_timer.h:118
avr_timer_wgm_t mode
Definition: avr_timer.h:123
Definition: avr_timer.h:82
avr_io_addr_t r_tcnt
Definition: avr_timer.h:118
char name
Definition: avr_timer.h:114
uint16_t tov_top
current top value to calculate tnct
Definition: avr_timer.h:142
uint32_t bottom
Definition: avr_timer.h:84
Normal mode, OCnx disconnected.
Definition: avr_timer.h:70
struct avr_timer_t * timer
parent timer
Definition: avr_timer.h:103
avr_int_vector_t overflow
overflow
Definition: avr_timer.h:137
avr_int_vector_t interrupt
interrupt vector
Definition: avr_timer.h:102
Definition: avr_timer.h:38
avr_timer_wgm_t wgm_op[16]
Definition: avr_timer.h:122
clear OCnx on compare match
Definition: avr_timer.h:72
Main AVR instance.
Definition: sim_avr.h:142
IO module base struct Modules uses that as their first member in their own struct.
Definition: sim_io.h:42
Definition: avr_timer.h:41
void avr_timer_init(avr_t *avr, avr_timer_t *port)
Definition: avr_timer.c:673
Definition: avr_timer.h:50