diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-04-01 08:45:34 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-04-01 08:45:34 +0000 |
commit | 0b0fb6f88f6851842e89f19129b0dc535f41dcbc (patch) | |
tree | 68f624b27371ca455ea1e43e16074963fd66d495 /os | |
parent | beab954a35b7c6be13b8c5af58c7cd52b5888abc (diff) | |
download | ChibiOS-0b0fb6f88f6851842e89f19129b0dc535f41dcbc.tar.gz ChibiOS-0b0fb6f88f6851842e89f19129b0dc535f41dcbc.tar.bz2 ChibiOS-0b0fb6f88f6851842e89f19129b0dc535f41dcbc.zip |
ICU driver functional.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2857 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/include/icu.h | 4 | ||||
-rw-r--r-- | os/hal/platforms/STM32/icu_lld.c | 14 | ||||
-rw-r--r-- | os/hal/platforms/STM32/icu_lld.h | 27 | ||||
-rw-r--r-- | os/hal/src/hal.c | 3 |
4 files changed, 17 insertions, 31 deletions
diff --git a/os/hal/include/icu.h b/os/hal/include/icu.h index 26fc120ad..b51345c4d 100644 --- a/os/hal/include/icu.h +++ b/os/hal/include/icu.h @@ -130,8 +130,8 @@ extern "C" { void icuObjectInit(ICUDriver *icup);
void icuStart(ICUDriver *icup, const ICUConfig *config);
void icuStop(ICUDriver *icup);
- void icuEnableI(ICUDriver *icup);
- void icuDisableI(ICUDriver *icup);
+ void icuEnable(ICUDriver *icup);
+ void icuDisable(ICUDriver *icup);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/platforms/STM32/icu_lld.c b/os/hal/platforms/STM32/icu_lld.c index 5d3bb284d..f950a5eb6 100644 --- a/os/hal/platforms/STM32/icu_lld.c +++ b/os/hal/platforms/STM32/icu_lld.c @@ -91,12 +91,18 @@ ICUDriver ICUD5; static void icu_lld_serve_interrupt(ICUDriver *icup) {
uint16_t sr;
- sr = TIM1->SR & TIM1->DIER;
+ sr = icup->tim->SR & icup->tim->DIER;
icup->tim->SR = 0;
- if ((sr & TIM_SR_CC1IF) != 0)
- icup->config->period_cb(icup);
- if ((sr & TIM_SR_CC2IF) != 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);
+ }
}
/*===========================================================================*/
diff --git a/os/hal/platforms/STM32/icu_lld.h b/os/hal/platforms/STM32/icu_lld.h index 437390d52..b98b8bf86 100644 --- a/os/hal/platforms/STM32/icu_lld.h +++ b/os/hal/platforms/STM32/icu_lld.h @@ -223,7 +223,6 @@ struct ICUDriver { /* Driver macros. */
/*===========================================================================*/
-
/**
* @brief Returns the width of the latest pulse.
* @details The pulse width is defined as number of ticks between the start
@@ -234,7 +233,7 @@ struct ICUDriver { *
* @notapi
*/
-#define icu_lld_get_width(icup) ((icup)->tim->CCR2)
+#define icu_lld_get_width(icup) ((icup)->tim->CCR2 + 1)
/**
* @brief Returns the width of the latest cycle.
@@ -246,29 +245,7 @@ struct ICUDriver { *
* @notapi
*/
-#define icu_lld_get_period(icup) ((icup)->tim->CCR1)
-
-/**
- * @brief ICU clock prescaler initialization utility.
- * @note The real clock value is rounded to the lower valid value, please
- * make sure that the source clock frequency is a multiple of the
- * requested ICU clock frequency.
- * @note The calculated value must fit into an unsigned 16 bits integer.
- *
- * @param[in] clksrc clock source frequency, depending on the target timer
- * cell it can be one of:
- * - STM32_TIMCLK1
- * - STM32_TIMCLK2
- * .
- * Please refer to the STM32 HAL driver documentation
- * and/or the STM32 Reference Manual for the right clock
- * source.
- * @param[in] icuclk ICU clock frequency in cycles
- * @return The value to be stored in the @p psc field of the
- * @p ICUConfig structure.
- */
-#define ICU_COMPUTE_PSC(clksrc, icuclk) \
- ((uint16_t)(((clksrc) / (icuclk)) - 1))
+#define icu_lld_get_period(icup) ((icup)->tim->CCR1 + 1)
/*===========================================================================*/
/* External declarations. */
diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 09b832fe2..8555b44bb 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -73,6 +73,9 @@ void halInit(void) { #if HAL_USE_I2C || defined(__DOXYGEN__)
i2cInit();
#endif
+#if HAL_USE_ICU || defined(__DOXYGEN__)
+ icuInit();
+#endif
#if HAL_USE_MAC || defined(__DOXYGEN__)
macInit();
#endif
|