aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/STM32
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-09-01 08:27:52 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-09-01 08:27:52 +0000
commit051dd3958373c27c9ffeb06da004dca0023003b6 (patch)
tree229af7fcf59f7a493d4c5a04fcef681c171683eb /os/hal/ports/STM32
parent7d1b097edcd86c87e738069a64d41e8b0cf9fd4b (diff)
downloadChibiOS-051dd3958373c27c9ffeb06da004dca0023003b6.tar.gz
ChibiOS-051dd3958373c27c9ffeb06da004dca0023003b6.tar.bz2
ChibiOS-051dd3958373c27c9ffeb06da004dca0023003b6.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7224 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/ports/STM32')
-rw-r--r--os/hal/ports/STM32/LLD/TIMv1/icu_lld.c56
1 files changed, 36 insertions, 20 deletions
diff --git a/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c b/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c
index d8bc2e84c..c11736884 100644
--- a/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c
+++ b/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c
@@ -102,6 +102,34 @@ ICUDriver ICUD9;
/* Driver local functions. */
/*===========================================================================*/
+static void icu_lld_wait_edge(ICUDriver *icup) {
+
+ /* Polled mode so re-enabling the interrupts while the operation is
+ performed.*/
+ chSysUnlock();
+
+ /* Polling the right bit depending on the input channel.*/
+ if (icup->config->channel == ICU_CHANNEL_1) {
+ /* Waiting for an edge.*/
+ while ((icup->tim->SR & STM32_TIM_SR_CC1IF) == 0)
+ ;
+
+ /* Resetting capture flag.*/
+ icup->tim->SR &= ~STM32_TIM_SR_CC1IF;
+ }
+ else {
+ /* Waiting for an edge.*/
+ while ((icup->tim->SR & STM32_TIM_SR_CC2IF) == 0)
+ ;
+
+ /* Resetting capture flag.*/
+ icup->tim->SR &= ~STM32_TIM_SR_CC2IF;
+ }
+
+ /* Done, disabling interrupts again.*/
+ chSysLock();
+}
+
/**
* @brief Shared IRQ handler.
*
@@ -615,12 +643,9 @@ void icu_lld_start_capture(ICUDriver *icup) {
}
/**
- * @brief Waits for the next cycle activation edge.
- * @details The function waits for the next PWM input activation front then
- * brings the driver in the @p ICU_ACTIVE state.
- * @note If notifications are enabled then the transition to the
- * @p ICU_ACTIVE state is done automatically on the first edge.
+ * @brief Waits for a completed capture.
* @note The wait is performed in polled mode.
+ * @note The function cannot work if notifications are enabled.
*
* @param[in] icup pointer to the @p ICUDriver object
*
@@ -628,22 +653,13 @@ void icu_lld_start_capture(ICUDriver *icup) {
*/
void icu_lld_wait_capture(ICUDriver *icup) {
- if (icup->config->channel == ICU_CHANNEL_1) {
- /* Resetting capture flag.*/
- icup->tim->SR &= ~STM32_TIM_SR_CC1IF;
-
- /* Waiting for an edge.*/
- while ((icup->tim->SR & STM32_TIM_SR_CC1IF) == 0)
- ;
- }
- else {
- /* Resetting capture flag.*/
- icup->tim->SR &= ~STM32_TIM_SR_CC2IF;
+ /* If the driver is still in the ICU_WAITING state then we need to wait
+ for the first activation edge.*/
+ if (icup->state == ICU_WAITING)
+ icu_lld_wait_edge(icup);
- /* Waiting for an edge.*/
- while ((icup->tim->SR & STM32_TIM_SR_CC2IF) == 0)
- ;
- }
+ /* This edge marks the availability of a capture result.*/
+ icu_lld_wait_edge(icup);
}
/**