1 /* Copyright (C) 2012-2013 Czech Technical University in Prague
5 * - Carlos Jenkins <carlos@jenkins.co.cr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * RPP driver implementation for ADC.
31 // Semaphore for ADC conversion
32 xSemaphoreHandle adcSemaphore_ADC1GRP1;
38 vSemaphoreCreateBinary(adcSemaphore_ADC1GRP1);
46 * Function called by ADC interrupt handler, stores data from ADC
48 * If conversion has finished on ADC, store measured data and detect weather right number of channels was measured.
49 * If memory overrun was detected, set appropriate flag, reset ADC FIFO to be allow future measurement.
51 * @param[in] adc Pointer to ADC module:
52 * - adcREG1: ADC1 module pointer
53 * - adcREG2: ADC2 module pointer
54 * @param[in] group Hardware group of ADC module:
55 * - adcGROUP0: ADC event group
56 * - adcGROUP1: ADC group 1
57 * - adcGROUP2: ADC group 2
59 void adcNotification(adcBASE_t *adc, uint32_t group)
61 if(adcIsConversionComplete(adc, group) == ADC_CONVERSION_IS_FINISHED) {
67 // Group0 is unused on RPP
70 xSemaphoreGiveFromISR(adcSemaphore_ADC1GRP1, NULL);
73 // Group2 is unused on RPP
80 // Group0 is unused on RPP
83 // Group1 is unused on RPP
86 // Group2 is unused on RPP
94 uint32_t drv_adc_generic_read(adcBASE_t *adc, uint32_t group,
95 xSemaphoreHandle adcSemaphore, adcData_t* data)
99 adcMidPointCalibration(adc);
102 adcEnableNotification(adc, group);
103 adcStartConversion(adc, group);
105 // Wait for conversion to complete
106 xSemaphoreTake(adcSemaphore, portMAX_DELAY);
107 adcDisableNotification(adc, group);
110 uint32_t channels = adcGetData(adc, group, data);
112 // Check if memory overrun
113 if(adcIsFifoFull(adc, group) == ADC_FIFO_OVERFLOW) {
114 // FIXME Should report somehow.
115 adcResetFiFo(adc, group);
122 uint32_t drv_adc_read(adcData_t* data)
124 return drv_adc_generic_read(adcREG1,
126 adcSemaphore_ADC1GRP1,
131 // FIXME make it work again
132 uint32_t adc_get_port_val(uint32_t* config, uint32_t num_channels,
136 adcBASE_t* adcReg = (adcBASE_t *)config[0];
137 uint32_t adcGroup = config[1];
139 adcData.adc_data = adc_data_origin;
140 adcData.ch_count = num_channels;
141 if (read_adc(adcReg, adcGroup) == 1)
144 for (i = 0; i < num_channels; i++) {
145 values[i] = adcData.adc_data[i].value;
146 values[i+num_channels] = adcData.adc_data[i].id;
148 adcData.adc_data = NULL;