Revision 738a28c8

View differences:

kernel/patches/Introduced-support-for-the-ADC-analog-watchdog.patch
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

  
kernel/patches/RTCv1-fixed-illegal-type-casts.patch
1
From 6a763db09751ded7e11e531825c1c12d9fbecca9 Mon Sep 17 00:00:00 2001
2
From: =?UTF-8?q?Thomas=20Sch=C3=B6pping?= <tschoepp@cit-ec.uni-bielefeld.de>
3
Date: Fri, 13 Jul 2018 16:21:27 +0200
4
Subject: [PATCH] RTCv1: Fixed illegal type casts (from pointer to arithmetic type to pointer to real type).
5

  
6
---
7
 os/hal/ports/STM32/LLD/RTCv1/hal_rtc_lld.c | 5 +++--
8
 1 file changed, 3 insertions(+), 2 deletions(-)
9

  
10
diff --git a/os/hal/ports/STM32/LLD/RTCv1/hal_rtc_lld.c b/os/hal/ports/STM32/LLD/RTCv1/hal_rtc_lld.c
11
index df4b7e7..fedce93 100644
12
--- a/os/hal/ports/STM32/LLD/RTCv1/hal_rtc_lld.c
13
+++ b/os/hal/ports/STM32/LLD/RTCv1/hal_rtc_lld.c
14
@@ -130,14 +130,15 @@ static void rtc_decode(uint32_t tv_sec,
15
                        RTCDateTime *timespec) {
16
   struct tm tim;
17
   struct tm *t;
18
+  const time_t time = tv_sec;
19
 
20
   /* If the conversion is successful the function returns a pointer
21
      to the object the result was written into.*/
22
 #if defined(__GNUC__) || defined(__CC_ARM)
23
-  t = localtime_r((time_t *)&(tv_sec), &tim);
24
+  t = localtime_r(&time, &tim);
25
   osalDbgAssert(t != NULL, "conversion failed");
26
 #else
27
-  t = localtime(&tv_sec);
28
+  t = localtime(&time);
29
   memcpy(&tim, t, sizeof(struct tm));
30
 #endif
31
 
32
-- 
33
2.7.4
34

  

Also available in: Unified diff