1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Marcin Bukat
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
29 volatile unsigned short adc_data
[NUM_ADC_CHANNELS
] IBSS_ATTR
;
31 /* Reading takes 4096 adclk ticks
32 * 1) tick task is created that enables ADC interrupt
33 * 2) On interrupt single channel is readed and
34 * ADC is prepared for next channel
35 * 3) When all 4 channels are scanned ADC interrupt is disabled
38 void ADC(void) __attribute__ ((interrupt_handler
,section(".icode")));
41 static unsigned char channel IBSS_ATTR
;
42 /* read current value */
43 adc_data
[(channel
&0x03)] = ADVALUE
;
48 * ADCONFIG is 16bit wide so we have to shift data by 16bits left
49 * thats why we shift <<24 instead of <<8
54 and_l(~(0x03<<24),&ADCONFIG
);
55 or_l( (((channel
&0x03) << 8 )|(1<<7))<<16, &ADCONFIG
);
57 if ( (channel
& 0x03) == 0 )
58 /* disable ADC interrupt */
59 and_l((~(1<<6))<<16,&ADCONFIG
);
62 unsigned short adc_scan(int channel
)
64 /* maybe we can drop &0x03 part */
65 return adc_data
[(channel
&0x03)];
70 /* enable ADC interrupt */
71 or_l( ((1<<6))<<16, &ADCONFIG
);
77 and_l(~((1<<6)|(1<<7)), &GPIO1_FUNCTION
);
81 * CLEAR INTERRUPT FLAG
82 * ENABLE INTERRUPT = 0
84 * ADCLK_SEL = 011 (busclk/8)
87 ADCONFIG
= (1<<10)|(1<<8)|(1<<7)|0x03;
89 /* ADC interrupt level 4.0 */
90 or_l((4<<28), &INTPRI8
);
92 /* create tick task which enables ADC interrupt */
93 tick_add_task(adc_tick
);
95 /* let the interrupt handler fill readout array */