6e2f1aeaf38f3f40e30e1c64f94d6f7ea0468349
[bertos.git] / drv / adc.c
1 /**
2  * \file
3  * <!--
4  * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
5  * This file is part of DevLib - See README.devlib for information.
6  * -->
7  *
8  * \version $Id$
9  *
10  * \brief ADC driver (implementation)
11  *
12  * \version $Id$
13  * \author Francesco Sacchi <batt@develer.com>
14  */
15
16 /*#*
17  *#* $Log$
18  *#* Revision 1.4  2006/09/20 17:32:46  marco
19  *#* Use MOD_* macros instead of DB.
20  *#*
21  *#* Revision 1.3  2006/09/13 18:30:07  bernie
22  *#* Add a FIXME.
23  *#*
24  *#* Revision 1.2  2006/07/19 12:56:25  bernie
25  *#* Convert to new Doxygen style.
26  *#*
27  *#* Revision 1.1  2005/06/27 21:28:31  bernie
28  *#* Import ADC driver.
29  *#*
30  *#*/
31
32
33 #include <drv/adc.h>
34 #include <drv/timer.h>
35
36 // FIXME: move CPU specific part to adc_CPU.c
37 #include <hw_adc.h>
38
39 #include <cfg/debug.h>     // ASSERT()
40 #include <cfg/macros.h>    // MIN()
41 #include <cfg/compiler.h>
42 #include <cfg/module.h>
43
44 /**
45  * Read the ADC channel \a ch.
46  */
47 adcread_t adc_read(uint16_t ch)
48 {
49         ASSERT(ch <= (uint16_t)ADC_MUX_MAXCH);
50         ch = MIN(ch, (uint16_t)ADC_MUX_MAXCH);
51
52         adc_hw_select_ch(ch);
53
54         return(adc_hw_read());
55 }
56
57 MOD_DEFINE(adc)
58
59 /**
60  * Initialize the ADC hardware.
61  */
62 void adc_init(void)
63 {
64         cpuflags_t flags;
65         IRQ_SAVE_DISABLE(flags);
66
67         ADC_HW_INIT;
68         IRQ_RESTORE(flags);
69
70         MOD_INIT(adc);
71 }