ChibiOS/HAL
6.1.0
|
Generic GPT Driver. More...
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.
HAL_USE_GPT
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 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... | |
#define gptChangeIntervalI | ( | gptp, | |
interval | |||
) |
Changes the interval of GPT peripheral.
This function changes the interval of a running GPT unit.
[in] | gptp | pointer to a GPTDriver object |
[in] | interval | new cycle time in timer ticks |
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.
[in] | gptp | pointer to a GPTDriver object |
#define gptGetCounterX | ( | gptp | ) | gpt_lld_get_counter(gptp) |
Returns the counter value of GPT peripheral.
[in] | gptp | pointer to a GPTDriver object |
#define PLATFORM_GPT_USE_GPT1 FALSE |
GPTD1 driver enable switch.
If set to TRUE
the support for GPTD1 is included.
FALSE
. Definition at line 48 of file hal_gpt_lld.h.
#define gpt_lld_change_interval | ( | gptp, | |
interval | |||
) |
Changes the interval of GPT peripheral.
This function changes the interval of a running GPT unit.
gptStart()
. gptStartContinuous()
. [in] | gptp | pointer to a GPTDriver object |
[in] | interval | new cycle time in timer ticks |
Definition at line 124 of file hal_gpt_lld.h.
typedef void(* gptcallback_t) (GPTDriver *gptp) |
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.
enum gptstate_t |
void gptInit | ( | void | ) |
GPT Driver initialization.
halInit()
, there is no need to explicitly initialize the driver.Definition at line 56 of file hal_gpt.c.
References gpt_lld_init().
Referenced by halInit().
void gptObjectInit | ( | GPTDriver * | gptp | ) |
Initializes the standard part of a GPTDriver
structure.
[out] | gptp | pointer to the GPTDriver object |
Definition at line 68 of file hal_gpt.c.
References GPTDriver::config, GPT_STOP, and GPTDriver::state.
Referenced by gpt_lld_init().
Configures and activates the GPT peripheral.
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.
void gptStop | ( | GPTDriver * | gptp | ) |
Deactivates the GPT peripheral.
[in] | gptp | pointer to the GPTDriver object |
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.
Changes the interval of GPT peripheral.
This function changes the interval of a running GPT unit.
[in] | gptp | pointer to a GPTDriver object |
[in] | interval | new cycle time in timer ticks |
Definition at line 129 of file hal_gpt.c.
References GPT_CONTINUOUS, gptChangeIntervalI, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and GPTDriver::state.
Starts the timer in continuous mode.
[in] | gptp | pointer to the GPTDriver object |
[in] | interval | period in ticks |
Definition at line 148 of file hal_gpt.c.
References gptStartContinuousI(), osalSysLock(), and osalSysUnlock().
Starts the timer in continuous mode.
[in] | gptp | pointer to the GPTDriver object |
[in] | interval | period in ticks |
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().
Starts the timer in one shot mode.
[in] | gptp | pointer to the GPTDriver object |
[in] | interval | time interval in ticks |
Definition at line 182 of file hal_gpt.c.
References gptStartOneShotI(), osalSysLock(), and osalSysUnlock().
Starts the timer in one shot mode.
[in] | gptp | pointer to the GPTDriver object |
[in] | interval | time interval in ticks |
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().
void gptStopTimer | ( | GPTDriver * | gptp | ) |
Stops the timer.
[in] | gptp | pointer to the GPTDriver object |
Definition at line 216 of file hal_gpt.c.
References gptStopTimerI(), osalSysLock(), and osalSysUnlock().
void gptStopTimerI | ( | GPTDriver * | gptp | ) |
Stops the timer.
[in] | gptp | pointer to the GPTDriver object |
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().
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.
[in] | gptp | pointer to the GPTDriver object |
[in] | interval | time interval in ticks |
Definition at line 254 of file hal_gpt.c.
References gpt_lld_polled_delay(), GPT_ONESHOT, GPT_READY, osalDbgAssert, and GPTDriver::state.
void gpt_lld_init | ( | void | ) |
Low level GPT driver initialization.
Definition at line 65 of file hal_gpt_lld.c.
References gptObjectInit().
Referenced by gptInit().
void gpt_lld_start | ( | GPTDriver * | gptp | ) |
Configures and activates the GPT peripheral.
[in] | gptp | pointer to the GPTDriver object |
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.
[in] | gptp | pointer to the GPTDriver object |
Definition at line 101 of file hal_gpt_lld.c.
References GPT_READY, and GPTDriver::state.
Referenced by gptStop().
Starts the timer in continuous mode.
[in] | gptp | pointer to the GPTDriver object |
[in] | interval | period in ticks |
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.
[in] | gptp | pointer to the GPTDriver object |
Definition at line 137 of file hal_gpt_lld.c.
Referenced by gptStopTimerI().
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.
[in] | gptp | pointer to the GPTDriver object |
[in] | interval | time interval in ticks |
Definition at line 154 of file hal_gpt_lld.c.
Referenced by gptPolledDelay().
GPTDriver GPTD1 |
GPTD1 driver identifier.
Definition at line 41 of file hal_gpt_lld.c.