ChibiOS/HAL  6.1.0
GPT Driver

Generic GPT Driver. More...

Collaboration diagram for GPT Driver:

Detailed Description

Generic GPT Driver.

This module implements a generic GPT (General Purpose Timer) driver. The timer can be programmed in order to trigger callbacks after a specified time period or continuously with a specified interval.

Precondition
In order to use the GPT driver the HAL_USE_GPT 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_5.png

GPT Operations.

This driver abstracts a generic timer composed of:

The timer can operate in three different modes:

Macros

#define gptChangeIntervalI(gptp, interval)
 Changes the interval of GPT peripheral. More...
 
#define gptGetIntervalX(gptp)   gpt_lld_get_interval(gptp)
 Returns the interval of GPT peripheral. More...
 
#define gptGetCounterX(gptp)   gpt_lld_get_counter(gptp)
 Returns the counter value of GPT peripheral. More...
 
#define gpt_lld_change_interval(gptp, interval)
 Changes the interval of GPT peripheral. More...
 

PLATFORM configuration options

#define PLATFORM_GPT_USE_GPT1   FALSE
 GPTD1 driver enable switch. More...
 

Typedefs

typedef struct GPTDriver GPTDriver
 Type of a structure representing a GPT driver. More...
 
typedef void(* gptcallback_t) (GPTDriver *gptp)
 GPT notification callback type. More...
 
typedef uint32_t gptfreq_t
 GPT frequency type. More...
 
typedef uint16_t gptcnt_t
 GPT counter type. More...
 

Data Structures

struct  GPTConfig
 Driver configuration structure. More...
 
struct  GPTDriver
 Structure representing a GPT driver. More...
 

Functions

void gptInit (void)
 GPT Driver initialization. More...
 
void gptObjectInit (GPTDriver *gptp)
 Initializes the standard part of a GPTDriver structure. More...
 
void gptStart (GPTDriver *gptp, const GPTConfig *config)
 Configures and activates the GPT peripheral. More...
 
void gptStop (GPTDriver *gptp)
 Deactivates the GPT peripheral. More...
 
void gptChangeInterval (GPTDriver *gptp, gptcnt_t interval)
 Changes the interval of GPT peripheral. More...
 
void gptStartContinuous (GPTDriver *gptp, gptcnt_t interval)
 Starts the timer in continuous mode. More...
 
void gptStartContinuousI (GPTDriver *gptp, gptcnt_t interval)
 Starts the timer in continuous mode. More...
 
void gptStartOneShot (GPTDriver *gptp, gptcnt_t interval)
 Starts the timer in one shot mode. More...
 
void gptStartOneShotI (GPTDriver *gptp, gptcnt_t interval)
 Starts the timer in one shot mode. More...
 
void gptStopTimer (GPTDriver *gptp)
 Stops the timer. More...
 
void gptStopTimerI (GPTDriver *gptp)
 Stops the timer. More...
 
void gptPolledDelay (GPTDriver *gptp, gptcnt_t interval)
 Starts the timer in one shot mode and waits for completion. More...
 
void gpt_lld_init (void)
 Low level GPT driver initialization. More...
 
void gpt_lld_start (GPTDriver *gptp)
 Configures and activates the GPT peripheral. More...
 
void gpt_lld_stop (GPTDriver *gptp)
 Deactivates the GPT peripheral. More...
 
void gpt_lld_start_timer (GPTDriver *gptp, gptcnt_t interval)
 Starts the timer in continuous mode. More...
 
void gpt_lld_stop_timer (GPTDriver *gptp)
 Stops the timer. More...
 
void gpt_lld_polled_delay (GPTDriver *gptp, gptcnt_t interval)
 Starts the timer in one shot mode and waits for completion. More...
 

Enumerations

Variables

GPTDriver GPTD1
 GPTD1 driver identifier. More...
 

Macro Definition Documentation

#define gptChangeIntervalI (   gptp,
  interval 
)
Value:
{ \
gpt_lld_change_interval(gptp, interval); \
}
#define gpt_lld_change_interval(gptp, interval)
Changes the interval of GPT peripheral.
Definition: hal_gpt_lld.h:124

Changes the interval of GPT peripheral.

This function changes the interval of a running GPT unit.

Precondition
The GPT unit must be running in continuous mode.
Postcondition
The GPT unit interval is changed to the new value.
Parameters
[in]gptppointer to a GPTDriver object
[in]intervalnew cycle time in timer ticks
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 86 of file hal_gpt.h.

Referenced by gptChangeInterval().

