ChibiOS/HAL 9.0.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:
PLATFORM configuration options | |
#define | PLATFORM_GPT_USE_GPT1 FALSE |
GPTD1 driver enable switch. |
Data Structures | |
struct | GPTConfig |
Driver configuration structure. More... | |
struct | GPTDriver |
Structure representing a GPT driver. More... |
Macros | |
#define | gptChangeIntervalI(gptp, interval) |
Changes the interval of GPT peripheral. | |
#define | gptGetIntervalX(gptp) |
Returns the interval of GPT peripheral. | |
#define | gptGetCounterX(gptp) |
Returns the counter value of GPT peripheral. | |
#define | _gpt_isr_invoke_cb(gptp) |
Common ISR code, GPT period event. | |
#define | gpt_lld_change_interval(gptp, interval) |
Changes the interval of GPT peripheral. |
Typedefs | |
typedef struct GPTDriver | GPTDriver |
Type of a structure representing a GPT driver. | |
typedef void(* | gptcallback_t) (GPTDriver *gptp) |
GPT notification callback type. | |
typedef uint32_t | gptfreq_t |
GPT frequency type. | |
typedef uint16_t | gptcnt_t |
GPT counter type. |
Enumerations | |
enum | gptstate_t { GPT_UNINIT = 0 , GPT_STOP = 1 , GPT_READY = 2 , GPT_CONTINUOUS = 3 , GPT_ONESHOT = 4 } |
Driver state machine possible states. More... |
Functions | |
void | gptInit (void) |
GPT Driver initialization. | |
void | gptObjectInit (GPTDriver *gptp) |
Initializes the standard part of a GPTDriver structure. | |
msg_t | gptStart (GPTDriver *gptp, const GPTConfig *config) |
Configures and activates the GPT peripheral. | |
void | gptStop (GPTDriver *gptp) |
Deactivates the GPT peripheral. | |
void | gptChangeInterval (GPTDriver *gptp, gptcnt_t interval) |
Changes the interval of GPT peripheral. | |
void | gptStartContinuous (GPTDriver *gptp, gptcnt_t interval) |
Starts the timer in continuous mode. | |
void | gptStartContinuousI (GPTDriver *gptp, gptcnt_t interval) |
Starts the timer in continuous mode. | |
void | gptStartOneShot (GPTDriver *gptp, gptcnt_t interval) |
Starts the timer in one shot mode. | |
void | gptStartOneShotI (GPTDriver *gptp, gptcnt_t interval) |
Starts the timer in one shot mode. | |
void | gptStopTimer (GPTDriver *gptp) |
Stops the timer. | |
void | gptStopTimerI (GPTDriver *gptp) |
Stops the timer. | |
void | gptPolledDelay (GPTDriver *gptp, gptcnt_t interval) |
Starts the timer in one shot mode and waits for completion. | |
void | gpt_lld_init (void) |
Low level GPT driver initialization. | |
void | gpt_lld_start (GPTDriver *gptp) |
Configures and activates the GPT peripheral. | |
void | gpt_lld_stop (GPTDriver *gptp) |
Deactivates the GPT peripheral. | |
void | gpt_lld_start_timer (GPTDriver *gptp, gptcnt_t interval) |
Starts the timer in continuous mode. | |
void | gpt_lld_stop_timer (GPTDriver *gptp) |
Stops the timer. | |
void | gpt_lld_polled_delay (GPTDriver *gptp, gptcnt_t interval) |
Starts the timer in one shot mode and waits for completion. |
Variables | |
GPTDriver | GPTD1 |
GPTD1 driver identifier. |
#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 | ) |
Returns the interval of GPT peripheral.
[in] | gptp | pointer to a GPTDriver object |
#define gptGetCounterX | ( | gptp | ) |
Returns the counter value of GPT peripheral.
[in] | gptp | pointer to a GPTDriver object |
#define _gpt_isr_invoke_cb | ( | gptp | ) |
Common ISR code, GPT period event.
[in] | gptp | pointer to the 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 struct GPTDriver GPTDriver |
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 83 of file hal_gpt.c.
References GPTDriver::config, gpt_lld_start(), GPT_READY, GPT_STOP, HAL_RET_SUCCESS, 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 121 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 148 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 167 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 182 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 201 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 216 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 235 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 249 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 273 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 GPTD1, and 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, GPTD1, 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, GPTD1, 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.
Referenced by gpt_lld_init(), gpt_lld_start(), and gpt_lld_stop().