diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2014-08-31 17:21:02 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2014-08-31 17:21:02 +0000 |
commit | 6c97d4f6fb4184c41f6283ce025a7030280a1802 (patch) | |
tree | 3c3c5fa9401c3d2aa6a4da4747a31fa0aa9c997a /os/hal | |
parent | 87e4b85755680a122f690f445b8cb320ca4f05ad (diff) | |
download | ChibiOS-6c97d4f6fb4184c41f6283ce025a7030280a1802.tar.gz ChibiOS-6c97d4f6fb4184c41f6283ce025a7030280a1802.tar.bz2 ChibiOS-6c97d4f6fb4184c41f6283ce025a7030280a1802.zip |
Enhanced ICU driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7211 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal')
-rw-r--r-- | os/hal/include/icu.h | 7 | ||||
-rw-r--r-- | os/hal/ports/STM32/LLD/TIMv1/icu_lld.c | 26 | ||||
-rw-r--r-- | os/hal/ports/STM32/LLD/TIMv1/pwm_lld.c | 2 |
3 files changed, 23 insertions, 12 deletions
diff --git a/os/hal/include/icu.h b/os/hal/include/icu.h index 1839c214f..0b85aa97b 100644 --- a/os/hal/include/icu.h +++ b/os/hal/include/icu.h @@ -183,7 +183,7 @@ typedef void (*icucallback_t)(ICUDriver *icup); * @notapi
*/
#define _icu_isr_invoke_width_cb(icup) do { \
- if (((icup)->state != ICU_WAITING) && \
+ if (((icup)->state == ICU_ACTIVE) && \
((icup)->config->period_cb != NULL)) \
(icup)->config->width_cb(icup); \
} while (0)
@@ -196,11 +196,10 @@ typedef void (*icucallback_t)(ICUDriver *icup); * @notapi
*/
#define _icu_isr_invoke_period_cb(icup) do { \
- icustate_t previous_state = (icup)->state; \
- (icup)->state = ICU_ACTIVE; \
- if ((previous_state != ICU_WAITING) && \
+ if (((icup)->state == ICU_ACTIVE) && \
((icup)->config->period_cb != NULL)) \
(icup)->config->period_cb(icup); \
+ (icup)->state = ICU_ACTIVE; \
} while (0)
/**
diff --git a/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c b/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c index 1602ac1d1..6ee7ff293 100644 --- a/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c +++ b/os/hal/ports/STM32/LLD/TIMv1/icu_lld.c @@ -108,17 +108,18 @@ ICUDriver ICUD9; * @param[in] icup pointer to the @p ICUDriver object
*/
static void icu_lld_serve_interrupt(ICUDriver *icup) {
- uint16_t sr;
+ uint32_t sr;
sr = icup->tim->SR;
sr &= icup->tim->DIER & STM32_TIM_DIER_IRQ_MASK;
icup->tim->SR = ~sr;
if (icup->config->channel == ICU_CHANNEL_1) {
- if ((sr & STM32_TIM_SR_CC1IF) != 0)
- _icu_isr_invoke_period_cb(icup);
if ((sr & STM32_TIM_SR_CC2IF) != 0)
_icu_isr_invoke_width_cb(icup);
- } else {
+ if ((sr & STM32_TIM_SR_CC1IF) != 0)
+ _icu_isr_invoke_period_cb(icup);
+ }
+ else {
if ((sr & STM32_TIM_SR_CC1IF) != 0)
_icu_isr_invoke_width_cb(icup);
if ((sr & STM32_TIM_SR_CC2IF) != 0)
@@ -506,7 +507,8 @@ void icu_lld_start(ICUDriver *icup) { data faster from within callbacks.*/
icup->wccrp = &icup->tim->CCR[1];
icup->pccrp = &icup->tim->CCR[0];
- } else {
+ }
+ else {
/* Selected input 2.
CCMR1_CC1S = 10 = CH1 Input on TI2.
CCMR1_CC2S = 01 = CH2 Input on TI2.*/
@@ -618,6 +620,7 @@ void icu_lld_start_capture(ICUDriver *icup) { * brings the driver in the @p ICU_ACTIVE state.
* @note If notifications are enabled then the transition to the
* @p ICU_ACTIVE state is done automatically on the first edge.
+ * @note The wait is performed in polled mode.
*
* @param[in] icup pointer to the @p ICUDriver object
*
@@ -625,6 +628,14 @@ void icu_lld_start_capture(ICUDriver *icup) { */
void icu_lld_wait_capture(ICUDriver *icup) {
+ if (icup->config->channel == ICU_CHANNEL_1) {
+ while ((icup->tim->SR & STM32_TIM_SR_CC1IF) == 0)
+ ;
+ }
+ else {
+ while ((icup->tim->SR & STM32_TIM_SR_CC2IF) == 0)
+ ;
+ }
}
/**
@@ -658,7 +669,7 @@ void icu_enable_notifications(ICUDriver *icup) { /* If interrupts were already enabled then the operation is skipped.
This is done in order to avoid clearing the SR and risk losing
pending interrupts.*/
- if ((dier & STM32_TIM_DIER_IRQ_MASK) != 0) {
+ if ((dier & STM32_TIM_DIER_IRQ_MASK) == 0) {
/* Previously triggered IRQs are ignored, status cleared.*/
icup->tim->SR = 0;
@@ -669,7 +680,8 @@ void icu_enable_notifications(ICUDriver *icup) { /* Optionally enabling width callback on CC2.*/
if (icup->config->width_cb != NULL)
dier |= STM32_TIM_DIER_CC2IE;
- } else {
+ }
+ else {
/* Enabling periodic callback on CC2.*/
dier |= STM32_TIM_DIER_CC2IE;
diff --git a/os/hal/ports/STM32/LLD/TIMv1/pwm_lld.c b/os/hal/ports/STM32/LLD/TIMv1/pwm_lld.c index 2b633c2e2..50884c5c8 100644 --- a/os/hal/ports/STM32/LLD/TIMv1/pwm_lld.c +++ b/os/hal/ports/STM32/LLD/TIMv1/pwm_lld.c @@ -109,7 +109,7 @@ PWMDriver PWMD9; * @param[in] pwmp pointer to a @p PWMDriver object
*/
static void pwm_lld_serve_interrupt(PWMDriver *pwmp) {
- uint16_t sr;
+ uint32_t sr;
sr = pwmp->tim->SR;
sr &= pwmp->tim->DIER & STM32_TIM_DIER_IRQ_MASK;
|