diff options
Diffstat (limited to 'firmware/target/coldfire/mpio/hd200/adc-hd200.c')
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/adc-hd200.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/firmware/target/coldfire/mpio/hd200/adc-hd200.c b/firmware/target/coldfire/mpio/hd200/adc-hd200.c new file mode 100644 index 0000000000..8bf96436bf --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/adc-hd200.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "kernel.h" | ||
26 | #include "thread.h" | ||
27 | #include "adc.h" | ||
28 | |||
29 | volatile unsigned short adc_data[NUM_ADC_CHANNELS] IBSS_ATTR; | ||
30 | |||
31 | /* Reading takes 4096 adclk ticks | ||
32 | * We do read one channel at once | ||
33 | * | ||
34 | * state FCPU Fbus Fadc bus/Fadc Fchannelread | ||
35 | * default 11.2896 MHz 5.6448 MHz 5.6448 MHz 2 172.2656 Hz | ||
36 | * normal 45.1584 MHz 22.5792 MHz 2.8224 MHz 8 172.2656 Hz | ||
37 | * max 124.1856 MHz 62.0928 MHz 1.9404 MHz 32 118.4326 Hz | ||
38 | */ | ||
39 | |||
40 | void ADC(void) __attribute__ ((interrupt_handler,section(".icode"))); | ||
41 | void ADC(void) | ||
42 | { | ||
43 | static unsigned char channel; | ||
44 | /* read current value */ | ||
45 | adc_data[(channel & 0x03)] = ADVALUE; | ||
46 | |||
47 | /* switch channel | ||
48 | * | ||
49 | * set source remark | ||
50 | * ADCONFIG is 16bit wide so we have to shift data by 16bits left | ||
51 | * thats why we shift <<24 instead of <<8 | ||
52 | */ | ||
53 | |||
54 | channel++; | ||
55 | |||
56 | and_l(~(3<<24),&ADCONFIG); | ||
57 | or_l( (((channel & 0x03) << 8 )|(1<<7))<<16, &ADCONFIG); | ||
58 | |||
59 | } | ||
60 | |||
61 | unsigned short adc_scan(int channel) | ||
62 | { | ||
63 | /* maybe we can drop &0x03 part */ | ||
64 | return adc_data[(channel&0x03)]; | ||
65 | } | ||
66 | |||
67 | void adc_init(void) | ||
68 | { | ||
69 | /* GPIO38 GPIO39 */ | ||
70 | and_l(~((1<<6)|(1<<7)), &GPIO1_FUNCTION); | ||
71 | |||
72 | /* ADOUT_SEL = 01 | ||
73 | * SOURCE SELECT = 000 | ||
74 | * CLEAR INTERRUPT FLAG | ||
75 | * ENABLE INTERRUPT = 1 | ||
76 | * ADOUT_DRIVE = 00 | ||
77 | * ADCLK_SEL = 011 (busclk/8) | ||
78 | */ | ||
79 | |||
80 | ADCONFIG = (1<<10)|(1<<7)|(1<<6)|(1<<1)|(1<<0); | ||
81 | |||
82 | /* ADC interrupt level 4.0 */ | ||
83 | or_l((4<<28), &INTPRI8); | ||
84 | } | ||