#define gptGetIntervalX (   gptp)    gpt_lld_get_interval(gptp)

Returns the interval of GPT peripheral.

Precondition
The GPT unit must be running in continuous mode.
Parameters
[in]gptppointer to a GPTDriver object
Returns
The current interval.
Function Class:This is an X-Class API, this function can be invoked from any context.

Definition at line 99 of file hal_gpt.h.

#define gptGetCounterX (   gptp)    gpt_lld_get_counter(gptp)

Returns the counter value of GPT peripheral.

Precondition
The GPT unit must be running in continuous mode.
Note
The nature of the counter is not defined, it may count upward or downward, it could be continuously running or not.
Parameters
[in]gptppointer to a GPTDriver object
Returns
The current counter value.
Function Class:This is an X-Class API, this function can be invoked from any context.

Definition at line 112 of file hal_gpt.h.

#define PLATFORM_GPT_USE_GPT1   FALSE

GPTD1 driver enable switch.

If set to TRUE the support for GPTD1 is included.

Note
The default is FALSE.

Definition at line 48 of file hal_gpt_lld.h.

#define gpt_lld_change_interval (   gptp,
  interval 
)
Value:
{ \
(void)gptp; \
(void)interval; \
}

Changes the interval of GPT peripheral.

This function changes the interval of a running GPT unit.

Precondition
The GPT unit must have been activated using gptStart().
The GPT unit must have been running in continuous mode using gptStartContinuous().
Postcondition
The GPT unit interval is changed to the new value.
Note
The function has effect at the next cycle start.
Parameters
[in]gptppointer to a GPTDriver object
[in]intervalnew cycle time in timer ticks
Function Class:Not an API, this function is for internal use only.

Definition at line 124 of file hal_gpt_lld.h.

Typedef Documentation

typedef struct GPTDriver GPTDriver

Type of a structure representing a GPT driver.

Definition at line 60 of file hal_gpt.h.

typedef void(* gptcallback_t) (GPTDriver *gptp)

GPT notification callback type.

Parameters
[in]gptppointer to a GPTDriver object

Definition at line 67 of file hal_gpt.h.

typedef uint32_t gptfreq_t

GPT frequency type.

Definition at line 63 of file hal_gpt_lld.h.

typedef uint16_t gptcnt_t

GPT counter type.

Definition at line 68 of file hal_gpt_lld.h.

Enumeration Type Documentation

enum gptstate_t

Driver state machine possible states.

Enumerator
GPT_UNINIT 

Not initialized.

GPT_STOP 

Stopped.

GPT_READY 

Ready.

GPT_CONTINUOUS 

Active in continuous mode.

GPT_ONESHOT 

Active in one shot mode.

Definition at line 49 of file hal_gpt.h.

Function Documentation

void gptInit ( void  )

GPT 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 56 of file hal_gpt.c.

References gpt_lld_init().

Referenced by halInit().

Here is the call graph for this function:

void gptObjectInit ( GPTDriver gptp)

Initializes the standard part of a GPTDriver structure.

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

Definition at line 68 of file hal_gpt.c.

References GPTDriver::config, GPT_STOP, and GPTDriver::state.

Referenced by gpt_lld_init().

void gptStart ( GPTDriver gptp,
const GPTConfig config 
)

Configures and activates the GPT peripheral.

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

Definition at line 82 of file hal_gpt.c.

References GPTDriver::config, gpt_lld_start(), GPT_READY, GPT_STOP, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and GPTDriver::state.

Here is the call graph for this function:

void gptStop ( GPTDriver gptp)

Deactivates the GPT peripheral.

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

Definition at line 102 of file hal_gpt.c.

References GPTDriver::config, gpt_lld_stop(), GPT_READY, GPT_STOP, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and GPTDriver::state.

Here is the call graph for this function:

void gptChangeInterval ( GPTDriver gptp,
gptcnt_t  interval 
)

Changes the interval of GPT peripheral.

This function changes the interval of a running GPT unit.

Precondition
The GPT unit must be running in continuous mode.
Postcondition
The GPT unit interval is changed to the new value.
Parameters
[in]gptppointer to a GPTDriver object
[in]intervalnew cycle time in timer ticks
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 129 of file hal_gpt.c.

References GPT_CONTINUOUS, gptChangeIntervalI, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and GPTDriver::state.

Here is the call graph for this function:

void gptStartContinuous ( GPTDriver gptp,
gptcnt_t  interval 
)

Starts the timer in continuous mode.

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

Definition at line 148 of file hal_gpt.c.

