aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-03-10 11:56:43 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-03-10 11:56:43 +0000
commit1f05b803edfb45940c544aa01ae3af3693b1a4cd (patch)
tree76823dd701e8e8609ae4f83f7ea9bdc9e5609a6a /os
parent696e7202dca8e59cb3a38bfdb190a1e095da70cd (diff)
downloadChibiOS-1f05b803edfb45940c544aa01ae3af3693b1a4cd.tar.gz
ChibiOS-1f05b803edfb45940c544aa01ae3af3693b1a4cd.tar.bz2
ChibiOS-1f05b803edfb45940c544aa01ae3af3693b1a4cd.zip
Overflow handling in ICU driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4033 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/include/icu.h11
-rw-r--r--os/hal/platforms/STM32/icu_lld.c10
-rw-r--r--os/hal/platforms/STM32/icu_lld.h4
-rw-r--r--os/hal/templates/icu_lld.h8
4 files changed, 32 insertions, 1 deletions
diff --git a/os/hal/include/icu.h b/os/hal/include/icu.h
index 99cfc4e3c..15a9b2380 100644
--- a/os/hal/include/icu.h
+++ b/os/hal/include/icu.h
@@ -157,6 +157,17 @@ typedef void (*icucallback_t)(ICUDriver *icup);
if (previous_state != ICU_WAITING) \
(icup)->config->period_cb(icup); \
}
+
+/**
+ * @brief Common ISR code, ICU timer overflow event.
+ *
+ * @param[in] icup pointer to the @p ICUDriver object
+ *
+ * @notapi
+ */
+#define _icu_isr_invoke_overflow_cb(icup) { \
+ (icup)->config->overflow_cb(icup); \
+}
/** @} */
/*===========================================================================*/
diff --git a/os/hal/platforms/STM32/icu_lld.c b/os/hal/platforms/STM32/icu_lld.c
index 2bfffd3bd..849241c2b 100644
--- a/os/hal/platforms/STM32/icu_lld.c
+++ b/os/hal/platforms/STM32/icu_lld.c
@@ -17,6 +17,10 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/*
+ Concepts and parts of this file have been contributed by Fabio Utzig and
+ Xo Wang.
+ */
/**
* @file STM32/icu_lld.c
@@ -112,6 +116,8 @@ static void icu_lld_serve_interrupt(ICUDriver *icup) {
if ((sr & TIM_SR_CC2IF) != 0)
_icu_isr_invoke_period_cb(icup);
}
+ if ((sr & TIM_SR_UIF) != 0)
+ _icu_isr_invoke_overflow_cb(icup);
}
/*===========================================================================*/
@@ -482,7 +488,7 @@ void icu_lld_stop(ICUDriver *icup) {
*/
void icu_lld_enable(ICUDriver *icup) {
- icup->tim->SR = 0; /* Clear pending IRQs (if any). */
+ icup->tim->SR = 0; /* Clear pending IRQs (if any). */
if (icup->config->channel == ICU_CHANNEL_1) {
if (icup->config->period_cb != NULL)
icup->tim->DIER |= TIM_DIER_CC1IE;
@@ -494,6 +500,8 @@ void icu_lld_enable(ICUDriver *icup) {
if (icup->config->period_cb != NULL)
icup->tim->DIER |= TIM_DIER_CC2IE;
}
+ if (icup->config->overflow_cb != NULL)
+ icup->tim->DIER |= TIM_DIER_UIE;
icup->tim->CR1 = TIM_CR1_URS | TIM_CR1_CEN;
}
diff --git a/os/hal/platforms/STM32/icu_lld.h b/os/hal/platforms/STM32/icu_lld.h
index 642de2a64..691b06a71 100644
--- a/os/hal/platforms/STM32/icu_lld.h
+++ b/os/hal/platforms/STM32/icu_lld.h
@@ -227,6 +227,10 @@ typedef struct {
* @brief Callback for cycle period measurement.
*/
icucallback_t period_cb;
+ /**
+ * @brief Callback for timer overflow.
+ */
+ icucallback_t overflow_cb;
/* End of the mandatory fields.*/
/**
* @brief Timer input channel to be used.
diff --git a/os/hal/templates/icu_lld.h b/os/hal/templates/icu_lld.h
index 4b0568102..56ce3af98 100644
--- a/os/hal/templates/icu_lld.h
+++ b/os/hal/templates/icu_lld.h
@@ -17,6 +17,10 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/*
+ Concepts and parts of this file have been contributed by Fabio Utzig and
+ Xo Wang.
+ */
/**
* @file templates/icu_lld.h
@@ -88,6 +92,10 @@ typedef struct {
* @brief Callback for cycle period measurement.
*/
icucallback_t period_cb;
+ /**
+ * @brief Callback for timer overflow.
+ */
+ icucallback_t overflow_cb;
/* End of the mandatory fields.*/
} ICUConfig;