summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/mpio/adc-mpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/mpio/adc-mpio.c')
-rw-r--r--firmware/target/coldfire/mpio/adc-mpio.c30
1 files changed, 5 insertions, 25 deletions
diff --git a/firmware/target/coldfire/mpio/adc-mpio.c b/firmware/target/coldfire/mpio/adc-mpio.c
index 92b9479279..4c796d5d15 100644
--- a/firmware/target/coldfire/mpio/adc-mpio.c
+++ b/firmware/target/coldfire/mpio/adc-mpio.c
@@ -28,17 +28,11 @@
28 28
29volatile unsigned short adc_data[NUM_ADC_CHANNELS] IBSS_ATTR; 29volatile unsigned short adc_data[NUM_ADC_CHANNELS] IBSS_ATTR;
30 30
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
36 */
37
38void ADC(void) __attribute__ ((interrupt_handler,section(".icode"))); 31void ADC(void) __attribute__ ((interrupt_handler,section(".icode")));
39void ADC(void) 32void ADC(void)
40{ 33{
41 static unsigned char channel IBSS_ATTR; 34 static unsigned char channel IBSS_ATTR;
35
42 /* read current value */ 36 /* read current value */
43 adc_data[(channel&0x03)] = ADVALUE; 37 adc_data[(channel&0x03)] = ADVALUE;
44 38
@@ -48,15 +42,10 @@ void ADC(void)
48 * ADCONFIG is 16bit wide so we have to shift data by 16bits left 42 * ADCONFIG is 16bit wide so we have to shift data by 16bits left
49 * thats why we shift <<24 instead of <<8 43 * thats why we shift <<24 instead of <<8
50 */ 44 */
51
52 channel++; 45 channel++;
53 46
54 and_l(~(0x03<<24),&ADCONFIG); 47 and_l(~(0x03<<24),&ADCONFIG);
55 or_l( (((channel&0x03) << 8 )|(1<<7))<<16, &ADCONFIG); 48 or_l( (((channel&0x03) << 8 )|(1<<7))<<16, &ADCONFIG);
56
57 if ( (channel & 0x03) == 0 )
58 /* disable ADC interrupt */
59 and_l((~(1<<6))<<16,&ADCONFIG);
60} 49}
61 50
62unsigned short adc_scan(int channel) 51unsigned short adc_scan(int channel)
@@ -65,12 +54,6 @@ unsigned short adc_scan(int channel)
65 return adc_data[(channel&0x03)]; 54 return adc_data[(channel&0x03)];
66} 55}
67 56
68void adc_tick(void)
69{
70 /* enable ADC interrupt */
71 or_l( ((1<<6))<<16, &ADCONFIG);
72}
73
74void adc_init(void) 57void adc_init(void)
75{ 58{
76 /* GPIO38 GPIO39 */ 59 /* GPIO38 GPIO39 */
@@ -79,19 +62,16 @@ void adc_init(void)
79 /* ADOUT_SEL = 01 62 /* ADOUT_SEL = 01
80 * SOURCE SELECT = 000 63 * SOURCE SELECT = 000
81 * CLEAR INTERRUPT FLAG 64 * CLEAR INTERRUPT FLAG
82 * ENABLE INTERRUPT = 0 65 * ENABLE INTERRUPT = 1
83 * ADOUT_DRIVE = 00 66 * ADOUT_DRIVE = 00
84 * ADCLK_SEL = 011 (busclk/8) 67 * ADCLK_SEL = 011 (busclk/64)
85 */ 68 */
86 69
87 ADCONFIG = (1<<10)|(1<<8)|(1<<7)|0x03; 70 ADCONFIG = (1<<10)|(1<<7)|(1<<6)|0x06;
88 71
89 /* ADC interrupt level 4.0 */ 72 /* ADC interrupt level 4.0 */
90 or_l((4<<28), &INTPRI8); 73 or_l((4<<28), &INTPRI8);
91 74
92 /* create tick task which enables ADC interrupt */
93 tick_add_task(adc_tick);
94
95 /* let the interrupt handler fill readout array */ 75 /* let the interrupt handler fill readout array */
96 sleep(2); 76 sleep(HZ/10);
97} 77}