ChibiOS/RT
2.5.1
ICU Driver
Collaboration diagram for ICU Driver:

Detailed Description

Generic ICU Driver.

This module implements a generic ICU (Input Capture Unit) driver.

Precondition:
In order to use the ICU driver the HAL_USE_ICU option must be enabled in halconf.h.

Driver State Machine

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).

dot_inline_dotgraph_11.png

ICU Operations.

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...

Function Documentation

void icuInit ( void  )

ICU Driver initialization.

Note:
This function is implicitly invoked by halInit(), there is no need to explicitly initialize the driver.
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 61 of file icu.c.

Referenced by halInit().

void icuObjectInit ( ICUDriver icup)

Initializes the standard part of a ICUDriver structure.

Parameters:
[out]icuppointer to the ICUDriver object
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 73 of file icu.c.

References ICU_STOP.

void icuStart ( ICUDriver icup,
const ICUConfig *  config 
)

Configures and activates the ICU peripheral.

Parameters:
[in]icuppointer to the ICUDriver object
[in]configpointer to the ICUConfig object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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.

Parameters:
[in]icuppointer to the ICUDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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.

Parameters:
[in]icuppointer to the ICUDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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.

Parameters:
[in]icuppointer to the ICUDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 144 of file icu.c.

References chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, ICU_ACTIVE, ICU_IDLE, ICU_READY, and ICU_WAITING.


Define Documentation

#define icuEnableI (   icup)    icu_lld_enable(icup)

Enables the input capture.

Parameters:
[in]icuppointer to the ICUDriver object
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 91 of file icu.h.

#define icuDisableI (   icup)    icu_lld_disable(icup)

Disables the input capture.

Parameters:
[in]icuppointer to the ICUDriver object
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 100 of file icu.h.

#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.

Note:
This function is meant to be invoked from the width capture callback only.
Parameters:
[in]icuppointer to the ICUDriver object
Returns:
The number of ticks.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 114 of file icu.h.

#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.

Note:
This function is meant to be invoked from the width capture callback only.
Parameters:
[in]icuppointer to the ICUDriver object
Returns:
The number of ticks.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 128 of file icu.h.

#define _icu_isr_invoke_width_cb (   icup)
Value:
{                                    \
  (icup)->state = ICU_IDLE;                                                 \
  (icup)->config->width_cb(icup);                                           \
}

Common ISR code, ICU width event.

Parameters:
[in]icuppointer to the ICUDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 142 of file icu.h.

#define _icu_isr_invoke_period_cb (   icup)
Value:
{                                   \
  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.

Parameters:
[in]icuppointer to the ICUDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 154 of file icu.h.

#define _icu_isr_invoke_overflow_cb (   icup)
Value:
{                                 \
  (icup)->config->overflow_cb(icup);                                        \
}

Common ISR code, ICU timer overflow event.

Parameters:
[in]icuppointer to the ICUDriver object
Function Class:
Not an API, this function is for internal use only.

Definition at line 168 of file icu.h.


Typedef Documentation

typedef struct ICUDriver ICUDriver

Type of a structure representing an ICU driver.

Definition at line 65 of file icu.h.

typedef void(* icucallback_t)(ICUDriver *icup)

ICU notification callback type.

Parameters:
[in]icuppointer to a ICUDriver object

Definition at line 72 of file icu.h.


Enumeration Type Documentation

enum icustate_t

Driver state machine possible states.

Enumerator:
ICU_UNINIT 

Not initialized.

ICU_STOP 

Stopped.

ICU_READY 

Ready.

ICU_WAITING 

Waiting first edge.

ICU_ACTIVE 

Active cycle phase.

ICU_IDLE 

Idle cycle phase.

Definition at line 53 of file icu.h.