References gptStartContinuousI(), osalSysLock(), and osalSysUnlock().

Here is the call graph for this function:

void gptStartContinuousI ( GPTDriver gptp,
gptcnt_t  interval 
)

Starts the timer in continuous mode.

Parameters
[in]gptppointer to the GPTDriver object
[in]intervalperiod in ticks
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 163 of file hal_gpt.c.

References GPT_CONTINUOUS, gpt_lld_start_timer(), GPT_READY, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, and GPTDriver::state.

Referenced by gptStartContinuous().

Here is the call graph for this function:

void gptStartOneShot ( GPTDriver gptp,
gptcnt_t  interval 
)

Starts the timer in one shot mode.

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

Definition at line 182 of file hal_gpt.c.

References gptStartOneShotI(), osalSysLock(), and osalSysUnlock().

Here is the call graph for this function:

void gptStartOneShotI ( GPTDriver gptp,
gptcnt_t  interval 
)

Starts the timer in one shot mode.

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

Definition at line 197 of file hal_gpt.c.

References GPTConfig::callback, GPTDriver::config, gpt_lld_start_timer(), GPT_ONESHOT, GPT_READY, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, and GPTDriver::state.

Referenced by gptStartOneShot().

Here is the call graph for this function:

void gptStopTimer ( GPTDriver gptp)

Stops the timer.

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

Definition at line 216 of file hal_gpt.c.

References gptStopTimerI(), osalSysLock(), and osalSysUnlock().

Here is the call graph for this function:

void gptStopTimerI ( GPTDriver gptp)

Stops the timer.

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

Definition at line 230 of file hal_gpt.c.

References GPT_CONTINUOUS, gpt_lld_stop_timer(), GPT_ONESHOT, GPT_READY, osalDbgAssert, osalDbgCheck, osalDbgCheckClassI, and GPTDriver::state.

Referenced by gptStopTimer().

Here is the call graph for this function:

void gptPolledDelay ( GPTDriver gptp,
gptcnt_t  interval 
)

Starts the timer in one shot mode and waits for completion.

This function specifically polls the timer waiting for completion in order to not have extra delays caused by interrupt servicing, this function is only recommended for short delays.

Note
The configured callback is not invoked when using this function.
Parameters
[in]gptppointer to the GPTDriver object
[in]intervaltime interval in ticks
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 254 of file hal_gpt.c.

References gpt_lld_polled_delay(), GPT_ONESHOT, GPT_READY, osalDbgAssert, and GPTDriver::state.

Here is the call graph for this function:

void gpt_lld_init ( void  )

Low level GPT driver initialization.

Function Class:Not an API, this function is for internal use only.

Definition at line 65 of file hal_gpt_lld.c.

References gptObjectInit().

Referenced by gptInit().

Here is the call graph for this function:

void gpt_lld_start ( GPTDriver gptp)

Configures and activates the GPT peripheral.

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

Definition at line 80 of file hal_gpt_lld.c.

References GPT_STOP, and GPTDriver::state.

Referenced by gptStart().

void gpt_lld_stop ( GPTDriver gptp)

Deactivates the GPT peripheral.

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

Definition at line 101 of file hal_gpt_lld.c.

References GPT_READY, and GPTDriver::state.

Referenced by gptStop().

void gpt_lld_start_timer ( GPTDriver gptp,
gptcnt_t  interval 
)

Starts the timer in continuous mode.

Parameters
[in]gptppointer to the GPTDriver object
[in]intervalperiod in ticks
Function Class:Not an API, this function is for internal use only.

Definition at line 123 of file hal_gpt_lld.c.

Referenced by gptStartContinuousI(), and gptStartOneShotI().

void gpt_lld_stop_timer ( GPTDriver gptp)

Stops the timer.

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

Definition at line 137 of file hal_gpt_lld.c.

Referenced by gptStopTimerI().

void gpt_lld_polled_delay ( GPTDriver gptp,
gptcnt_t  interval 
)

Starts the timer in one shot mode and waits for completion.

This function specifically polls the timer waiting for completion in order to not have extra delays caused by interrupt servicing, this function is only recommended for short delays.

Parameters
[in]gptppointer to the GPTDriver object
[in]intervaltime interval in ticks
Function Class:Not an API, this function is for internal use only.

Definition at line 154 of file hal_gpt_lld.c.

Referenced by gptPolledDelay().

Variable Documentation

GPTDriver GPTD1

GPTD1 driver identifier.

Definition at line 41 of file hal_gpt_lld.c.