These sections introduce the Generic Purpose Timer (GPT), including terms and acronyms, supported features.
More...
These sections introduce the Generic Purpose Timer (GPT), including terms and acronyms, supported features.
And any simple usage with these APIs and current system case of GPT are introduced in the section on how to use this driver.
Terms and Acronyms
Terms | Details |
GPT | Generic Purpose Timer |
ISR | Interrupt Service Routines |
Supported Features
Each IO-CM4 has one GPT device (which is placed on APB bus) respectively to support time calculation application.
Those GPT device units are the same. And each GPT device unit contains five timers which are designed as follows:
ID | Mode | Clock Source | Clock speed | Interrupt signal |
GPT0 | one-shot and repeat | 32kHz | 1kHz or 32kHz | GPT |
GPT1 | one-shot and repeat | 32kHz | 1kHz or 32kHz | GPT |
GPT2 | free-run | 32kHz | 1kHz or 32kHz | n/a |
GPT3 | one-shot | XTAL Clock | 1MHz | GPT3 |
GPT4 | free-run | Bus Clock | 1/2 or 1 * Bus Clock | n/a |
For more details, please refer to the GPT datasheet.
How to Use This Driver
- Software Architecture:
See Overview of M-HAL SW Architecture for the details of SW architecture.
This section describes the definition of APIs and provides an example on FreeRTOS to show how to use these APIs to develop an OS-related GPT driver.
Also, this section provides an example about the sequence of APIs that should be used by the GPT driver.
- Scope of M-HAL GPT APIs
M-HAL GPT APIs are used to control timers hardware behaviors(specify timer with the pointer of struct hal_gpt_dev and a timer ID as enum gpt_num).
- For all GPT timers, mtk_mhal_gpt_start(), mtk_mhal_gpt_stop() and mtk_mhal_gpt_restart_count() can be used to enable, disable and restart timer counter, and mtk_mhal_gpt_get_count() can be used to get counter's value.
- For timers with multiple clock speeds, mtk_mhal_gpt_config_clk() can be used to configure timer clock speeds. And for GPT3, mtk_mhal_gpt_config_clk() is still necessary to calibrate its counter frequency.
- For interrupt-based timers, mtk_mhal_gpt_set_compare() can be used to set time of interrupt trigger after timer is enabled. And mtk_mhal_gpt_config_mode() can be used to configure timer interrupt mode.
mtk_mhal_gpt_enable_irq() and mtk_mhal_gpt_disable_irq() can be used to enable and disable interrupt source of GPT timer, and mtk_mhal_gpt_get_irq_status() and mtk_mhal_gpt_clear_irq_status() can be used to get and clear interrupt status of GPT timer interrupt source.
Note:
Here, GPT3 is designed to have a fixed enable interrupt mode in the hardware. mtk_mhal_gpt_clear_irq_status() is necessary for it, but mtk_mhal_gpt_enable_irq(), mtk_mhal_gpt_disable_irq() and mtk_mhal_gpt_get_irq_status() are invalid for it, and always returns -GPT_EACCES. Enable or disable interrupt for GPT3 needs to unmask or mask the signal of upper interrupt controller.
- The OS-HAL Driver Sample Code for FreeRTOS is as follows:
freeRTos GPT sample code on github
|
| Define |
| This section introduces the macro definitions which are used by GPT M-HAL's APIs error return type.
|
|
| Enum |
| This section introduces the enumerations that GPT M-HAL used.
|
|
| Function |
| This section provides Fixed APIs(defined as Common Interface) to fully control the MediaTek GPT HW.
|
|
| Struct |
| This section introduces the structure used by GPT M-HAL used.
|
|