The MCUXpresso SDK provides a driver for the General Purpose Timer (GPT) of MCUXpresso SDK devices.
Function groups
The gpt driver supports the generation of PWM signals, input capture, and setting up the timer match conditions.
Initialization and deinitialization
The function GPT_Init() initializes the gpt with specified configurations. The function GPT_GetDefaultConfig() gets the default configurations. The initialization function configures the restart/free-run mode and input selection when running.
The function GPT_Deinit() stops the timer and turns off the module clock.
Typical use case
GPT interrupt example
Set up a channel to trigger a periodic interrupt after every 1 second. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/gpt
|
enum | gpt_clock_source_t {
kGPT_ClockSource_Off = 0U,
kGPT_ClockSource_Periph = 1U,
kGPT_ClockSource_HighFreq = 2U,
kGPT_ClockSource_Ext = 3U,
kGPT_ClockSource_LowFreq = 4U,
kGPT_ClockSource_Osc = 5U
} |
| List of clock sources. More...
|
|
enum | gpt_input_capture_channel_t {
kGPT_InputCapture_Channel1 = 0U,
kGPT_InputCapture_Channel2 = 1U
} |
| List of input capture channel number. More...
|
|
enum | gpt_input_operation_mode_t {
kGPT_InputOperation_Disabled = 0U,
kGPT_InputOperation_RiseEdge = 1U,
kGPT_InputOperation_FallEdge = 2U,
kGPT_InputOperation_BothEdge = 3U
} |
| List of input capture operation mode. More...
|
|
enum | gpt_output_compare_channel_t {
kGPT_OutputCompare_Channel1 = 0U,
kGPT_OutputCompare_Channel2 = 1U,
kGPT_OutputCompare_Channel3 = 2U
} |
| List of output compare channel number. More...
|
|
enum | gpt_output_operation_mode_t {
kGPT_OutputOperation_Disconnected = 0U,
kGPT_OutputOperation_Toggle = 1U,
kGPT_OutputOperation_Clear = 2U,
kGPT_OutputOperation_Set = 3U,
kGPT_OutputOperation_Activelow = 4U
} |
| List of output compare operation mode. More...
|
|
enum | gpt_interrupt_enable_t {
kGPT_OutputCompare1InterruptEnable = GPT_IR_OF1IE_MASK,
kGPT_OutputCompare2InterruptEnable = GPT_IR_OF2IE_MASK,
kGPT_OutputCompare3InterruptEnable = GPT_IR_OF3IE_MASK,
kGPT_InputCapture1InterruptEnable = GPT_IR_IF1IE_MASK,
kGPT_InputCapture2InterruptEnable = GPT_IR_IF2IE_MASK,
kGPT_RollOverFlagInterruptEnable = GPT_IR_ROVIE_MASK
} |
| List of GPT interrupts. More...
|
|
enum | gpt_status_flag_t {
kGPT_OutputCompare1Flag = GPT_SR_OF1_MASK,
kGPT_OutputCompare2Flag = GPT_SR_OF2_MASK,
kGPT_OutputCompare3Flag = GPT_SR_OF3_MASK,
kGPT_InputCapture1Flag = GPT_SR_IF1_MASK,
kGPT_InputCapture2Flag = GPT_SR_IF2_MASK,
kGPT_RollOverFlag = GPT_SR_ROV_MASK
} |
| Status flag. More...
|
|
|
static void | GPT_SetInputOperationMode (GPT_Type *base, gpt_input_capture_channel_t channel, gpt_input_operation_mode_t mode) |
| Set GPT operation mode of input capture channel. More...
|
|
static gpt_input_operation_mode_t | GPT_GetInputOperationMode (GPT_Type *base, gpt_input_capture_channel_t channel) |
| Get GPT operation mode of input capture channel. More...
|
|
static uint32_t | GPT_GetInputCaptureValue (GPT_Type *base, gpt_input_capture_channel_t channel) |
| Get GPT input capture value of certain channel. More...
|
|
static void | GPT_SetOutputOperationMode (GPT_Type *base, gpt_output_compare_channel_t channel, gpt_output_operation_mode_t mode) |
| Set GPT operation mode of output compare channel. More...
|
|
static gpt_output_operation_mode_t | GPT_GetOutputOperationMode (GPT_Type *base, gpt_output_compare_channel_t channel) |
| Get GPT operation mode of output compare channel. More...
|
|
static void | GPT_SetOutputCompareValue (GPT_Type *base, gpt_output_compare_channel_t channel, uint32_t value) |
| Set GPT output compare value of output compare channel. More...
|
|
static uint32_t | GPT_GetOutputCompareValue (GPT_Type *base, gpt_output_compare_channel_t channel) |
| Get GPT output compare value of output compare channel. More...
|
|
static void | GPT_ForceOutput (GPT_Type *base, gpt_output_compare_channel_t channel) |
| Force GPT output action on output compare channel, ignoring comparator. More...
|
|
uint32_t gpt_config_t::divider |
bool gpt_config_t::enableFreeRun |
bool gpt_config_t::enableRunInWait |
bool gpt_config_t::enableRunInStop |
bool gpt_config_t::enableRunInDoze |
bool gpt_config_t::enableRunInDbg |
bool gpt_config_t::enableMode |
- Note
- Actual number of clock sources is SoC dependent
Enumerator |
---|
kGPT_ClockSource_Off |
GPT Clock Source Off.
|
kGPT_ClockSource_Periph |
GPT Clock Source from Peripheral Clock.
|
kGPT_ClockSource_HighFreq |
GPT Clock Source from High Frequency Reference Clock.
|
kGPT_ClockSource_Ext |
GPT Clock Source from external pin.
|
kGPT_ClockSource_LowFreq |
GPT Clock Source from Low Frequency Reference Clock.
|
kGPT_ClockSource_Osc |
GPT Clock Source from Crystal oscillator.
|
Enumerator |
---|
kGPT_InputCapture_Channel1 |
GPT Input Capture Channel1.
|
kGPT_InputCapture_Channel2 |
GPT Input Capture Channel2.
|
Enumerator |
---|
kGPT_InputOperation_Disabled |
Don't capture.
|
kGPT_InputOperation_RiseEdge |
Capture on rising edge of input pin.
|
kGPT_InputOperation_FallEdge |
Capture on falling edge of input pin.
|
kGPT_InputOperation_BothEdge |
Capture on both edges of input pin.
|
Enumerator |
---|
kGPT_OutputCompare_Channel1 |
Output Compare Channel1.
|
kGPT_OutputCompare_Channel2 |
Output Compare Channel2.
|
kGPT_OutputCompare_Channel3 |
Output Compare Channel3.
|
Enumerator |
---|
kGPT_OutputOperation_Disconnected |
Don't change output pin.
|
kGPT_OutputOperation_Toggle |
Toggle output pin.
|
kGPT_OutputOperation_Clear |
Set output pin low.
|
kGPT_OutputOperation_Set |
Set output pin high.
|
kGPT_OutputOperation_Activelow |
Generate a active low pulse on output pin.
|
Enumerator |
---|
kGPT_OutputCompare1InterruptEnable |
Output Compare Channel1 interrupt enable.
|
kGPT_OutputCompare2InterruptEnable |
Output Compare Channel2 interrupt enable.
|
kGPT_OutputCompare3InterruptEnable |
Output Compare Channel3 interrupt enable.
|
kGPT_InputCapture1InterruptEnable |
Input Capture Channel1 interrupt enable.
|
kGPT_InputCapture2InterruptEnable |
Input Capture Channel1 interrupt enable.
|
kGPT_RollOverFlagInterruptEnable |
Counter rolled over interrupt enable.
|
Enumerator |
---|
kGPT_OutputCompare1Flag |
Output compare channel 1 event.
|
kGPT_OutputCompare2Flag |
Output compare channel 2 event.
|
kGPT_OutputCompare3Flag |
Output compare channel 3 event.
|
kGPT_InputCapture1Flag |
Input Capture channel 1 event.
|
kGPT_InputCapture2Flag |
Input Capture channel 2 event.
|
kGPT_RollOverFlag |
Counter reaches maximum value and rolled over to 0 event.
|
void GPT_Init |
( |
GPT_Type * |
base, |
|
|
const gpt_config_t * |
initConfig |
|
) |
| |
- Parameters
-
base | GPT peripheral base address. |
initConfig | GPT mode setting configuration. |
void GPT_Deinit |
( |
GPT_Type * |
base | ) |
|
- Parameters
-
base | GPT peripheral base address. |
The default values are:
* config->divider = 1U;
* config->enableRunInStop = true;
* config->enableRunInWait = true;
* config->enableRunInDoze = false;
* config->enableRunInDbg = false;
* config->enableFreeRun = false;
* config->enableMode = true;
*
- Parameters
-
config | Pointer to the user configuration structure. |
static void GPT_SoftwareReset |
( |
GPT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address. |
- Parameters
-
base | GPT peripheral base address. |
source | Clock source (see gpt_clock_source_t typedef enumeration). |
- Parameters
-
base | GPT peripheral base address. |
- Returns
- clock source (see gpt_clock_source_t typedef enumeration).
static void GPT_SetClockDivider |
( |
GPT_Type * |
base, |
|
|
uint32_t |
divider |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address. |
divider | Divider of GPT (1-4096). |
static uint32_t GPT_GetClockDivider |
( |
GPT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address. |
- Returns
- clock divider in GPT module (1-4096).
static void GPT_SetOscClockDivider |
( |
GPT_Type * |
base, |
|
|
uint32_t |
divider |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address. |
divider | OSC Divider(1-16). |
static uint32_t GPT_GetOscClockDivider |
( |
GPT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address. |
- Returns
- OSC clock divider in GPT module (1-16).
static void GPT_StartTimer |
( |
GPT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address. |
static void GPT_StopTimer |
( |
GPT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address. |
static uint32_t GPT_GetCurrentTimerCount |
( |
GPT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address. |
- Returns
- Current GPT counter value.
- Parameters
-
- Returns
- GPT input capture value.
- Parameters
-
base | GPT peripheral base address. |
channel | GPT output compare channel (see gpt_output_compare_channel_t typedef enumeration). |
value | GPT output compare value. |
- Parameters
-
- Returns
- GPT output compare value.
static void GPT_EnableInterrupts |
( |
GPT_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address. |
mask | The interrupts to enable. This is a logical OR of members of the enumeration gpt_interrupt_enable_t |
static void GPT_DisableInterrupts |
( |
GPT_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address |
mask | The interrupts to disable. This is a logical OR of members of the enumeration gpt_interrupt_enable_t |
static uint32_t GPT_GetEnabledInterrupts |
( |
GPT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | GPT peripheral base address |
- Returns
- The enabled interrupts. This is the logical OR of members of the enumeration gpt_interrupt_enable_t
- Parameters
-
base | GPT peripheral base address. |
flags | GPT status flag mask (see gpt_status_flag_t for bit definition). |
- Returns
- GPT status, each bit represents one status flag.
- Parameters
-
base | GPT peripheral base address. |
flags | GPT status flag mask (see gpt_status_flag_t for bit definition). |