From 875a7d8f4151039f4c47b05c0d4f196575b8d109 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 1 Apr 2011 09:31:28 +0000 Subject: [PATCH] Shared ISR code moved in icu.h. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2860 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/icu.h | 26 ++++++++++++++++++++++++++ os/hal/platforms/STM32/icu_lld.c | 14 ++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/os/hal/include/icu.h b/os/hal/include/icu.h index b51345c4d..8a89281ae 100644 --- a/os/hal/include/icu.h +++ b/os/hal/include/icu.h @@ -119,6 +119,32 @@ typedef void (*icucallback_t)(ICUDriver *icup); */ #define icuGetPeriodI(icup) icu_lld_get_period(icup) +/** + * @brief Common ISR code, ICU width event. + * + * @param[in] icup pointer to the @p ICUDriver object + * + * @notapi + */ +#define _icu_isr_invoke_width_cb(usbp) { \ + (icup)->state = ICU_IDLE; \ + (icup)->config->width_cb(icup); \ +} + +/** + * @brief Common ISR code, ICU period event. + * + * @param[in] icup pointer to the @p ICUDriver object + * + * @notapi + */ +#define _icu_isr_invoke_period_cb(usbp) { \ + icustate_t previous_state = (icup)->state; \ + (icup)->state = ICU_ACTIVE; \ + if (previous_state != ICU_WAITING) \ + (icup)->config->period_cb(icup); \ +} + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ diff --git a/os/hal/platforms/STM32/icu_lld.c b/os/hal/platforms/STM32/icu_lld.c index f950a5eb6..ae3287ef9 100644 --- a/os/hal/platforms/STM32/icu_lld.c +++ b/os/hal/platforms/STM32/icu_lld.c @@ -93,16 +93,10 @@ static void icu_lld_serve_interrupt(ICUDriver *icup) { sr = icup->tim->SR & icup->tim->DIER; icup->tim->SR = 0; - if ((sr & TIM_SR_CC1IF) != 0) { - icustate_t previous_state = icup->state; - icup->state = ICU_ACTIVE; - if (previous_state != ICU_WAITING) - icup->config->period_cb(icup); - } - if ((sr & TIM_SR_CC2IF) != 0) { - icup->state = ICU_IDLE; - icup->config->width_cb(icup); - } + if ((sr & TIM_SR_CC1IF) != 0) + _icu_isr_invoke_period_cb(icup); + if ((sr & TIM_SR_CC2IF) != 0) + _icu_isr_invoke_width_cb(icup); } /*===========================================================================*/