From b95ae7e467f88879cb255b75f4286e6aa2ff57a1 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 15 Dec 2022 10:07:25 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15878 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/hal/include/hal_icu.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/os/hal/include/hal_icu.h b/os/hal/include/hal_icu.h index a2026ac8c..759999ec1 100644 --- a/os/hal/include/hal_icu.h +++ b/os/hal/include/hal_icu.h @@ -35,6 +35,10 @@ /* Driver pre-compile time settings. */ /*===========================================================================*/ +#if !defined(ICU_USE_OVERFLOW_SCALING) +#define ICU_USE_OVERFLOW_SCALING FALSE +#endif + /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ @@ -198,6 +202,25 @@ typedef void (*icucallback_t)(ICUDriver *icup); (icup)->state = ICU_ACTIVE; \ } while (0) +#if ICU_USE_OVERFLOW_SCALING == TRUE +/** + * @brief Common ISR code, ICU timer overflow event. + * @note An overflow when in @p ICU_ACTIVE state with a callback set + * executes the callback code (supports overflow scaling). Otherwise + * overflow brings the driver back to the @p ICU_WAITING state. + * + * @param[in] icup pointer to the @p ICUDriver object + * + * @notapi + */ +#define _icu_isr_invoke_overflow_cb(icup) do { \ + if ((icup)->config->overflow_cb != NULL && (icup)->state == ICU_ACTIVE) \ + (icup)->config->overflow_cb(icup); \ + else \ + (icup)->state = ICU_WAITING; \ +} while (0) + +#else /* ICU_USE_OVERFLOW_SCALING != TRUE */ /** * @brief Common ISR code, ICU timer overflow event. * @note An overflow always brings the driver back to the @p ICU_WAITING @@ -211,6 +234,8 @@ typedef void (*icucallback_t)(ICUDriver *icup); (icup)->config->overflow_cb(icup); \ (icup)->state = ICU_WAITING; \ } while (0) +#endif /* ICU_USE_OVERFLOW_SCALING != TRUE */ + /** @} */ /*===========================================================================*/