aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-10-17 12:28:10 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-10-17 12:28:10 +0000
commitb2c261eeeefcd94c9c164fa1e8671b7b42997e4d (patch)
treecc5413af9fef7661c7e8d55db1d14a88d67e729a /os/hal/ports
parenta708e083e1cf6f6181bcd02baf9cc580f38b5397 (diff)
downloadChibiOS-b2c261eeeefcd94c9c164fa1e8671b7b42997e4d.tar.gz
ChibiOS-b2c261eeeefcd94c9c164fa1e8671b7b42997e4d.tar.bz2
ChibiOS-b2c261eeeefcd94c9c164fa1e8671b7b42997e4d.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7411 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/ports')
-rw-r--r--os/hal/ports/STM32/LLD/TIMv1/icu_lld.c36
-rw-r--r--os/hal/ports/STM32/LLD/TIMv1/icu_lld.h2
2 files changed, 25 insertions, 13 deletions
diff --git a/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c b/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c
index d5604515e..04fec43cd 100644
--- a/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c
+++ b/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c
@@ -102,7 +102,9 @@ ICUDriver ICUD9;
/* Driver local functions. */
/*===========================================================================*/
-static void icu_lld_wait_edge(ICUDriver *icup) {
+static bool icu_lld_wait_edge(ICUDriver *icup) {
+ uint32_t sr;
+ bool result;
/* Polled mode so re-enabling the interrupts while the operation is
performed.*/
@@ -111,23 +113,29 @@ static void icu_lld_wait_edge(ICUDriver *icup) {
/* 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)
+ while (((sr = icup->tim->SR) &
+ (STM32_TIM_SR_CC1IF | STM32_TIM_SR_UIF)) == 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)
+ while (((sr = icup->tim->SR) &
+ (STM32_TIM_SR_CC2IF | STM32_TIM_SR_UIF)) == 0)
;
-
- /* Resetting capture flag.*/
- icup->tim->SR &= ~STM32_TIM_SR_CC2IF;
}
+ /* Edge or overflow?*/
+ result = (sr & STM32_TIM_SR_UIF) != 0 ? true : false;
+
/* Done, disabling interrupts again.*/
chSysLock();
+
+ /* Resetting all flags.*/
+ icup->tim->SR &= ~(STM32_TIM_SR_CC1IF |
+ STM32_TIM_SR_CC2IF |
+ STM32_TIM_SR_UIF);
+
+ return result;
}
/**
@@ -648,18 +656,22 @@ void icu_lld_start_capture(ICUDriver *icup) {
* @note In order to use this function notifications must be disabled.
*
* @param[in] icup pointer to the @p ICUDriver object
+ * @return The capture status.
+ * @retval false if the capture is successful.
+ * @retval true if a timer overflow occurred.
*
* @notapi
*/
-void icu_lld_wait_capture(ICUDriver *icup) {
+bool icu_lld_wait_capture(ICUDriver *icup) {
/* 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);
+ if (icu_lld_wait_edge(icup))
+ return true;
/* This edge marks the availability of a capture result.*/
- icu_lld_wait_edge(icup);
+ return icu_lld_wait_edge(icup);
}
/**
diff --git a/os/hal/ports/STM32/LLD/TIMv1/icu_lld.h b/os/hal/ports/STM32/LLD/TIMv1/icu_lld.h
index 5b8b71d9f..c20d1bc7c 100644
--- a/os/hal/ports/STM32/LLD/TIMv1/icu_lld.h
+++ b/os/hal/ports/STM32/LLD/TIMv1/icu_lld.h
@@ -413,7 +413,7 @@ extern "C" {
void icu_lld_start(ICUDriver *icup);
void icu_lld_stop(ICUDriver *icup);
void icu_lld_start_capture(ICUDriver *icup);
- void icu_lld_wait_capture(ICUDriver *icup);
+ bool icu_lld_wait_capture(ICUDriver *icup);
void icu_lld_stop_capture(ICUDriver *icup);
void icu_lld_enable_notifications(ICUDriver *icup);
void icu_lld_disable_notifications(ICUDriver *icup);