|
ChibiOS/RT
2.5.1 |
|
Generic ICU Driver.
This module implements a generic ICU (Input Capture Unit) driver.
HAL_USE_ICU option must be enabled in halconf.h.The driver implements a state machine internally, not all the driver functionalities can be used in any moment, any transition not explicitly shown in the following diagram has to be considered an error and shall be captured by an assertion (if enabled).
This driver abstracts a generic Input Capture Unit composed of:
The ICU unit can be programmed to synchronize on the rising or falling edge of the sample input:
After the activation the ICU unit can be in one of the following states at any time:
Callbacks are invoked when start or stop signals occur.
Functions | |
| void | icuInit (void) |
| ICU Driver initialization. | |
| void | icuObjectInit (ICUDriver *icup) |
Initializes the standard part of a ICUDriver structure. | |
| void | icuStart (ICUDriver *icup, const ICUConfig *config) |
| Configures and activates the ICU peripheral. | |
| void | icuStop (ICUDriver *icup) |
| Deactivates the ICU peripheral. | |
| void | icuEnable (ICUDriver *icup) |
| Enables the input capture. | |
| void | icuDisable (ICUDriver *icup) |
| Disables the input capture. | |
Macro Functions | |
| #define | icuEnableI(icup) icu_lld_enable(icup) |
| Enables the input capture. | |
| #define | icuDisableI(icup) icu_lld_disable(icup) |
| Disables the input capture. | |
| #define | icuGetWidth(icup) icu_lld_get_width(icup) |
| Returns the width of the latest pulse. | |
| #define | icuGetPeriod(icup) icu_lld_get_period(icup) |
| Returns the width of the latest cycle. | |
Low Level driver helper macros | |
| #define | _icu_isr_invoke_width_cb(icup) |
| Common ISR code, ICU width event. | |
| #define | _icu_isr_invoke_period_cb(icup) |
| Common ISR code, ICU period event. | |
| #define | _icu_isr_invoke_overflow_cb(icup) |
| Common ISR code, ICU timer overflow event. | |
Typedefs | |
| typedef struct ICUDriver | ICUDriver |
| Type of a structure representing an ICU driver. | |
| typedef void(* | icucallback_t )(ICUDriver *icup) |
| ICU notification callback type. | |
Enumerations | |
| enum | icustate_t { ICU_UNINIT = 0, ICU_STOP = 1, ICU_READY = 2, ICU_WAITING = 3, ICU_ACTIVE = 4, ICU_IDLE = 5 } |
| Driver state machine possible states. More... | |
| void icuInit | ( | void | ) |
ICU Driver initialization.
halInit(), there is no need to explicitly initialize the driver.Definition at line 61 of file icu.c.
Referenced by halInit().
| void icuObjectInit | ( | ICUDriver * | icup | ) |
| void icuStart | ( | ICUDriver * | icup, |
| const ICUConfig * | config | ||
| ) |
Configures and activates the ICU peripheral.
| [in] | icup | pointer to the ICUDriver object |
| [in] | config | pointer to the ICUConfig object |
Definition at line 87 of file icu.c.
References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, ICU_READY, and ICU_STOP.
| void icuStop | ( | ICUDriver * | icup | ) |
Deactivates the ICU peripheral.
| [in] | icup | pointer to the ICUDriver object |
Definition at line 107 of file icu.c.
References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, ICU_READY, and ICU_STOP.
| void icuEnable | ( | ICUDriver * | icup | ) |
Enables the input capture.
| [in] | icup | pointer to the ICUDriver object |
Definition at line 126 of file icu.c.
References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, ICU_READY, and ICU_WAITING.
| void icuDisable | ( | ICUDriver * | icup | ) |
Disables the input capture.
| [in] | icup | pointer to the ICUDriver object |
Definition at line 144 of file icu.c.
References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, ICU_ACTIVE, ICU_IDLE, ICU_READY, and ICU_WAITING.
| #define icuEnableI | ( | icup | ) | icu_lld_enable(icup) |
| #define icuDisableI | ( | icup | ) | icu_lld_disable(icup) |
| #define icuGetWidth | ( | icup | ) | icu_lld_get_width(icup) |
Returns the width of the latest pulse.
The pulse width is defined as number of ticks between the start edge and the stop edge.
| [in] | icup | pointer to the ICUDriver object |
| #define icuGetPeriod | ( | icup | ) | icu_lld_get_period(icup) |
Returns the width of the latest cycle.
The cycle width is defined as number of ticks between a start edge and the next start edge.
| [in] | icup | pointer to the ICUDriver object |
| #define _icu_isr_invoke_width_cb | ( | icup | ) |
| #define _icu_isr_invoke_period_cb | ( | icup | ) |
{ \
icustate_t previous_state = (icup)->state; \
(icup)->state = ICU_ACTIVE; \
if (previous_state != ICU_WAITING) \
(icup)->config->period_cb(icup); \
}
Common ISR code, ICU period event.
| [in] | icup | pointer to the ICUDriver object |
| #define _icu_isr_invoke_overflow_cb | ( | icup | ) |
| typedef void(* icucallback_t)(ICUDriver *icup) |
| enum icustate_t |