SimAVR
AVR Simulator
avr_adc.h
Go to the documentation of this file.
1 /*
2  * avr_adc.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 
34 #ifndef __AVR_ADC_H___
35 #define __AVR_ADC_H___
36 
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41 
42 #include "sim_avr.h"
43 
44  enum
45  {
51  ADC_IRQ_TEMP, // see the datasheet
55  };
56 
58 #define AVR_IOCTL_ADC_GETIRQ AVR_IOCTL_DEF('a','d','c',' ')
59 
61  enum
62  {
70  };
71 
72  typedef struct avr_adc_mux_t
73  {
74  unsigned long kind:3, gain:8, diff:8, src:13;
75  } avr_adc_mux_t;
76 
77  enum
78  {
82  ADC_VREF_V110 = 1100,
83  ADC_VREF_V256 = 2560,
84  };
85 
87  typedef enum
88  {
106  } avr_adts_type;
107 
108  typedef struct avr_adc_t
109  {
111 
112  uint8_t r_admux;
113  // if the last bit exists in the mux, we are an extended ADC
116  uint16_t ref_values[7];
117 
119 
120  uint8_t r_adcsra;
124 
126 
127  uint8_t r_adcl, r_adch;
128 
129  uint8_t r_adcsrb;
132  uint8_t adts_mode;
135 
138 
139  /*
140  * runtime bits
141  */
143  uint16_t adc_values[8];
144  uint16_t temp;
145  uint8_t first;
146  uint8_t read_status;
147  } avr_adc_t;
148 
149  void avr_adc_init (avr_t * avr, avr_adc_t * port);
150 
151  /*
152  * Helper macros for the Cores definition of muxes
153  */
154 #define AVR_ADC_SINGLE(_chan) { \
155  .kind = ADC_MUX_SINGLE, \
156  .src = (_chan), \
157  }
158 
159 #define AVR_ADC_DIFF(_a,_b,_g) { \
160  .kind = ADC_MUX_DIFF, \
161  .src = (_a), \
162  .diff = (_b), \
163  .gain = (_g), \
164  }
165 
166 #define AVR_ADC_REF(_t) { \
167  .kind = ADC_MUX_REF, \
168  .src = (_t), \
169  }
170 
171 #define AVR_ADC_TEMP() { \
172  .kind = ADC_MUX_TEMP, \
173  }
174 
175 #define AVR_ADC_VCC4() { \
176  .kind = ADC_MUX_VCC4, \
177  }
178 
179 #ifdef __cplusplus
180 };
181 #endif
182 
183 #endif /* __AVR_ADC_H___ */
184 
Definition: avr_adc.h:81
Definition: avr_adc.h:48
Definition: avr_adc.h:97
differential channels (src-diff)
Definition: avr_adc.h:67
Definition: avr_adc.h:51
avr_adts_type
ADC trigger sources.
Definition: avr_adc.h:87
avr_regbit_t aden
ADC Enabled.
Definition: avr_adc.h:121
struct avr_adc_t avr_adc_t
Definition: avr_adc.h:104
Definition: avr_adc.h:49
avr_regbit_t adps[3]
Prescaler bits. Note that it's a frequency bit shift.
Definition: avr_adc.h:125
Definition: avr_adc.h:50
sends a avr_adc_mux_t
Definition: avr_adc.h:54
Definition: avr_adc.h:102
Nothing. return 0
Definition: avr_adc.h:64
uint8_t read_status
marked one when adcl is read
Definition: avr_adc.h:146
Definition: avr_adc.h:90
avr_t * avr
Definition: run_avr.c:54
unsigned long gain
Definition: avr_adc.h:74
input IRQ values. Values are /always/ volts * 1000 (millivolts)
Definition: avr_adc.h:47
Definition: avr_adc.h:91
uint8_t adts_mode
the extracted ADTS mode
Definition: avr_adc.h:132
default mode
Definition: avr_adc.h:80
reference voltage (in src * 100)
Definition: avr_adc.h:69
uint16_t adc_values[8]
current values on the ADCs
Definition: avr_adc.h:143
Definition: avr_adc.h:52
Normal ADC pin reading
Definition: avr_adc.h:66
Definition: avr_adc.h:95
void avr_adc_init(avr_t *avr, avr_adc_t *port)
Definition: avr_adc.c:360
Definition: avr_adc.h:50
Definition: avr_adc.h:47
interrupt vector for the IO modules
Definition: sim_interrupts.h:37
Nothing. return something random
Definition: avr_adc.h:65
Definition: avr_adc.h:49
This 'structure' is a packed representation of an IO register 'bit' (or consecutive bits)...
Definition: sim_avr_types.h:47
Definition: avr_adc.h:94
Definition: avr_adc.h:48
internal temp sensor
Definition: avr_adc.h:68
Definition: avr_adc.h:83
uint8_t r_adcsrb
ADC Control and Status Register B.
Definition: avr_adc.h:129
Definition: avr_adc.h:79
avr_regbit_t adate
ADC Auto Trigger Enable.
Definition: avr_adc.h:123
avr_adts_type adts_op[16]
ADTS type.
Definition: avr_adc.h:131
uint8_t r_adch
Data Registers.
Definition: avr_adc.h:127
avr_regbit_t mux[6]
Definition: avr_adc.h:114
uint8_t first
Definition: avr_adc.h:145
Definition: avr_adc.h:63
Definition: avr_adc.h:47
avr_regbit_t adsc
ADC Start Conversion.
Definition: avr_adc.h:122
avr_regbit_t adlar
left/right adjustment bit
Definition: avr_adc.h:118
uint8_t r_adcsra
ADC Control and Status Register A.
Definition: avr_adc.h:120
avr_adc_mux_t muxmode[64]
maximum 6 bits of mux modes
Definition: avr_adc.h:142
uint8_t r_adcl
Definition: avr_adc.h:127
Definition: avr_adc.h:105
Definition: avr_adc.h:103
Definition: avr_adc.h:99
unsigned long kind
Definition: avr_adc.h:74
avr_io_t io
Definition: avr_adc.h:110
avr_regbit_t ipr
Input Polarity Reversal (tinyx5 have it)
Definition: avr_adc.h:134
struct avr_adc_mux_t avr_adc_mux_t
uint8_t r_admux
Definition: avr_adc.h:112
unsigned long diff
Definition: avr_adc.h:74
Definition: avr_adc.h:50
avr_regbit_t bin
Bipolar Input Mode (tinyx5 have it)
Definition: avr_adc.h:133
Definition: avr_adc.h:49
Definition: avr_adc.h:89
Definition: avr_adc.h:108
Definition: avr_adc.h:98
Definition: avr_adc.h:101
avr_regbit_t adts[4]
Timing Source.
Definition: avr_adc.h:130
Definition: avr_adc.h:53
avr_int_vector_t adc
use ADIF and ADIE bits
Definition: avr_adc.h:137
Definition: avr_adc.h:100
unsigned long src
Definition: avr_adc.h:74
Definition: avr_adc.h:48
Definition: avr_adc.h:92
Definition: avr_adc.h:96
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_adc.h:93
uint16_t ref_values[7]
ADC_VREF_*.
Definition: avr_adc.h:116
Definition: avr_adc.h:49
uint16_t temp
temp sensor reading
Definition: avr_adc.h:144
Definition: avr_adc.h:47
Definition: avr_adc.h:82
Definition: avr_adc.h:50
Definition: avr_adc.h:72
Definition: avr_adc.h:48
avr_regbit_t ref[3]
reference voltages bits
Definition: avr_adc.h:115