ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file templates/adc_lld.h 00029 * @brief ADC Driver subsystem low level driver header template. 00030 * 00031 * @addtogroup ADC_LLD 00032 * @{ 00033 */ 00034 00035 #ifndef _ADC_LLD_H_ 00036 #define _ADC_LLD_H_ 00037 00038 #if CH_HAL_USE_ADC || defined(__DOXYGEN__) 00039 00040 /*===========================================================================*/ 00041 /* Driver constants. */ 00042 /*===========================================================================*/ 00043 00044 /*===========================================================================*/ 00045 /* Driver pre-compile time settings. */ 00046 /*===========================================================================*/ 00047 00048 /*===========================================================================*/ 00049 /* Derived constants and error checks. */ 00050 /*===========================================================================*/ 00051 00052 #if !CH_USE_SEMAPHORES 00053 #error "the ADC driver requires CH_USE_SEMAPHORES" 00054 #endif 00055 00056 /*===========================================================================*/ 00057 /* Driver data structures and types. */ 00058 /*===========================================================================*/ 00059 00060 /** 00061 * @brief ADC sample data type. 00062 */ 00063 typedef uint16_t adcsample_t; 00064 00065 /** 00066 * @brief Channels number in a conversion group. 00067 */ 00068 typedef uint16_t adc_channels_num_t; 00069 00070 /** 00071 * @brief ADC notification callback type. 00072 * 00073 * @param[in] buffer pointer to the most recent samples data 00074 * @param[in] n number of buffer rows available starting from @p buffer 00075 */ 00076 typedef void (*adccallback_t)(adcsample_t *buffer, size_t n); 00077 00078 /** 00079 * @brief Conversion group configuration structure. 00080 * @details This implementation-dependent structure describes a conversion 00081 * operation. 00082 */ 00083 typedef struct { 00084 /** 00085 * @brief Enables the circular buffer mode for the group. 00086 */ 00087 bool_t acg_circular; 00088 /** 00089 * @brief Number of the analog channels belonging to the conversion group. 00090 */ 00091 adc_channels_num_t acg_num_channels; 00092 /* End of the mandatory fields.*/ 00093 } ADCConversionGroup; 00094 00095 /** 00096 * @brief Driver configuration structure. 00097 * @note It could be empty on some architectures. 00098 */ 00099 typedef struct { 00100 00101 } ADCConfig; 00102 00103 /** 00104 * @brief Structure representing an ADC driver. 00105 */ 00106 typedef struct { 00107 /** 00108 * @brief Driver state. 00109 */ 00110 adcstate_t ad_state; 00111 /** 00112 * @brief Current configuration data. 00113 */ 00114 const ADCConfig *ad_config; 00115 /** 00116 * @brief Synchronization semaphore. 00117 */ 00118 Semaphore ad_sem; 00119 /** 00120 * @brief Current callback function or @p NULL. 00121 */ 00122 adccallback_t ad_callback; 00123 /** 00124 * @brief Current samples buffer pointer or @p NULL. 00125 */ 00126 adcsample_t *ad_samples; 00127 /** 00128 * @brief Current samples buffer depth or @p 0. 00129 */ 00130 size_t ad_depth; 00131 /** 00132 * @brief Current conversion group pointer or @p NULL. 00133 */ 00134 const ADCConversionGroup *ad_grpp; 00135 /* End of the mandatory fields.*/ 00136 } ADCDriver; 00137 00138 /*===========================================================================*/ 00139 /* Driver macros. */ 00140 /*===========================================================================*/ 00141 00142 /*===========================================================================*/ 00143 /* External declarations. */ 00144 /*===========================================================================*/ 00145 00146 #ifdef __cplusplus 00147 extern "C" { 00148 #endif 00149 void adc_lld_init(void); 00150 void adc_lld_start(ADCDriver *adcp); 00151 void adc_lld_stop(ADCDriver *adcp); 00152 void adc_lld_start_conversion(ADCDriver *adcp); 00153 void adc_lld_stop_conversion(ADCDriver *adcp); 00154 #ifdef __cplusplus 00155 } 00156 #endif 00157 00158 #endif /* CH_HAL_USE_ADC */ 00159 00160 #endif /* _ADC_LLD_H_ */ 00161 00162 /** @} */