Overflow handling in ICU driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4033 35acf78f-673a-0410-8e92-d51de3d6d3f4master
parent
696e7202dc
commit
1f05b803ed
|
@ -157,6 +157,17 @@ typedef void (*icucallback_t)(ICUDriver *icup);
|
||||||
if (previous_state != ICU_WAITING) \
|
if (previous_state != ICU_WAITING) \
|
||||||
(icup)->config->period_cb(icup); \
|
(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); \
|
||||||
|
}
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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
|
* @file STM32/icu_lld.c
|
||||||
|
@ -112,6 +116,8 @@ static void icu_lld_serve_interrupt(ICUDriver *icup) {
|
||||||
if ((sr & TIM_SR_CC2IF) != 0)
|
if ((sr & TIM_SR_CC2IF) != 0)
|
||||||
_icu_isr_invoke_period_cb(icup);
|
_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) {
|
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->channel == ICU_CHANNEL_1) {
|
||||||
if (icup->config->period_cb != NULL)
|
if (icup->config->period_cb != NULL)
|
||||||
icup->tim->DIER |= TIM_DIER_CC1IE;
|
icup->tim->DIER |= TIM_DIER_CC1IE;
|
||||||
|
@ -494,6 +500,8 @@ void icu_lld_enable(ICUDriver *icup) {
|
||||||
if (icup->config->period_cb != NULL)
|
if (icup->config->period_cb != NULL)
|
||||||
icup->tim->DIER |= TIM_DIER_CC2IE;
|
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;
|
icup->tim->CR1 = TIM_CR1_URS | TIM_CR1_CEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,10 @@ typedef struct {
|
||||||
* @brief Callback for cycle period measurement.
|
* @brief Callback for cycle period measurement.
|
||||||
*/
|
*/
|
||||||
icucallback_t period_cb;
|
icucallback_t period_cb;
|
||||||
|
/**
|
||||||
|
* @brief Callback for timer overflow.
|
||||||
|
*/
|
||||||
|
icucallback_t overflow_cb;
|
||||||
/* End of the mandatory fields.*/
|
/* End of the mandatory fields.*/
|
||||||
/**
|
/**
|
||||||
* @brief Timer input channel to be used.
|
* @brief Timer input channel to be used.
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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
|
* @file templates/icu_lld.h
|
||||||
|
@ -88,6 +92,10 @@ typedef struct {
|
||||||
* @brief Callback for cycle period measurement.
|
* @brief Callback for cycle period measurement.
|
||||||
*/
|
*/
|
||||||
icucallback_t period_cb;
|
icucallback_t period_cb;
|
||||||
|
/**
|
||||||
|
* @brief Callback for timer overflow.
|
||||||
|
*/
|
||||||
|
icucallback_t overflow_cb;
|
||||||
/* End of the mandatory fields.*/
|
/* End of the mandatory fields.*/
|
||||||
} ICUConfig;
|
} ICUConfig;
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,7 @@
|
||||||
3484947)(backported to 2.4.1).
|
3484947)(backported to 2.4.1).
|
||||||
- FIX: Fixed various minor documentation errors (bug 3484942)(backported
|
- FIX: Fixed various minor documentation errors (bug 3484942)(backported
|
||||||
to 2.4.1).
|
to 2.4.1).
|
||||||
|
- NEW: Added overflow handling in the ICU driver (contributed by Xo).
|
||||||
- NEW: Updated debug plugin 1.0.8 (backported to 2.4.0).
|
- NEW: Updated debug plugin 1.0.8 (backported to 2.4.0).
|
||||||
- NEW: Added more accurate UBRR calculation in AVR serial driver (backported
|
- NEW: Added more accurate UBRR calculation in AVR serial driver (backported
|
||||||
to 2.4.0).
|
to 2.4.0).
|
||||||
|
|
|
@ -66,6 +66,7 @@ static ICUConfig icucfg = {
|
||||||
10000, /* 10KHz ICU clock frequency. */
|
10000, /* 10KHz ICU clock frequency. */
|
||||||
icuwidthcb,
|
icuwidthcb,
|
||||||
icuperiodcb,
|
icuperiodcb,
|
||||||
|
NULL,
|
||||||
ICU_CHANNEL_1
|
ICU_CHANNEL_1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,20 +51,22 @@ icucnt_t last_width, last_period;
|
||||||
static void icuwidthcb(ICUDriver *icup) {
|
static void icuwidthcb(ICUDriver *icup) {
|
||||||
|
|
||||||
palSetPad(GPIOD, GPIOD_LED4);
|
palSetPad(GPIOD, GPIOD_LED4);
|
||||||
last_width = icuGetWidthI(icup);
|
last_width = icuGetWidth(icup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void icuperiodcb(ICUDriver *icup) {
|
static void icuperiodcb(ICUDriver *icup) {
|
||||||
|
|
||||||
palClearPad(GPIOD, GPIOD_LED4);
|
palClearPad(GPIOD, GPIOD_LED4);
|
||||||
last_period = icuGetPeriodI(icup);
|
last_period = icuGetPeriod(icup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ICUConfig icucfg = {
|
static ICUConfig icucfg = {
|
||||||
ICU_INPUT_ACTIVE_HIGH,
|
ICU_INPUT_ACTIVE_HIGH,
|
||||||
10000, /* 10KHz ICU clock frequency. */
|
10000, /* 10KHz ICU clock frequency. */
|
||||||
icuwidthcb,
|
icuwidthcb,
|
||||||
icuperiodcb
|
icuperiodcb,
|
||||||
|
NULL,
|
||||||
|
ICU_CHANNEL_1
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -51,20 +51,22 @@ icucnt_t last_width, last_period;
|
||||||
static void icuwidthcb(ICUDriver *icup) {
|
static void icuwidthcb(ICUDriver *icup) {
|
||||||
|
|
||||||
palSetPad(GPIOB, GPIOB_LED3);
|
palSetPad(GPIOB, GPIOB_LED3);
|
||||||
last_width = icuGetWidthI(icup);
|
last_width = icuGetWidth(icup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void icuperiodcb(ICUDriver *icup) {
|
static void icuperiodcb(ICUDriver *icup) {
|
||||||
|
|
||||||
palClearPad(GPIOB, GPIOB_LED3);
|
palClearPad(GPIOB, GPIOB_LED3);
|
||||||
last_period = icuGetPeriodI(icup);
|
last_period = icuGetPeriod(icup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ICUConfig icucfg = {
|
static ICUConfig icucfg = {
|
||||||
ICU_INPUT_ACTIVE_HIGH,
|
ICU_INPUT_ACTIVE_HIGH,
|
||||||
10000, /* 10KHz ICU clock frequency. */
|
10000, /* 10KHz ICU clock frequency. */
|
||||||
icuwidthcb,
|
icuwidthcb,
|
||||||
icuperiodcb
|
icuperiodcb,
|
||||||
|
NULL,
|
||||||
|
ICU_CHANNEL_1
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue