Improvements to the ICU driver.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7409 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
gdisirio 2014-10-17 07:31:40 +00:00
parent b1586a7e3a
commit a708e083e1
4 changed files with 43 additions and 21 deletions

View File

@ -92,18 +92,6 @@ typedef void (*icucallback_t)(ICUDriver *icup);
icup->state = ICU_WAITING; \
} while (0)
/**
* @brief Waits for a completed capture.
*
* @param[in] icup pointer to the @p ICUDriver object
*
* @iclass
*/
#define icuWaitCaptureI(icup) do { \
icu_lld_wait_capture(icup); \
icup->state = ICU_ACTIVE; \
} while (0)
/**
* @brief Stops the input capture.
*
@ -125,7 +113,7 @@ typedef void (*icucallback_t)(ICUDriver *icup);
*
* @iclass
*/
#define icuEnableNotificationsI(icup) icu_enable_notifications(icup)
#define icuEnableNotificationsI(icup) icu_lld_enable_notifications(icup)
/**
* @brief Disables notifications.
@ -136,7 +124,20 @@ typedef void (*icucallback_t)(ICUDriver *icup);
*
* @iclass
*/
#define icuDisableNotificationsI(icup) icu_disable_notifications(icup)
#define icuDisableNotificationsI(icup) icu_lld_disable_notifications(icup)
/**
* @brief Check on notifications status.
*
* @param[in] icup pointer to the @p ICUDriver object
* @return The notifications status.
* @retval false if notifications are not enabled.
* @retval true if notifications are enabled.
*
* @notapi
*/
#define icuAreNotificationsEnabledX(icup) \
icu_lld_are_notifications_enabled(icup)
/**
* @brief Returns the width of the latest pulse.

View File

@ -644,8 +644,8 @@ void icu_lld_start_capture(ICUDriver *icup) {
/**
* @brief Waits for a completed capture.
* @note The wait is performed in polled mode.
* @note The function cannot work if notifications are enabled.
* @note The operation is performed in polled mode.
* @note In order to use this function notifications must be disabled.
*
* @param[in] icup pointer to the @p ICUDriver object
*
@ -687,7 +687,7 @@ void icu_lld_stop_capture(ICUDriver *icup) {
*
* @api
*/
void icu_enable_notifications(ICUDriver *icup) {
void icu_lld_enable_notifications(ICUDriver *icup) {
uint32_t dier = icup->tim->DIER;
/* If interrupts were already enabled then the operation is skipped.
@ -733,7 +733,7 @@ void icu_enable_notifications(ICUDriver *icup) {
*
* @api
*/
void icu_disable_notifications(ICUDriver *icup) {
void icu_lld_disable_notifications(ICUDriver *icup) {
/* All interrupts disabled.*/
icup->tim->DIER &= ~STM32_TIM_DIER_IRQ_MASK;

View File

@ -361,6 +361,19 @@ struct ICUDriver {
*/
#define icu_lld_get_period(icup) (*((icup)->pccrp) + 1)
/**
* @brief Check on notifications status.
*
* @param[in] icup pointer to the @p ICUDriver object
* @return The notifications status.
* @retval false if notifications are not enabled.
* @retval true if notifications are enabled.
*
* @notapi
*/
#define icu_lld_are_notifications_enabled(icup) \
(bool)(((icup)->tim->DIER & STM32_TIM_DIER_IRQ_MASK) != 0)
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@ -402,8 +415,8 @@ extern "C" {
void icu_lld_start_capture(ICUDriver *icup);
void icu_lld_wait_capture(ICUDriver *icup);
void icu_lld_stop_capture(ICUDriver *icup);
void icu_enable_notifications(ICUDriver *icup);
void icu_disable_notifications(ICUDriver *icup);
void icu_lld_enable_notifications(ICUDriver *icup);
void icu_lld_disable_notifications(ICUDriver *icup);
#ifdef __cplusplus
}
#endif

View File

@ -134,6 +134,11 @@ void icuStartCapture(ICUDriver *icup) {
/**
* @brief Waits for a completed capture.
* @note The operation could be performed in polled mode depending on.
* @note In order to use this function notifications must be disabled.
* @pre The driver must be in @p ICU_WAITING or @p ICU_ACTIVE modes.
* @post After the capture is available the driver is in @p ICU_ACTIVE
* mode.
*
* @param[in] icup pointer to the @p ICUDriver object
*
@ -146,7 +151,10 @@ void icuWaitCapture(ICUDriver *icup) {
osalSysLock();
osalDbgAssert((icup->state == ICU_WAITING) || (icup->state == ICU_ACTIVE),
"invalid state");
icuWaitCaptureI(icup);
osalDbgAssert(icuAreNotificationsEnabledX(icup) == false,
"notifications enabled");
icu_lld_wait_capture(icup);
icup->state = ICU_ACTIVE;
osalSysUnlock();
}