4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
30 * All Rights Reserved.
33 * \brief AFSK modem hardware-specific definitions.
36 * \author Francesco Sacchi <batt@develer.com>
44 #include <cfg/compiler.h>
45 #include <cfg/macros.h>
46 #include <cfg/module.h>
49 #define CONFIG_ADC_CLOCK 4800000UL
50 #define CONFIG_ADC_STARTUP_TIME 20
51 #define CONFIG_ADC_SHTIME 834
53 #define ADC_COMPUTED_PRESCALER ((CPU_FREQ/(2 * CONFIG_ADC_CLOCK)) - 1)
54 #define ADC_COMPUTED_STARTUPTIME (((CONFIG_ADC_STARTUP_TIME * CONFIG_ADC_CLOCK)/ 8000000UL) - 1)
55 #define ADC_COMPUTED_SHTIME (((CONFIG_ADC_SHTIME * CONFIG_ADC_CLOCK)/1000000000UL) - 1)
57 static Afsk *afsk_ctx;
61 static void __attribute__((interrupt)) hw_afsk_adc_isr(void)
63 afsk_adc_isr(afsk_ctx, ADC_LCDR - 128);
65 /* Enable block writing */
66 PIOA_OWER = DAC_PIN_MASK;
69 PIOA_ODSR = (afsk_dac_isr(afsk_ctx) << 15) & DAC_PIN_MASK;
72 PIOA_ODSR = 0x4000000;
74 PIOA_OWDR = DAC_PIN_MASK;
79 void hw_afsk_adc_init(int ch, struct Afsk * ctx)
82 afsk_ctx->adc_ch = ch;
84 ADC_MR |= BV(ADC_LOWRES);
86 //Apply computed prescaler value
87 ADC_MR &= ~ADC_PRESCALER_MASK;
88 ADC_MR |= ((ADC_COMPUTED_PRESCALER << ADC_PRESCALER_SHIFT) & ADC_PRESCALER_MASK);
90 //Apply computed start up time
91 ADC_MR &= ~ADC_STARTUP_MASK;
92 ADC_MR |= ((ADC_COMPUTED_STARTUPTIME << ADC_STARTUP_SHIFT) & ADC_STARTUP_MASK);
94 //Apply computed sample and hold time
95 ADC_MR &= ~ADC_SHTIME_MASK;
96 ADC_MR |= ((ADC_COMPUTED_SHTIME << ADC_SHTIME_SHIFT) & ADC_SHTIME_MASK);
98 // Disable all interrupt
101 //Register interrupt vector
102 AIC_SVR(ADC_ID) = hw_afsk_adc_isr;
103 AIC_SMR(ADC_ID) = AIC_SRCTYPE_INT_EDGE_TRIGGERED;
104 AIC_IECR = BV(ADC_ID);
106 //Enable data ready irq
107 ADC_IER = BV(ADC_DRDY);
110 PMC_PCER = BV(TC0_ID);
112 TC0_CCR = BV(TC_SWTRG) | BV(TC_CLKEN);
114 TC0_CMR = BV(TC_WAVE);
115 TC0_CMR |= (TC_WAVSEL_UP_RC_TRG | TC_ACPC_CLEAR_OUTPUT | TC_ACPA_SET_OUTPUT);
116 TC0_RC = (CPU_FREQ / 2) / 9600;
120 // Auto trigger enabled on TIOA channel 0
121 ADC_MR |= BV(ADC_TRGEN);
123 //Disable all channels
124 ADC_CHDR = ADC_CH_MASK;