amiro-os / kernel / patches / Introduced-support-for-the-ADC-analog-watchdog.patch @ 5d7e6f9e
History | View | Annotate | Download (4.128 KB)
1 |
From d5e13e540dec58ece6de3d246a166185418f3fd3 Mon Sep 17 00:00:00 2001
|
---|---|
2 |
From: =?UTF-8?q?Thomas=20Sch=C3=B6pping?= <tschoepp@cit-ec.uni-bielefeld.de>
|
3 |
Date: Mon, 12 Jun 2017 17:27:13 +0200
|
4 |
Subject: [PATCH] Introduced support for the ADC analog watchdog (ADCv2 only).
|
5 |
|
6 |
---
|
7 |
os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c | 20 +++++++++++++++++--- |
8 |
os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h | 21 ++++++++++++++++++++- |
9 |
2 files changed, 37 insertions(+), 4 deletions(-) |
10 |
|
11 |
diff --git a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c
|
12 |
index b2e651e..d5875ee 100644
|
13 |
--- a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c
|
14 |
+++ b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.c
|
15 |
@@ -124,7 +124,11 @@ OSAL_IRQ_HANDLER(STM32_ADC_HANDLER) {
|
16 |
if (ADCD1.grpp != NULL) |
17 |
_adc_isr_error_code(&ADCD1, ADC_ERR_OVERFLOW); |
18 |
} |
19 |
- /* TODO: Add here analog watchdog handling.*/
|
20 |
+ if (sr & ADC_SR_AWD) {
|
21 |
+ if (ADCD1.grpp != NULL) {
|
22 |
+ _adc_isr_error_code(&ADCD1, ADC_ERR_WATCHDOG);
|
23 |
+ }
|
24 |
+ }
|
25 |
#if defined(STM32_ADC_ADC1_IRQ_HOOK)
|
26 |
STM32_ADC_ADC1_IRQ_HOOK |
27 |
#endif
|
28 |
@@ -141,7 +145,11 @@ OSAL_IRQ_HANDLER(STM32_ADC_HANDLER) {
|
29 |
if (ADCD2.grpp != NULL) |
30 |
_adc_isr_error_code(&ADCD2, ADC_ERR_OVERFLOW); |
31 |
} |
32 |
- /* TODO: Add here analog watchdog handling.*/
|
33 |
+ if (sr & ADC_SR_AWD) {
|
34 |
+ if (ADCD2.grpp != NULL) {
|
35 |
+ _adc_isr_error_code(&ADCD2, ADC_ERR_WATCHDOG);
|
36 |
+ }
|
37 |
+ }
|
38 |
#if defined(STM32_ADC_ADC2_IRQ_HOOK)
|
39 |
STM32_ADC_ADC2_IRQ_HOOK |
40 |
#endif
|
41 |
@@ -158,7 +166,11 @@ OSAL_IRQ_HANDLER(STM32_ADC_HANDLER) {
|
42 |
if (ADCD3.grpp != NULL) |
43 |
_adc_isr_error_code(&ADCD3, ADC_ERR_OVERFLOW); |
44 |
} |
45 |
- /* TODO: Add here analog watchdog handling.*/
|
46 |
+ if (sr & ADC_SR_AWD) {
|
47 |
+ if (ADCD3.grpp != NULL) {
|
48 |
+ _adc_isr_error_code(&ADCD3, ADC_ERR_WATCHDOG);
|
49 |
+ }
|
50 |
+ }
|
51 |
#if defined(STM32_ADC_ADC3_IRQ_HOOK)
|
52 |
STM32_ADC_ADC3_IRQ_HOOK |
53 |
#endif
|
54 |
@@ -350,6 +362,8 @@ void adc_lld_start_conversion(ADCDriver *adcp) { |
55 |
adcp->adc->SR = 0;
|
56 |
adcp->adc->SMPR1 = grpp->smpr1; |
57 |
adcp->adc->SMPR2 = grpp->smpr2; |
58 |
+ adcp->adc->HTR = grpp->htr;
|
59 |
+ adcp->adc->LTR = grpp->ltr;
|
60 |
adcp->adc->SQR1 = grpp->sqr1 | ADC_SQR1_NUM_CH(grpp->num_channels); |
61 |
adcp->adc->SQR2 = grpp->sqr2; |
62 |
adcp->adc->SQR3 = grpp->sqr3; |
63 |
diff --git a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h
|
64 |
index 13df506..fa266f0 100644
|
65 |
--- a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h
|
66 |
+++ b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h
|
67 |
@@ -313,7 +313,8 @@ typedef uint16_t adc_channels_num_t; |
68 |
*/ |
69 |
typedef enum { |
70 |
ADC_ERR_DMAFAILURE = 0, /**< DMA operations failure. */ |
71 |
- ADC_ERR_OVERFLOW = 1 /**< ADC overflow condition. */
|
72 |
+ ADC_ERR_OVERFLOW = 1, /**< ADC overflow condition. */
|
73 |
+ ADC_ERR_WATCHDOG = 2 /**< ADC watchdog condition. */
|
74 |
} adcerror_t; |
75 |
|
76 |
/**
|
77 |
@@ -392,6 +393,16 @@ typedef struct { |
78 |
*/ |
79 |
uint32_t smpr2; |
80 |
/**
|
81 |
+ * @brief ADC watchdog high threshold register.
|
82 |
+ * @details This field defines the high threshold of the analog watchdog.
|
83 |
+ */
|
84 |
+ uint16_t htr;
|
85 |
+ /**
|
86 |
+ * @brief ADC watchdog low threshold register.
|
87 |
+ * @details This field defines the low threshold of the analog watchdog.
|
88 |
+ */
|
89 |
+ uint16_t ltr;
|
90 |
+ /**
|
91 |
* @brief ADC SQR1 register initialization data. |
92 |
* @details Conversion group sequence 13...16 + sequence length. |
93 |
*/ |
94 |
@@ -531,6 +542,14 @@ struct ADCDriver { |
95 |
#define ADC_SMPR1_SMP_VBAT(n) ((n) << 24) /**< @brief VBAT sampling time. */ |
96 |
/** @} */
|
97 |
|
98 |
+/**
|
99 |
+ * @name Threshold settings helper macros
|
100 |
+ * @{
|
101 |
+ */
|
102 |
+#define ADC_HTR(n) ((n > ADC_HTR_HT) ? ADC_HTR_HT : n) /**< @brief High threshold limitation. */
|
103 |
+#define ADC_LTR(n) ((n > ADC_LTR_LT) ? ADC_LTR_LT : n) /**< @brief Low threshold limitation. */
|
104 |
+/** @} */
|
105 |
+
|
106 |
/*===========================================================================*/
|
107 |
/* External declarations. */
|
108 |
/*===========================================================================*/
|
109 |
--
|
110 |
2.7.4
|
111 |
|