at91_adc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (C) 2004 by Ole Reinhardt <ole.reinhardt@embedded-it.de>,
  3. * Kernelconcepts http://www.embedded-it.de
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the copyright holders nor the names of
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  22. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  26. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * For additional information see http://www.ethernut.de/
  32. *
  33. */
  34. /*
  35. * $Log$
  36. * Revision 1.4 2009/01/17 11:26:47 haraldkipp
  37. * Getting rid of two remaining BSD types in favor of stdint.
  38. * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
  39. *
  40. * Revision 1.3 2008/08/11 06:59:59 haraldkipp
  41. * BSD types replaced by stdint types (feature request #1282721).
  42. *
  43. * Revision 1.2 2007/12/09 22:12:05 olereinhardt
  44. * Added cvs log tag
  45. *
  46. */
  47. /*!
  48. * \file include/dev/at91_adc.h
  49. * \brief Header for AT91 Adc driver
  50. */
  51. /*@{*/
  52. #ifndef _AT91_ADC_H_
  53. #define _AT91_ADC_H_
  54. /*!
  55. * \enum adc_moded_type dev/at91_adc.h
  56. * \brief enum declaring possible ADC modes
  57. *
  58. * ADC_OFF:
  59. * Switch off adc and enable slep mode
  60. * FREE_RUNNING_x:
  61. * This is a pseudo free running mode as we don't want to use a
  62. * dedicated timer (0..3) for this purpose we retrigger sampling in
  63. * the interrupt handler. Starting when ADC_start_conversion() is called.
  64. * SINGLE_CONVERSION:
  65. * Single-conversion mode. One sample taken every time
  66. * ADC_start_conversion() is called.
  67. *
  68. */
  69. typedef enum adc_mode_type
  70. {
  71. ADC_OFF,
  72. FREE_RUNNING_T0,
  73. FREE_RUNNING_T1,
  74. FREE_RUNNING_T2,
  75. FREE_RUNNING_EXT,
  76. SINGLE_CONVERSION
  77. } TADCMode;
  78. /*!
  79. * \enum adc_channel_type dev/at91_adc.h
  80. * \brief enum declaring possible ADC channels
  81. */
  82. typedef enum adc_channel_type
  83. {
  84. ADC0=0,
  85. ADC1=1,
  86. ADC2=2,
  87. ADC3=3,
  88. ADC4=4,
  89. ADC5=5,
  90. ADC6=6,
  91. ADC7=7,
  92. ADC_MAX_CHANNEL = 8
  93. } TADCChannel;
  94. /* Function prototypes */
  95. void ADCInit(void);
  96. // ADCStartConversion
  97. //
  98. // Begins ADC conversion. The conversion will process all
  99. // enabled channels one after the other.
  100. //
  101. // NOTE: Converted values from the ADC are stored
  102. // in a local buffer. The user must call
  103. // ADC_read to obtain these values.
  104. //
  105. // pre: none
  106. // post: The ADC has started conversion. Completion of
  107. // any conversions is not guaranteed.
  108. void ADCStartConversion(void);
  109. // ADCSetPrescale
  110. //
  111. // Allows setting of ADC clock prescalar (ADC rate).
  112. // The ADC rate is given by the system clock rate
  113. // divided by the prescalar value. Possible prescalar
  114. // values range from 2-128
  115. //
  116. // pre: "prescalar" is a valid ADC reference from the
  117. // choices given above
  118. // post: ADC prescalar set to desired choice
  119. void ADCSetPrescale(uint32_t prescale);
  120. // ADCEnableChannel
  121. // ADCDisableChannel
  122. //
  123. // Enables/disables a channel to be sampled on the next conversion
  124. //
  125. // pre: none
  126. // post: Channel is selected / deselected. Next conversion will respect these settings
  127. void ADCDisableChannel(TADCChannel channel);
  128. void ADCEnableChannel(TADCChannel channel);
  129. // ADCSetMode
  130. //
  131. // Possible values:
  132. // - ADC_OFF
  133. // - SINGLE_CONVERSION
  134. // - FREE_RUNNING_T0
  135. // - FREE_RUNNING_T1
  136. // - FREE_RUNNING_T2
  137. // These depend on a timer t0 / t1 / t2
  138. // - FREE_RUNNING_EXT
  139. // External trigger
  140. //
  141. // pre: none
  142. // post: Set adc conversion to the selected value.
  143. void ADCSetMode(TADCMode mode);
  144. // AFCBufRead
  145. //
  146. // Reads the next sampled value of the given channel from the buffer.
  147. //
  148. // pre: Sample completed
  149. // post: Value will be removed from buffer
  150. int ADCBufRead(uint16_t channel, uint16_t * read);
  151. #endif
  152. /*@}*/