00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifndef _ADCIFA_H_
00049 #define _ADCIFA_H_
00050
00051 #include <avr32/io.h>
00052 #include "compiler.h"
00053
00054 #if UC3C
00055 #define AVR32_FLASHC_CALIBRATION_FIRST_WORD_ADDRESS 0x80800200
00056 #define AVR32_FLASHC_CALIBRATION_SECOND_WORD_ADDRESS 0x80800204
00057 #define AVR32_FLASHC_CALIBRATION_THIRD_WORD_ADDRESS 0x80800208
00058 #endif
00059
00062 #define AVR32_ADCIFA_INP_ADCIN0 0
00063 #define AVR32_ADCIFA_INP_ADCIN1 1
00064 #define AVR32_ADCIFA_INP_ADCIN2 2
00065 #define AVR32_ADCIFA_INP_ADCIN3 3
00066 #define AVR32_ADCIFA_INP_ADCIN4 4
00067 #define AVR32_ADCIFA_INP_ADCIN5 5
00068 #define AVR32_ADCIFA_INP_ADCIN6 6
00069 #define AVR32_ADCIFA_INP_ADCIN7 7
00070 #define AVR32_ADCIFA_INP_DAC0_INT 8
00071 #define AVR32_ADCIFA_INP_TSENSE 9
00072 #define AVR32_ADCIFA_INP_GNDANA 10
00073
00076 #define AVR32_ADCIFA_INN_ADCIN8 0
00077 #define AVR32_ADCIFA_INN_ADCIN9 1
00078 #define AVR32_ADCIFA_INN_ADCIN10 2
00079 #define AVR32_ADCIFA_INN_ADCIN11 3
00080 #define AVR32_ADCIFA_INN_ADCIN12 4
00081 #define AVR32_ADCIFA_INN_ADCIN13 5
00082 #define AVR32_ADCIFA_INN_ADCIN14 6
00083 #define AVR32_ADCIFA_INN_ADCIN15 7
00084 #define AVR32_ADCIFA_INN_DAC1_INT 8
00085 #define AVR32_ADCIFA_INN_GNDANA 9
00086
00089 #define ADCIFA_REF1V 0x0
00090 #define ADCIFA_REF065VCC 0x1
00091 #define ADCIFA_ADCREF0 0x2
00092 #define ADCIFA_ADCREF1 0x3
00093 #define ADCIFA_ADCREF 0x10
00094
00097 #define ADCIFA_TRGSEL_SOFT 0x0
00098 #define ADCIFA_TRGSEL_ITIMER 0x1
00099 #define ADCIFA_TRGSEL_EVT 0x2
00100
00103 #define ADCIFA_SRES_8B 0x2
00104 #define ADCIFA_SRES_10B 0x1
00105 #define ADCIFA_SRES_12B 0x0
00106
00109 #define ADCIFA_SHG_1 0x0
00110 #define ADCIFA_SHG_2 0x1
00111 #define ADCIFA_SHG_4 0x2
00112 #define ADCIFA_SHG_8 0x3
00113 #define ADCIFA_SHG_16 0x4
00114 #define ADCIFA_SHG_32 0x5
00115 #define ADCIFA_SHG_64 0x6
00116
00119 #define ADCIFA_SOCB_ALLSEQ 0x0
00120 #define ADCIFA_SOCB_SINGLECONV 0x1
00121
00124 #define ADCIFA_CSWS_WSTATE 0x1
00125 #define ADCIFA_CSWS_NOWSTATE 0x0
00126
00129 #define ADCIFA_HWLA_NOADJ 0x0
00130 #define ADCIFA_HWLA_LEFTADJ 0x1
00131
00134 #define ADCIFA_SA_EOS_SOFTACK 0x0
00135 #define ADCIFA_SA_NO_EOS_SOFTACK 0x1
00136
00139 #define ADCIFA_SEQ0 0x0
00140 #define ADCIFA_SEQ1 0x1
00141 #define ADCIFA_SEQ0_SEQ1 0x3
00142
00145 #define ADCIFA_START_UP_TIME 1000
00146
00148
00150 #define ADCIFA_set_offset_calibration(ocal) { AVR32_ADCIFA.adccal |=((ocal)<<AVR32_ADCIFA_ADCCAL_OCAL)&AVR32_ADCIFA_ADCCAL_OCAL_MASK; }
00152 #define ADCIFA_set_gain_calibration(gcal) { AVR32_ADCIFA.adccal |=((gcal)<<AVR32_ADCIFA_ADCCAL_GCAL)&AVR32_ADCIFA_ADCCAL_GCAL_MASK; }
00154 #define ADCIFA_set_sh_gain_calibration(scal) { AVR32_ADCIFA.shcal =((scal)&(AVR32_ADCIFA_SHCAL_GAIN1_MASK | AVR32_ADCIFA_SHCAL_GAIN0_MASK)); }
00156 #define ADCIFA_is_startup_time() (((AVR32_ADCIFA.sr) & (1 << AVR32_ADCIFA_SR_SUTD)) == (1 << AVR32_ADCIFA_SR_SUTD))
00158 #define ADCIFA_enable() { AVR32_ADCIFA.cfg |= (1 << AVR32_ADCIFA_CFG_ADCEN); }
00160 #define ADCIFA_disable() { AVR32_ADCIFA.cfg &= ~(1 << AVR32_ADCIFA_CFG_ADCEN); }
00161
00162 #define ADCIFA_softsoc_sequencer(seq) { AVR32_ADCIFA.cr = (seq); }
00163
00165
00174 #define ADCIFA_configure_sequencer_0(cnvnb, sres, trgsel, socb, csws, hwla, sa) {AVR32_ADCIFA.seqcfg0 = ( (cnvnb<<AVR32_ADCIFA_SEQCFG0_CNVNB)|\
00175 (sres<<AVR32_ADCIFA_SEQCFG0_SRES)|\
00176 (trgsel<<AVR32_ADCIFA_SEQCFG0_TRGSEL)|\
00177 (socb<<AVR32_ADCIFA_SEQCFG0_SOCB)|\
00178 (csws<<AVR32_ADCIFA_SEQCFG0_CSWS)|\
00179 (hwla<<AVR32_ADCIFA_SEQCFG0_HWLA)|\
00180 (sa<<AVR32_ADCIFA_SEQCFG0_SA) ); }
00181
00183 #define ADCIFA_softsoc_sequencer_0() { AVR32_ADCIFA.cr = AVR32_ADCIFA_CR_SOC0_MASK; }
00184
00186 #define ADCIFA_is_eoc_sequencer_0() (((AVR32_ADCIFA.sr)&(1<<AVR32_ADCIFA_SR_SEOC0))==(1<<AVR32_ADCIFA_SR_SEOC0))
00187
00189 #define ADCIFA_is_eos_sequencer_0() (((AVR32_ADCIFA.sr)&(1<<AVR32_ADCIFA_SR_SEOS0))==(1<<AVR32_ADCIFA_SR_SEOS0))
00190
00193 #define ADCIFA_configure_muxsel0p(m7, m6, m5, m4, m3, m2, m1, m0) {\
00194 AVR32_ADCIFA.inpsel10 = ((m7) << AVR32_ADCIFA_INNSEL10_CNV7_OFFSET) | ((m6) << AVR32_ADCIFA_INNSEL10_CNV6_OFFSET) | ((m5) << AVR32_ADCIFA_INNSEL10_CNV5_OFFSET) | ((m4) << AVR32_ADCIFA_INNSEL10_CNV4_OFFSET);\
00195 AVR32_ADCIFA.inpsel00 = ((m3) << AVR32_ADCIFA_INNSEL00_CNV3_OFFSET) | ((m2) << AVR32_ADCIFA_INNSEL00_CNV2_OFFSET) | ((m1) << AVR32_ADCIFA_INNSEL00_CNV1_OFFSET) | ((m0) << AVR32_ADCIFA_INNSEL00_CNV0_OFFSET);\
00196 }
00197
00200 #define ADCIFA_configure_muxsel0n(m7, m6, m5, m4, m3, m2, m1, m0) {\
00201 AVR32_ADCIFA.innsel10 = ((m7) << AVR32_ADCIFA_INNSEL10_CNV7_OFFSET) | ((m6) << AVR32_ADCIFA_INNSEL10_CNV6_OFFSET) | ((m5) << AVR32_ADCIFA_INNSEL10_CNV5_OFFSET) | ((m4) << AVR32_ADCIFA_INNSEL10_CNV4_OFFSET);\
00202 AVR32_ADCIFA.innsel00 = ((m3) << AVR32_ADCIFA_INNSEL00_CNV3_OFFSET) | ((m2) << AVR32_ADCIFA_INNSEL00_CNV2_OFFSET) | ((m1) << AVR32_ADCIFA_INNSEL00_CNV1_OFFSET) | ((m0) << AVR32_ADCIFA_INNSEL00_CNV0_OFFSET);\
00203 }
00204
00207 #define ADCIFA_configure_sh0gain(g7, g6, g5, g4, g3, g2, g1, g0) { AVR32_ADCIFA.shg0 = ((g7) << AVR32_ADCIFA_GCNV7_OFFSET) | ((g6) << AVR32_ADCIFA_GCNV6_OFFSET) | ((g5) << AVR32_ADCIFA_GCNV5_OFFSET) |((g4) << AVR32_ADCIFA_GCNV4_OFFSET) |((g3) << AVR32_ADCIFA_GCNV3_OFFSET) |((g2) << AVR32_ADCIFA_GCNV2_OFFSET) |((g1) << AVR32_ADCIFA_GCNV1_OFFSET) |((g0) << AVR32_ADCIFA_GCNV0_OFFSET); }
00208
00211 #define ADCIFA_read_resx_sequencer_0(ind) ((int)AVR32_ADCIFA.resx[(ind)])
00212
00214
00223 #define ADCIFA_configure_sequencer_1(cnvnb, sres, trgsel, socb, csws, hwla, sa) {AVR32_ADCIFA.seqcfg1 = ((cnvnb)<<AVR32_ADCIFA_SEQCFG1_CNVNB)|\
00224 ((sres)<<AVR32_ADCIFA_SEQCFG1_SRES)|\
00225 ((trgsel)<<AVR32_ADCIFA_SEQCFG1_TRGSEL)|\
00226 ((socb)<<AVR32_ADCIFA_SEQCFG1_SOCB)|\
00227 ((csws)<<AVR32_ADCIFA_SEQCFG1_CSWS)|\
00228 ((hwla)<<AVR32_ADCIFA_SEQCFG1_HWLA)|\
00229 ((sa)<<AVR32_ADCIFA_SEQCFG1_SA);}
00230
00232 #define ADCIFA_softsoc_sequencer_1() { AVR32_ADCIFA.cr = AVR32_ADCIFA_CR_SOC1_MASK; }
00233
00235 #define ADCIFA_is_eoc_sequencer_1() (((AVR32_ADCIFA.sr)&(1<<AVR32_ADCIFA_SR_SEOC1))==(1<<AVR32_ADCIFA_SR_SEOC1))
00236
00238 #define ADCIFA_is_eos_sequencer_1() (((AVR32_ADCIFA.sr)&(1<<AVR32_ADCIFA_SR_SEOS1))==(1<<AVR32_ADCIFA_SR_SEOS1))
00239
00242 #define ADCIFA_configure_muxsel1p(m7, m6, m5, m4, m3, m2, m1, m0) {\
00243 AVR32_ADCIFA.inpsel11 = ((m7) << AVR32_ADCIFA_INNSEL10_CNV7_OFFSET) | ((m6) << AVR32_ADCIFA_INNSEL10_CNV6_OFFSET) | ((m5) << AVR32_ADCIFA_INNSEL10_CNV5_OFFSET) | ((m4) << AVR32_ADCIFA_INNSEL10_CNV4_OFFSET);\
00244 AVR32_ADCIFA.inpsel01 = ((m3) << AVR32_ADCIFA_INNSEL00_CNV3_OFFSET) | ((m2) << AVR32_ADCIFA_INNSEL00_CNV2_OFFSET) | ((m1) << AVR32_ADCIFA_INNSEL00_CNV1_OFFSET) | ((m0) << AVR32_ADCIFA_INNSEL00_CNV0_OFFSET);\
00245 }
00246
00249 #define ADCIFA_configure_muxsel1n(m7, m6, m5, m4, m3, m2, m1, m0) {\
00250 AVR32_ADCIFA.innsel11 = ((m7) << AVR32_ADCIFA_INNSEL10_CNV7_OFFSET) | ((m6) << AVR32_ADCIFA_INNSEL10_CNV6_OFFSET) | ((m5) << AVR32_ADCIFA_INNSEL10_CNV5_OFFSET) | ((m4) << AVR32_ADCIFA_INNSEL10_CNV4_OFFSET);\
00251 AVR32_ADCIFA.innsel01 = ((m3) << AVR32_ADCIFA_INNSEL00_CNV3_OFFSET) | ((m2) << AVR32_ADCIFA_INNSEL00_CNV2_OFFSET) | ((m1) << AVR32_ADCIFA_INNSEL00_CNV1_OFFSET) | ((m0) << AVR32_ADCIFA_INNSEL00_CNV0_OFFSET);\
00252 }
00253
00256 #define ADCIFA_configure_sh1gain(g7, g6, g5, g4, g3, g2, g1, g0) { AVR32_ADCIFA.shg1 = ((g7) << AVR32_ADCIFA_GCNV7_OFFSET) | ((g6) << AVR32_ADCIFA_GCNV6_OFFSET) | ((g5) << AVR32_ADCIFA_GCNV5_OFFSET) |((g4) << AVR32_ADCIFA_GCNV4_OFFSET) |((g3) << AVR32_ADCIFA_GCNV3_OFFSET) |((g2) << AVR32_ADCIFA_GCNV2_OFFSET) |((g1) << AVR32_ADCIFA_GCNV1_OFFSET) |((g0) << AVR32_ADCIFA_GCNV0_OFFSET); }
00257
00260 #define ADCIFA_read_resx_sequencer_1(ind) ((int)AVR32_ADCIFA.resx[(ind)+8])
00261
00263 #define ADCIFA_NONE 0xFF
00264
00266
00268 #define ADCIFA_CONFIGURATION_REFUSED 0x0
00269
00271 #define ADCIFA_CONFIGURATION_ACCEPTED 0x1
00272
00274 #define ADCIFA_STATUS_COMPLETED 0x2
00275
00277 #define ADCIFA_STATUS_NOT_COMPLETED 0x3
00278
00280 typedef struct
00281 {
00283 U32 frequency;
00284
00286 U8 reference_source;
00287
00289 Bool sample_and_hold_disable;
00290
00292 Bool single_sequencer_mode;
00293
00295 Bool free_running_mode_enable;
00296
00298 Bool sleep_mode_enable;
00299
00301 U16 gain_calibration_value;
00302
00304 U16 offset_calibration_value;
00305
00307 U16 sh_calibration_value;
00308
00309 } adcifa_opt_t;
00310
00312 typedef struct
00313 {
00315 U8 convnb;
00316
00318 U8 resolution;
00319
00321 U8 trigger_selection;
00322
00324 U8 start_of_conversion;
00325
00327 U8 oversampling;
00328
00330 U8 half_word_adjustment;
00331
00333 U8 software_acknowledge;
00334
00335 } adcifa_sequencer_opt_t;
00336
00338 typedef struct
00339 {
00341 U8 channel_p;
00342
00344 U8 channel_n;
00345
00347 U8 gain;
00348
00349 } adcifa_sequencer_conversion_opt_t;
00350
00357 extern void adcifa_get_calibration_data( volatile avr32_adcifa_t * adcifa,
00358 adcifa_opt_t * p_adcifa_opt,
00359 U8 sequencer);
00360
00368 extern U8 adcifa_configure( volatile avr32_adcifa_t * adcifa,
00369 adcifa_opt_t * p_adcifa_opt,
00370 U32 pb_hz);
00371
00380 extern U8 adcifa_configure_sequencer( volatile avr32_adcifa_t * adcifa,
00381 U8 sequencer,
00382 adcifa_sequencer_opt_t * p_adcifa_sequencer_opt,
00383 adcifa_sequencer_conversion_opt_t * p_adcifa_sequencer_conversion_opt );
00384
00389 extern void adcifa_start_sequencer( volatile avr32_adcifa_t * adcifa,
00390 U8 sequencer );
00391
00400 extern U8 adcifa_get_values_from_sequencer( volatile avr32_adcifa_t * adcifa,
00401 U8 sequencer,
00402 adcifa_sequencer_opt_t * p_adcifa_sequencer_opt,
00403 S16* adcifa_values );
00404 #endif // _ADCIFA_H_