aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabien Poussin <fabien.poussin@gmail.com>2017-02-07 15:20:28 +0100
committerFabien Poussin <fabien.poussin@gmail.com>2017-02-07 15:20:28 +0100
commitf4687bd298290f54574f213406c21b6d7c38511c (patch)
tree784baa9adce8d283c2fe6f39d820e5234f24226a
parent7059c87ab4f237187bab6db709280de3a6b8ea6b (diff)
downloadChibiOS-Contrib-f4687bd298290f54574f213406c21b6d7c38511c.tar.gz
ChibiOS-Contrib-f4687bd298290f54574f213406c21b6d7c38511c.tar.bz2
ChibiOS-Contrib-f4687bd298290f54574f213406c21b6d7c38511c.zip
[Comp] Cleaning example, removing dependencies and adding checks.
-rw-r--r--os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.c222
-rw-r--r--os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.h50
-rw-r--r--testhal/STM32/STM32F3xx/COMP/main.c48
-rw-r--r--testhal/STM32/STM32F3xx/COMP/mcuconf_community.h21
4 files changed, 164 insertions, 177 deletions
diff --git a/os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.c b/os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.c
index 5289d50..0c96185 100644
--- a/os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.c
+++ b/os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.c
@@ -122,86 +122,156 @@ void comp_lld_init(void) {
#if STM32_COMP_USE_COMP1
/* Driver initialization.*/
compObjectInit(&COMPD1);
- COMPD1.comp = COMP;
+ COMPD1.reg = COMP;
+ COMPD1.reg->CSR = 0;
+#if STM32_COMP_USE_INTERRUPTS
+ nvicEnableVector(COMP1_2_3_IRQn, STM32_COMP_1_2_3_IRQ_PRIORITY);
+#endif
#endif
#if STM32_COMP_USE_COMP2
/* Driver initialization.*/
compObjectInit(&COMPD2);
- COMPD2.comp = COMP2;
+ COMPD2.reg = COMP2;
+ COMPD2.reg->CSR = 0;
+#if STM32_COMP_USE_INTERRUPTS
+ nvicEnableVector(COMP1_2_3_IRQn, STM32_COMP_1_2_3_IRQ_PRIORITY);
+#endif
#endif
#if STM32_COMP_USE_COMP3
/* Driver initialization.*/
compObjectInit(&COMPD3);
- COMPD3.comp = COMP3;
+ COMPD3.reg = COMP3;
+ COMPD3.reg->CSR = 0;
+#if STM32_COMP_USE_INTERRUPTS
+ nvicEnableVector(COMP1_2_3_IRQn, STM32_COMP_1_2_3_IRQ_PRIORITY);
+#endif
#endif
#if STM32_COMP_USE_COMP4
/* Driver initialization.*/
compObjectInit(&COMPD4);
- COMPD4.comp = COMP4;
+ COMPD4.reg = COMP4;
+ COMPD4.reg->CSR = 0;
+#if STM32_COMP_USE_INTERRUPTS
+ nvicEnableVector(COMP4_5_6_IRQn, STM32_COMP_1_2_3_IRQ_PRIORITY);
+#endif
#endif
#if STM32_COMP_USE_COMP5
/* Driver initialization.*/
compObjectInit(&COMPD5);
- COMPD8.comp = COMP5;
+ COMPD5.reg = COMP5;
+ COMPD5.reg->CSR = 0;
+#if STM32_COMP_USE_INTERRUPTS
+ nvicEnableVector(COMP4_5_6_IRQn, STM32_COMP_1_2_3_IRQ_PRIORITY);
+#endif
#endif
#if STM32_COMP_USE_COMP6
/* Driver initialization.*/
compObjectInit(&COMPD6);
- COMPD6.comp = COMP6;
+ COMPD6.reg = COMP6;
+ COMPD6.reg->CSR = 0;
+#if STM32_COMP_USE_INTERRUPTS
+ nvicEnableVector(COMP4_5_6_IRQn, STM32_COMP_1_2_3_IRQ_PRIORITY);
+#endif
#endif
#if STM32_COMP_USE_COMP7
/* Driver initialization.*/
compObjectInit(&COMPD7);
- COMPD7.comp = COMP7;
+ COMPD7.reg = COMP7;
+ COMPD7.reg->CSR = 0;
+#if STM32_COMP_USE_INTERRUPTS
+ nvicEnableVector(COMP7_IRQn, STM32_COMP_7_IRQ_PRIORITY);
+#endif
#endif
}
-#if STM32_COMP_USE_INTERRUPTS
-static void comp_lld_cb(EXTDriver *extp, expchannel_t channel) {
- (void) extp;
- switch (channel) {
+/**
+ * @brief COMP1, COMP2, COMP3 interrupt handler.
+ *
+ * @isr
+ */
+OSAL_IRQ_HANDLER(Vector140) {
+ uint32_t pr;
+
+ OSAL_IRQ_PROLOGUE();
+ pr = EXTI->PR;
+ pr &= EXTI->IMR & ((1U << 21) | (1U << 22) | (1U << 29));
+ EXTI->PR = pr;
#if STM32_COMP_USE_COMP1
- case 21:
- COMPD1.config->cb(&COMPD1);
+ if (pr & (1U << 21) && COMPD1.config->cb != NULL)
+ COMPD1.config->cb(&COMPD1);
#endif
#if STM32_COMP_USE_COMP2
- case 22:
- COMPD2.config->cb(&COMPD2);
+ if (pr & (1U << 22) && COMPD2.config->cb != NULL)
+ COMPD2.config->cb(&COMPD2);
#endif
#if STM32_COMP_USE_COMP3
- case 29:
- COMPD3.config->cb(&COMPD3);
+ if (pr & (1U << 29) && COMPD3.config->cb != NULL)
+ COMPD3.config->cb(&COMPD3);
#endif
+
+ OSAL_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief COMP4, COMP5, COMP6 interrupt handler.
+ *
+ * @isr
+ */
+OSAL_IRQ_HANDLER(Vector144) {
+ uint32_t pr;
+
+ OSAL_IRQ_PROLOGUE();
+
+ pr = EXTI->PR;
+ pr &= EXTI->IMR & ((1U << 30) | (1U << 31));
+ EXTI->PR = pr;
#if STM32_COMP_USE_COMP4
- case 30:
- COMPD4.config->cb(&COMPD4);
+ if (pr & (1U << 30) && COMPD4.config->cb != NULL)
+ COMPD4.config->cb(&COMPD4);
#endif
#if STM32_COMP_USE_COMP5
- case 31:
- COMPD5.config->cb(&COMPD5);
+ if (pr & (1U << 31) && COMPD5.config->cb != NULL)
+ COMPD5.config->cb(&COMPD5);
#endif
+
#if STM32_COMP_USE_COMP6
- case 32:
- COMPD6.config->cb(&COMPD6);
+ pr = EXTI->PR2 & EXTI->IMR2 & (1U << 0);
+ EXTI->PR2 = pr;
+ if (pr & (1U << 0) && COMPD6.config->cb != NULL)
+ COMPD6.config->cb(&COMPD6);
#endif
+
+ OSAL_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief COMP7 interrupt handler.
+ *
+ * @isr
+ */
+OSAL_IRQ_HANDLER(Vector148) {
+ uint32_t pr2;
+
+ OSAL_IRQ_PROLOGUE();
+
+ pr2 = EXTI->PR2;
+ pr2 = EXTI->IMR & (1U << 1);
+ EXTI->PR2 = pr2;
#if STM32_COMP_USE_COMP7
- case 33:
- COMPD7.config->cb(&COMPD7);
+ if (pr2 & (1U << 1) && COMPD7.config->cb != NULL)
+ COMPD7.config->cb(&COMPD7);
#endif
- default:
- return;
- }
+ OSAL_IRQ_EPILOGUE();
}
-#endif
/**
* @brief Configures and activates the COMP peripheral.
@@ -213,58 +283,11 @@ static void comp_lld_cb(EXTDriver *extp, expchannel_t channel) {
void comp_lld_start(COMPDriver *compp) {
// Apply CSR Execpt the enable bit.
- compp->comp->CSR = compp->config->csr & ~COMP_CSR_COMPxEN;
+ compp->reg->CSR = compp->config->csr & ~COMP_CSR_COMPxEN;
// Inverted output
if (compp->config->mode == COMP_OUTPUT_INVERTED)
- compp->comp->CSR |= COMP_CSR_COMPxPOL;
-
- EXTChannelConfig chn_cfg = {EXT_CH_MODE_BOTH_EDGES, comp_lld_cb};
- EXTConfig *cfg = (EXTConfig*)EXTD1.config;
-
-
-#if STM32_COMP_USE_COMP1 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD1 == compp) {
- cfg->channels[21] = chn_cfg;
- ext_lld_channel_enable(&EXTD1, 21);
- }
-#endif
-#if STM32_COMP_USE_COMP2 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD2 == compp) {
- cfg->channels[22] = chn_cfg;
- ext_lld_channel_enable(&EXTD1, 22);
- }
-#endif
-#if STM32_COMP_USE_COMP3 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD3 == compp) {
- cfg->channels[29] = chn_cfg;
- ext_lld_channel_enable(&EXTD1, 29);
- }
-#endif
-#if STM32_COMP_USE_COMP4 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD4 == compp) {
- cfg->channels[30] = chn_cfg;
- ext_lld_channel_enable(&EXTD1, 30);
- }
-#endif
-#if STM32_COMP_USE_COMP5 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD5 == compp) {
- cfg->channels[31] = chn_cfg;
- ext_lld_channel_enable(&EXTD1, 31);
- }
-#endif
-#if STM32_COMP_USE_COMP6 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD6 == compp) {
- cfg->channels[32] = chn_cfg;
- ext_lld_channel_enable(&EXTD1, 32);
- }
-#endif
-#if STM32_COMP_USE_COMP7 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD7 == compp) {
- cfg->channels[33] = chn_cfg;
- ext_lld_channel_enable(&EXTD1, 33);
- }
-#endif
+ compp->reg->CSR |= COMP_CSR_COMPxPOL;
}
@@ -279,42 +302,7 @@ void comp_lld_stop(COMPDriver *compp) {
if (compp->state == COMP_READY) {
-
-#if STM32_COMP_USE_COMP1 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD1 == compp) {
- ext_lld_channel_disable(&EXTD1, 21);
- }
-#endif
-#if STM32_COMP_USE_COMP2 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD2 == compp) {
- ext_lld_channel_disable(&EXTD1, 22);
- }
-#endif
-#if STM32_COMP_USE_COMP3 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD3 == compp) {
- ext_lld_channel_disable(&EXTD1, 29);
- }
-#endif
-#if STM32_COMP_USE_COMP4 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD4 == compp) {
- ext_lld_channel_disable(&EXTD1, 30);
- }
-#endif
-#if STM32_COMP_USE_COMP5 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD5 == compp) {
- ext_lld_channel_disable(&EXTD1, 31);
- }
-#endif
-#if STM32_COMP_USE_COMP6 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD6 == compp) {
- ext_lld_channel_disable(&EXTD1, 32);
- }
-#endif
-#if STM32_COMP_USE_COMP7 && STM32_COMP_USE_INTERRUPTS
- if (&COMPD7 == compp) {
- ext_lld_channel_disable(&EXTD1, 33);
- }
-#endif
+ compp->reg->CSR = 0;
}
}
@@ -327,8 +315,7 @@ void comp_lld_stop(COMPDriver *compp) {
*/
void comp_lld_enable(COMPDriver *compp) {
- compp->comp->CSR |= COMP_CSR_COMPxEN; /* Enable */
-
+ compp->reg->CSR |= COMP_CSR_COMPxEN; /* Enable */
}
/**
@@ -340,8 +327,7 @@ void comp_lld_enable(COMPDriver *compp) {
*/
void comp_lld_disable(COMPDriver *compp) {
- compp->comp->CSR &= ~COMP_CSR_COMPxEN; /* Disable */
-
+ compp->reg->CSR &= ~COMP_CSR_COMPxEN; /* Disable */
}
#endif /* HAL_USE_COMP */
diff --git a/os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.h b/os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.h
index 0ecdca2..70868c0 100644
--- a/os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.h
+++ b/os/hal/ports/STM32/LLD/COMPv1/hal_comp_lld.h
@@ -34,32 +34,26 @@
/* Driver constants. */
/*===========================================================================*/
-#if defined(STM32F303x8)
-
+#if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F303x8) \
+|| defined(STM32F318xx) || defined(STM32F328xx) || defined(STM32F334x8)
#define STM32_HAS_COMP1 FALSE
#define STM32_HAS_COMP2 TRUE
#define STM32_HAS_COMP3 FALSE
#define STM32_HAS_COMP4 TRUE
#define STM32_HAS_COMP5 FALSE
-#define STM32_HAS_COMP6 FALSE
+#define STM32_HAS_COMP6 TRUE
#define STM32_HAS_COMP7 FALSE
-#endif
-
-#if defined(STM32F303xC)
-
+#elif defined(STM32F302xc) || defined(STM32F302xe)
#define STM32_HAS_COMP1 TRUE
#define STM32_HAS_COMP2 TRUE
-#define STM32_HAS_COMP3 TRUE
+#define STM32_HAS_COMP3 FALSE
#define STM32_HAS_COMP4 TRUE
-#define STM32_HAS_COMP5 TRUE
+#define STM32_HAS_COMP5 FALSE
#define STM32_HAS_COMP6 TRUE
-#define STM32_HAS_COMP7 TRUE
-
-#endif
-
-#if defined(STM32F303xE)
+#define STM32_HAS_COMP7 FALSE
+#elif defined(STM32F303xC) || defined(STM32F303xE) || defined(STM32F358xx) || defined(STM32F398xx)
#define STM32_HAS_COMP1 TRUE
#define STM32_HAS_COMP2 TRUE
#define STM32_HAS_COMP3 TRUE
@@ -68,6 +62,24 @@
#define STM32_HAS_COMP6 TRUE
#define STM32_HAS_COMP7 TRUE
+#elif defined(STM32F373xx) || defined(STM32F378xx) || defined(STM32L0XX) || defined(STM32L1XX)
+#define STM32_HAS_COMP1 TRUE
+#define STM32_HAS_COMP2 TRUE
+#define STM32_HAS_COMP3 FALSE
+#define STM32_HAS_COMP4 FALSE
+#define STM32_HAS_COMP5 FALSE
+#define STM32_HAS_COMP6 FALSE
+#define STM32_HAS_COMP7 FALSE
+
+#else
+#define STM32_HAS_COMP1 FALSE
+#define STM32_HAS_COMP2 FALSE
+#define STM32_HAS_COMP3 FALSE
+#define STM32_HAS_COMP4 FALSE
+#define STM32_HAS_COMP5 FALSE
+#define STM32_HAS_COMP6 FALSE
+#define STM32_HAS_COMP7 FALSE
+
#endif
/*===========================================================================*/
@@ -157,12 +169,10 @@
/* Derived constants and error checks. */
/*===========================================================================*/
-#if STM32_COMP_USE_INTERRUPTS && !HAL_USE_EXT
-#error "COMP needs HAL_USE_EXT to use interrupts"
-#endif
-
#if STM32_COMP_USE_INTERRUPTS
-#include "hal_ext_lld.h"
+#if !defined(STM32_DISABLE_EXTI21_22_29_HANDLER) || !defined(STM32_DISABLE_EXTI30_32_HANDLER) || !defined(STM32_DISABLE_EXTI33_HANDLER)
+#error "COMP needs these defines in mcuconf to use interrupts: STM32_DISABLE_EXTI21_22_29_HANDLER STM32_DISABLE_EXTI30_32_HANDLER STM32_DISABLE_EXTI33_HANDLER"
+#endif
#endif
#if STM32_COMP_USE_COMP1 && !STM32_HAS_COMP1
@@ -256,7 +266,7 @@ struct COMPDriver {
/**
* @brief Pointer to the COMPx registers block.
*/
- COMP_TypeDef *comp;
+ COMP_TypeDef *reg;
};
/*===========================================================================*/
diff --git a/testhal/STM32/STM32F3xx/COMP/main.c b/testhal/STM32/STM32F3xx/COMP/main.c
index 5b377aa..83a00ff 100644
--- a/testhal/STM32/STM32F3xx/COMP/main.c
+++ b/testhal/STM32/STM32F3xx/COMP/main.c
@@ -17,44 +17,30 @@
#include "ch.h"
#include "hal.h"
-static const EXTConfig extcfg = {
- {
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL}
+void comp2_cb(COMPDriver *comp) {
+
+ if (comp->reg->CSR & COMP_CSR_COMPxOUT) {
+
+
}
-};
+
+}
+
+void comp4_cb(COMPDriver *comp) {
+ (void) comp;
+
+}
static const COMPConfig comp2_conf = {
COMP_OUTPUT_NORMAL,
- NULL,
- 0
+ comp2_cb,
+ COMP_CSR_COMPxINSEL_0 | COMP_CSR_COMPxOUTSEL_0 // CSR
};
static const COMPConfig comp4_conf = {
COMP_OUTPUT_INVERTED,
- NULL,
- 0
+ comp4_cb,
+ COMP_CSR_COMPxINSEL_0 | COMP_CSR_COMPxOUTSEL_1 // CSR
};
@@ -66,7 +52,6 @@ int main(void) {
halInit();
chSysInit();
- extStart(&EXTD1, &extcfg);
compStart(&COMPD2, &comp2_conf);
compStart(&COMPD4, &comp4_conf);
@@ -74,7 +59,6 @@ int main(void) {
* Normal main() thread activity, it resets the watchdog.
*/
while (true) {
- palToggleLine(LINE_LED4_BLUE);
chThdSleepMilliseconds(500);
}
return 0;
diff --git a/testhal/STM32/STM32F3xx/COMP/mcuconf_community.h b/testhal/STM32/STM32F3xx/COMP/mcuconf_community.h
index dad1b6d..1f89e54 100644
--- a/testhal/STM32/STM32F3xx/COMP/mcuconf_community.h
+++ b/testhal/STM32/STM32F3xx/COMP/mcuconf_community.h
@@ -64,15 +64,22 @@
/*
* COMP driver system settings.
- * IRQ priority is set with the EXT driver (lines 21-22, 29-33)
*/
-#define STM32_COMP_USE_COMP1 FALSE
+#define STM32_COMP_USE_COMP1 TRUE
#define STM32_COMP_USE_COMP2 TRUE
-#define STM32_COMP_USE_COMP3 FALSE
+#define STM32_COMP_USE_COMP3 TRUE
#define STM32_COMP_USE_COMP4 TRUE
-#define STM32_COMP_USE_COMP5 FALSE
-#define STM32_COMP_USE_COMP6 FALSE
-#define STM32_COMP_USE_COMP7 FALSE
+#define STM32_COMP_USE_COMP5 TRUE
+#define STM32_COMP_USE_COMP6 TRUE
+#define STM32_COMP_USE_COMP7 TRUE
+
#define STM32_COMP_USE_INTERRUPTS TRUE
+#define STM32_COMP_1_2_3_IRQ_PRIORITY 5
+#define STM32_COMP_4_5_6_IRQ_PRIORITY 5
+#define STM32_COMP_7_IRQ_PRIORITY 5
-
+#if STM32_COMP_USE_INTERRUPTS
+#define STM32_DISABLE_EXTI21_22_29_HANDLER
+#define STM32_DISABLE_EXTI30_32_HANDLER
+#define STM32_DISABLE_EXTI33_HANDLER
+#endif