aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_adc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_adc.c')
-rw-r--r--lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_adc.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_adc.c b/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_adc.c
new file mode 100644
index 000000000..431d95914
--- /dev/null
+++ b/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_adc.c
@@ -0,0 +1,110 @@
1/*
2 ChibiOS/RT - Copyright (C) 2014 Uladzimir Pylinsky aka barthess
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#include "ch.h"
18#include "hal.h"
19
20#define ADC_NUM_CHANNELS 6
21#define ADC_BUF_DEPTH 8
22
23/* human readable names */
24#define ADC_CURRENT_SENS ADC_CHANNEL_IN10
25#define ADC_MAIN_SUPPLY ADC_CHANNEL_IN11
26#define ADC_6V_SUPPLY ADC_CHANNEL_IN12
27#define ADC_AN33_0 ADC_CHANNEL_IN13
28#define ADC_AN33_1 ADC_CHANNEL_IN14
29#define ADC_AN33_2 ADC_CHANNEL_IN15
30
31#define ADC_CURRENT_SENS_OFFSET (ADC_CHANNEL_IN10 - 10)
32#define ADC_MAIN_VOLTAGE_OFFSET (ADC_CHANNEL_IN11 - 10)
33#define ADC_6V_OFFSET (ADC_CHANNEL_IN12 - 10)
34#define ADC_AN33_0_OFFSET (ADC_CHANNEL_IN13 - 10)
35#define ADC_AN33_1_OFFSET (ADC_CHANNEL_IN14 - 10)
36#define ADC_AN33_2_OFFSET (ADC_CHANNEL_IN15 - 10)
37
38static void adcerrorcallback(ADCDriver *adcp, adcerror_t err);
39static void adccallback(ADCDriver *adcp, adcsample_t *buffer, size_t n);
40
41static adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH];
42
43static uint32_t ints = 0;
44static uint32_t errors = 0;
45
46static const ADCConversionGroup adccg = {
47 TRUE,
48 ADC_NUM_CHANNELS,
49 adccallback,
50 adcerrorcallback,
51 0, /* CR1 */
52 ADC_CR2_SWSTART, /* CR2 */
53 ADC_SMPR1_SMP_AN10(ADC_SAMPLE_3) |
54 ADC_SMPR1_SMP_AN11(ADC_SAMPLE_3) |
55 ADC_SMPR1_SMP_AN12(ADC_SAMPLE_3) |
56 ADC_SMPR1_SMP_AN13(ADC_SAMPLE_3) |
57 ADC_SMPR1_SMP_AN14(ADC_SAMPLE_3) |
58 ADC_SMPR1_SMP_AN15(ADC_SAMPLE_3),
59 0, /* SMPR2 */
60 0,
61 0,
62 ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS),
63 0,
64 ADC_SQR3_SQ6_N(ADC_AN33_2) |
65 ADC_SQR3_SQ5_N(ADC_AN33_1) |
66 ADC_SQR3_SQ4_N(ADC_AN33_0) |
67 ADC_SQR3_SQ3_N(ADC_6V_SUPPLY) |
68 ADC_SQR3_SQ2_N(ADC_MAIN_SUPPLY) |
69 ADC_SQR3_SQ1_N(ADC_CURRENT_SENS)
70};
71
72static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) {
73 (void)adcp;
74 (void)err;
75
76 osalSysHalt("");
77}
78
79static void adccallback(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
80 (void)adcp;
81 (void)buffer;
82 (void)n;
83 ints++;
84}
85
86/*
87 *
88 */
89void dma_storm_adc_start(void){
90 ints = 0;
91 errors = 0;
92
93 /* Activates the ADC1 driver and the temperature sensor.*/
94 adcStart(&ADCD1, NULL);
95 adcSTM32EnableTSVREFE();
96
97 /* Starts an ADC continuous conversion.*/
98 adcStartConversion(&ADCD1, &adccg, samples, ADC_BUF_DEPTH);
99}
100
101/*
102 *
103 */
104uint32_t dma_storm_adc_stop(void){
105 adcStopConversion(&ADCD1);
106 adcSTM32DisableTSVREFE();
107 adcStop(&ADCD1);
108 return ints;
109}
110