ChibiOS/HAL
6.1.0
|
Generic ICU Driver. More...
Generic ICU Driver.
This module implements a generic ICU (Input Capture Unit) driver. The purpose of the driver is to measure period and duty cycle of an input digital signal (PWM input).
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:
Callbacks are optionally invoked when:
icuGetPeriodX()
and icuGetWidthX()
.Macros | |
#define | icu_lld_get_width(icup) 0 |
Returns the width of the latest pulse. More... | |
#define | icu_lld_get_period(icup) 0 |
Returns the width of the latest cycle. More... | |
#define | icu_lld_are_notifications_enabled(icup) false |
Check on notifications status. More... | |
Macro Functions | |
#define | icuStartCaptureI(icup) |
Starts the input capture. More... | |
#define | icuStopCaptureI(icup) |
Stops the input capture. More... | |
#define | icuEnableNotificationsI(icup) icu_lld_enable_notifications(icup) |
Enables notifications. More... | |
#define | icuDisableNotificationsI(icup) icu_lld_disable_notifications(icup) |
Disables notifications. More... | |
#define | icuAreNotificationsEnabledX(icup) icu_lld_are_notifications_enabled(icup) |
Check on notifications status. More... | |
#define | icuGetWidthX(icup) icu_lld_get_width(icup) |
Returns the width of the latest pulse. More... | |
#define | icuGetPeriodX(icup) icu_lld_get_period(icup) |
Returns the width of the latest cycle. More... | |
Low level driver helper macros | |
#define | _icu_isr_invoke_width_cb(icup) |
Common ISR code, ICU width event. More... | |
#define | _icu_isr_invoke_period_cb(icup) |
Common ISR code, ICU period event. More... | |
#define | _icu_isr_invoke_overflow_cb(icup) |
Common ISR code, ICU timer overflow event. More... | |
PLATFORM configuration options | |
#define | PLATFORM_ICU_USE_ICU1 FALSE |
ICUD1 driver enable switch. More... | |
Typedefs | |
typedef struct ICUDriver | ICUDriver |
Type of a structure representing an ICU driver. More... | |
typedef void(* | icucallback_t) (ICUDriver *icup) |
ICU notification callback type. More... | |
typedef uint32_t | icufreq_t |
ICU frequency type. More... | |
typedef uint32_t | icucnt_t |
ICU counter type. More... | |
Data Structures | |
struct | ICUConfig |
Driver configuration structure. More... | |
struct | ICUDriver |
Structure representing an ICU driver. More... | |
Functions | |
void | icuInit (void) |
ICU Driver initialization. More... | |
void | icuObjectInit (ICUDriver *icup) |
Initializes the standard part of a ICUDriver structure. More... | |
void | icuStart (ICUDriver *icup, const ICUConfig *config) |
Configures and activates the ICU peripheral. More... | |
void | icuStop (ICUDriver *icup) |
Deactivates the ICU peripheral. More... | |
void | icuStartCapture (ICUDriver *icup) |
Starts the input capture. More... | |
bool | icuWaitCapture (ICUDriver *icup) |
Waits for a completed capture. More... | |
void | icuStopCapture (ICUDriver *icup) |
Stops the input capture. More... | |
void | icuEnableNotifications (ICUDriver *icup) |
Enables notifications. More... | |
void | icuDisableNotifications (ICUDriver *icup) |
Disables notifications. More... | |
void | icu_lld_init (void) |
Low level ICU driver initialization. More... | |
void | icu_lld_start (ICUDriver *icup) |
Configures and activates the ICU peripheral. More... | |
void | icu_lld_stop (ICUDriver *icup) |
Deactivates the ICU peripheral. More... | |
void | icu_lld_start_capture (ICUDriver *icup) |
Starts the input capture. More... | |
bool | icu_lld_wait_capture (ICUDriver *icup) |
Waits for a completed capture. More... | |
void | icu_lld_stop_capture (ICUDriver *icup) |
Stops the input capture. More... | |
void | icu_lld_enable_notifications (ICUDriver *icup) |
Enables notifications. More... | |
void | icu_lld_disable_notifications (ICUDriver *icup) |
Disables notifications. More... | |
Enumerations |
Variables | |
ICUDriver | ICUD1 |
ICUD1 driver identifier. More... | |
#define icuStartCaptureI | ( | icup | ) |
Starts the input capture.
[in] | icup | pointer to the ICUDriver object |
Definition at line 86 of file hal_icu.h.
Referenced by icuStartCapture().
#define icuStopCaptureI | ( | icup | ) |
Stops the input capture.
[in] | icup | pointer to the ICUDriver object |
Definition at line 98 of file hal_icu.h.
Referenced by icuStopCapture().
#define icuEnableNotificationsI | ( | icup | ) | icu_lld_enable_notifications(icup) |
Enables notifications.
icuStart()
and the capture started using icuStartCapture()
. [in] | icup | pointer to the ICUDriver object |
Definition at line 113 of file hal_icu.h.
Referenced by icuEnableNotifications().
#define icuDisableNotificationsI | ( | icup | ) | icu_lld_disable_notifications(icup) |
Disables notifications.
icuStart()
and the capture started using icuStartCapture()
. [in] | icup | pointer to the ICUDriver object |
Definition at line 125 of file hal_icu.h.
Referenced by icuDisableNotifications().
#define icuAreNotificationsEnabledX | ( | icup | ) | icu_lld_are_notifications_enabled(icup) |
Check on notifications status.
[in] | icup | pointer to the ICUDriver object |
false | if notifications are not enabled. |
true | if notifications are enabled. |
Definition at line 137 of file hal_icu.h.
Referenced by icuWaitCapture().
#define icuGetWidthX | ( | 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 icuGetPeriodX | ( | 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 | ) |
Common ISR code, ICU width event.
[in] | icup | pointer to the ICUDriver object |
#define _icu_isr_invoke_period_cb | ( | icup | ) |
Common ISR code, ICU period event.
ICU_ACTIVE
state.[in] | icup | pointer to the ICUDriver object |
#define _icu_isr_invoke_overflow_cb | ( | icup | ) |
Common ISR code, ICU timer overflow event.
ICU_WAITING
state.[in] | icup | pointer to the ICUDriver object |
#define PLATFORM_ICU_USE_ICU1 FALSE |
ICUD1 driver enable switch.
If set to TRUE
the support for ICUD1 is included.
FALSE
. Definition at line 48 of file hal_icu_lld.h.
#define icu_lld_get_width | ( | icup | ) | 0 |
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 |
Definition at line 140 of file hal_icu_lld.h.
#define icu_lld_get_period | ( | icup | ) | 0 |
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 |
Definition at line 152 of file hal_icu_lld.h.
#define icu_lld_are_notifications_enabled | ( | icup | ) | false |
Check on notifications status.
[in] | icup | pointer to the ICUDriver object |
false | if notifications are not enabled. |
true | if notifications are enabled. |
Definition at line 164 of file hal_icu_lld.h.
typedef void(* icucallback_t) (ICUDriver *icup) |
typedef uint32_t icufreq_t |
ICU frequency type.
Definition at line 71 of file hal_icu_lld.h.
typedef uint32_t icucnt_t |
ICU counter type.
Definition at line 76 of file hal_icu_lld.h.
enum icustate_t |
enum icumode_t |
ICU driver mode.
Enumerator | |
---|---|
ICU_INPUT_ACTIVE_HIGH |
Trigger on rising edge. |
ICU_INPUT_ACTIVE_LOW |
Trigger on falling edge. |
Definition at line 63 of file hal_icu_lld.h.
void icuInit | ( | void | ) |
ICU Driver initialization.
halInit()
, there is no need to explicitly initialize the driver.Definition at line 56 of file hal_icu.c.
References icu_lld_init().
Referenced by halInit().
void icuObjectInit | ( | ICUDriver * | icup | ) |
Initializes the standard part of a ICUDriver
structure.
[out] | icup | pointer to the ICUDriver object |
Definition at line 68 of file hal_icu.c.
References ICUDriver::config, ICU_STOP, and ICUDriver::state.
Referenced by icu_lld_init().
Configures and activates the ICU peripheral.
Definition at line 82 of file hal_icu.c.
References ICUDriver::config, icu_lld_start(), ICU_READY, ICU_STOP, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and ICUDriver::state.
void icuStop | ( | ICUDriver * | icup | ) |
Deactivates the ICU peripheral.
[in] | icup | pointer to the ICUDriver object |
Definition at line 102 of file hal_icu.c.
References ICUDriver::config, icu_lld_stop(), ICU_READY, ICU_STOP, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and ICUDriver::state.
void icuStartCapture | ( | ICUDriver * | icup | ) |
Starts the input capture.
[in] | icup | pointer to the ICUDriver object |
Definition at line 125 of file hal_icu.c.
References ICU_READY, icuStartCaptureI, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and ICUDriver::state.
bool icuWaitCapture | ( | ICUDriver * | icup | ) |
Waits for a completed capture.
ICU_WAITING
or ICU_ACTIVE
states. ICU_ACTIVE
state. If a capture fails then the driver is in ICU_WAITING
state.[in] | icup | pointer to the ICUDriver object |
false | if the capture is successful. |
true | if a timer overflow occurred. |
Definition at line 151 of file hal_icu.c.
References ICU_ACTIVE, icu_lld_wait_capture(), ICU_WAITING, icuAreNotificationsEnabledX, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and ICUDriver::state.
void icuStopCapture | ( | ICUDriver * | icup | ) |
Stops the input capture.
[in] | icup | pointer to the ICUDriver object |
Definition at line 175 of file hal_icu.c.
References ICU_ACTIVE, ICU_READY, ICU_WAITING, icuStopCaptureI, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and ICUDriver::state.
void icuEnableNotifications | ( | ICUDriver * | icup | ) |
Enables notifications.
icuStart()
and the capture started using icuStartCapture()
. [in] | icup | pointer to the ICUDriver object |
Definition at line 197 of file hal_icu.c.
References ICU_ACTIVE, ICU_WAITING, icuEnableNotificationsI, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and ICUDriver::state.
void icuDisableNotifications | ( | ICUDriver * | icup | ) |
Disables notifications.
icuStart()
and the capture started using icuStartCapture()
. [in] | icup | pointer to the ICUDriver object |
Definition at line 218 of file hal_icu.c.
References ICU_ACTIVE, ICU_WAITING, icuDisableNotificationsI, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and ICUDriver::state.
void icu_lld_init | ( | void | ) |
Low level ICU driver initialization.
Definition at line 66 of file hal_icu_lld.c.
References icuObjectInit().
Referenced by icuInit().
void icu_lld_start | ( | ICUDriver * | icup | ) |
Configures and activates the ICU peripheral.
[in] | icup | pointer to the ICUDriver object |
Definition at line 81 of file hal_icu_lld.c.
References ICU_STOP, and ICUDriver::state.
Referenced by icuStart().
void icu_lld_stop | ( | ICUDriver * | icup | ) |
Deactivates the ICU peripheral.
[in] | icup | pointer to the ICUDriver object |
Definition at line 100 of file hal_icu_lld.c.
References ICU_READY, and ICUDriver::state.
Referenced by icuStop().
void icu_lld_start_capture | ( | ICUDriver * | icup | ) |
Starts the input capture.
[in] | icup | pointer to the ICUDriver object |
Definition at line 119 of file hal_icu_lld.c.
bool icu_lld_wait_capture | ( | ICUDriver * | icup | ) |
Waits for a completed capture.
[in] | icup | pointer to the ICUDriver object |
false | if the capture is successful. |
true | if a timer overflow occurred. |
Definition at line 136 of file hal_icu_lld.c.
Referenced by icuWaitCapture().
void icu_lld_stop_capture | ( | ICUDriver * | icup | ) |
Stops the input capture.
[in] | icup | pointer to the ICUDriver object |
Definition at line 150 of file hal_icu_lld.c.
void icu_lld_enable_notifications | ( | ICUDriver * | icup | ) |
Enables notifications.
icuStart()
and the capture started using icuStartCapture()
. [in] | icup | pointer to the ICUDriver object |
Definition at line 165 of file hal_icu_lld.c.
void icu_lld_disable_notifications | ( | ICUDriver * | icup | ) |
Disables notifications.
icuStart()
and the capture started using icuStartCapture()
. [in] | icup | pointer to the ICUDriver object |
Definition at line 180 of file hal_icu_lld.c.
ICUDriver ICUD1 |
ICUD1 driver identifier.
Definition at line 42 of file hal_icu_lld.c.