ICU driver functional.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2857 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
beab954a35
commit
0b0fb6f88f
|
@ -130,8 +130,8 @@ extern "C" {
|
||||||
void icuObjectInit(ICUDriver *icup);
|
void icuObjectInit(ICUDriver *icup);
|
||||||
void icuStart(ICUDriver *icup, const ICUConfig *config);
|
void icuStart(ICUDriver *icup, const ICUConfig *config);
|
||||||
void icuStop(ICUDriver *icup);
|
void icuStop(ICUDriver *icup);
|
||||||
void icuEnableI(ICUDriver *icup);
|
void icuEnable(ICUDriver *icup);
|
||||||
void icuDisableI(ICUDriver *icup);
|
void icuDisable(ICUDriver *icup);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -91,12 +91,18 @@ ICUDriver ICUD5;
|
||||||
static void icu_lld_serve_interrupt(ICUDriver *icup) {
|
static void icu_lld_serve_interrupt(ICUDriver *icup) {
|
||||||
uint16_t sr;
|
uint16_t sr;
|
||||||
|
|
||||||
sr = TIM1->SR & TIM1->DIER;
|
sr = icup->tim->SR & icup->tim->DIER;
|
||||||
icup->tim->SR = 0;
|
icup->tim->SR = 0;
|
||||||
if ((sr & TIM_SR_CC1IF) != 0)
|
if ((sr & TIM_SR_CC1IF) != 0) {
|
||||||
icup->config->period_cb(icup);
|
icustate_t previous_state = icup->state;
|
||||||
if ((sr & TIM_SR_CC2IF) != 0)
|
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);
|
icup->config->width_cb(icup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -223,7 +223,6 @@ struct ICUDriver {
|
||||||
/* Driver macros. */
|
/* Driver macros. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the width of the latest pulse.
|
* @brief Returns the width of the latest pulse.
|
||||||
* @details The pulse width is defined as number of ticks between the start
|
* @details The pulse width is defined as number of ticks between the start
|
||||||
|
@ -234,7 +233,7 @@ struct ICUDriver {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @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.
|
* @brief Returns the width of the latest cycle.
|
||||||
|
@ -246,29 +245,7 @@ struct ICUDriver {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
#define icu_lld_get_period(icup) ((icup)->tim->CCR1)
|
#define icu_lld_get_period(icup) ((icup)->tim->CCR1 + 1)
|
||||||
|
|
||||||
/**
|
|
||||||
* @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))
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* External declarations. */
|
/* External declarations. */
|
||||||
|
|
|
@ -73,6 +73,9 @@ void halInit(void) {
|
||||||
#if HAL_USE_I2C || defined(__DOXYGEN__)
|
#if HAL_USE_I2C || defined(__DOXYGEN__)
|
||||||
i2cInit();
|
i2cInit();
|
||||||
#endif
|
#endif
|
||||||
|
#if HAL_USE_ICU || defined(__DOXYGEN__)
|
||||||
|
icuInit();
|
||||||
|
#endif
|
||||||
#if HAL_USE_MAC || defined(__DOXYGEN__)
|
#if HAL_USE_MAC || defined(__DOXYGEN__)
|
||||||
macInit();
|
macInit();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -46,6 +46,25 @@ static PWMConfig pwmcfg = {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
icucnt_t last_width, last_period;
|
||||||
|
|
||||||
|
static void icuwidthcb(ICUDriver *icup) {
|
||||||
|
|
||||||
|
last_width = icuGetWidthI(icup);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void icuperiodcb(ICUDriver *icup) {
|
||||||
|
|
||||||
|
last_period = icuGetPeriodI(icup);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ICUConfig icucfg = {
|
||||||
|
ICU_INPUT_ACTIVE_HIGH,
|
||||||
|
10000, /* 10KHz ICU clock frequency. */
|
||||||
|
icuwidthcb,
|
||||||
|
icuperiodcb
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Application entry point.
|
* Application entry point.
|
||||||
*/
|
*/
|
||||||
|
@ -71,6 +90,8 @@ int main(void) {
|
||||||
*/
|
*/
|
||||||
pwmStart(&PWMD1, &pwmcfg);
|
pwmStart(&PWMD1, &pwmcfg);
|
||||||
palSetPadMode(IOPORT1, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
|
palSetPadMode(IOPORT1, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
|
||||||
|
icuStart(&ICUD4, &icucfg);
|
||||||
|
icuEnable(&ICUD4);
|
||||||
chThdSleepMilliseconds(2000);
|
chThdSleepMilliseconds(2000);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -97,6 +118,8 @@ int main(void) {
|
||||||
*/
|
*/
|
||||||
pwmDisableChannel(&PWMD1, 0);
|
pwmDisableChannel(&PWMD1, 0);
|
||||||
pwmStop(&PWMD1);
|
pwmStop(&PWMD1);
|
||||||
|
icuDisable(&ICUD4);
|
||||||
|
icuStop(&ICUD4);
|
||||||
palSetPad(IOPORT3, GPIOC_LED);
|
palSetPad(IOPORT3, GPIOC_LED);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -78,9 +78,9 @@
|
||||||
* ICU driver system settings.
|
* ICU driver system settings.
|
||||||
*/
|
*/
|
||||||
#define STM32_ICU_USE_TIM1 FALSE
|
#define STM32_ICU_USE_TIM1 FALSE
|
||||||
#define STM32_ICU_USE_TIM2 TRUE
|
#define STM32_ICU_USE_TIM2 FALSE
|
||||||
#define STM32_ICU_USE_TIM3 FALSE
|
#define STM32_ICU_USE_TIM3 FALSE
|
||||||
#define STM32_ICU_USE_TIM4 FALSE
|
#define STM32_ICU_USE_TIM4 TRUE
|
||||||
#define STM32_ICU_USE_TIM5 FALSE
|
#define STM32_ICU_USE_TIM5 FALSE
|
||||||
#define STM32_ICU_TIM1_IRQ_PRIORITY 7
|
#define STM32_ICU_TIM1_IRQ_PRIORITY 7
|
||||||
#define STM32_ICU_TIM2_IRQ_PRIORITY 7
|
#define STM32_ICU_TIM2_IRQ_PRIORITY 7
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
** ChibiOS/RT HAL - PWM driver demo for STM32. **
|
** ChibiOS/RT HAL - PWM/ICU driver demo for STM32. **
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
|
|
||||||
** TARGET **
|
** TARGET **
|
||||||
|
@ -8,7 +8,9 @@ The demo will on an Olimex STM32-P103 board.
|
||||||
|
|
||||||
** The Demo **
|
** The Demo **
|
||||||
|
|
||||||
The application demonstrates the use of the STM32 PWM driver.
|
The application demonstrates the use of the STM32 PWM and ICU drivers. Pins
|
||||||
|
PA8 and PB6 must be connected in order to trigger the ICU input with the
|
||||||
|
PWM output. The ICU unit will measure the generated PWM.
|
||||||
|
|
||||||
** Build Procedure **
|
** Build Procedure **
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue