MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
GPT: General purpose timer

Overview

The MCUXpresso SDK provides a peripheral driver for the General purpose timer(GPT) module of MCUXpresso SDK devices. The GPT module contains 4 timers, timer0/1/2/3, each timer support free running mode and one-shot mode.

Data Structures

struct  gpt_timer_config_t
 GPT Timer interface structure. More...
 
struct  gpt_handle_t
 GPT timer manager handle. More...
 

Macros

#define FSL_GPT_DRIVER_VERSION   (MAKE_VERSION(2, 1, 0))
 GPT driver version 2.1.0. More...
 
#define GPT_MAX_TIMEOUT   TIMERS_TIMEOUT_TIMER0_TIMEOUT_MASK
 gpt max timeout value
 

Typedefs

typedef void(* gpt_timer_callback_t )(void *param)
 Function prototype for the timers called by the GPT driver hanlder. More...
 

Enumerations

enum  gpt_timer_id_t {
  kGPT_Timer0 = 0U,
  kGPT_Timer1 = 1U,
  kGPT_Timer2 = 2U,
  kGPT_Timer3 = 3U,
  kGPT_TimerInvalid = 0xFFU
}
 gpt timer id More...
 
enum  gpt_timer_mode_t {
  kGPT_TimerModeSingleShot = 0U,
  kGPT_TimerModeSingleFreeRunning = 1U
}
 gpt timer mode More...
 
enum  gpt_counter_resolution_t {
  kGPT_CounterResolutionInvalid = 0U,
  kGPT_CounterResolution1us = 1U,
  kGPT_CounterResolution2us = 2U,
  kGPT_CounterResolution3us = 3U,
  kGPT_CounterResolution4us = 4U,
  kGPT_CounterResolution5us = 5U,
  kGPT_CounterResolutionMax = 6U
}
 GPT counter resolution. More...
 

GPT Initialization and deinitialization

void GPT_Init (TIMERS_Type *base, const gpt_timer_config_t *config)
 Timer init. More...
 
void GPT_Deinit (TIMERS_Type *base)
 Timer deinit. More...
 

GPT functional interface

static void GPT_SetPrescalerFactor (TIMERS_Type *base, uint8_t prescalerFactor)
 GPT prescaler factor configuration. More...
 
static uint8_t GPT_GetPrescalerFactor (TIMERS_Type *base)
 GPT get prescaler factor configuration. More...
 
void GPT_StartTimer (TIMERS_Type *base, gpt_timer_id_t timer, uint32_t timeoutCount)
 Timer start specific timer. More...
 
void GPT_StopTimer (TIMERS_Type *base, gpt_timer_id_t timer)
 Timer stop specific timers. More...
 
static void GPT_SetTimerMode (TIMERS_Type *base, gpt_timer_id_t timer, gpt_timer_mode_t mode)
 Timer set timers mode. More...
 
static void GPT_EnableTimeoutStatus (TIMERS_Type *base, gpt_timer_id_t timer)
 Timer timeout status enable/disable. More...
 
static void GPT_ClearTimeoutStatus (TIMERS_Type *base, gpt_timer_id_t timer)
 Timer clear timeout status. More...
 
static bool GPT_GetTimeoutStatus (TIMERS_Type *base, gpt_timer_id_t timer)
 Timer timeout status enable/disable. More...
 
static void GPT_EnableTimeoutInterrupt (TIMERS_Type *base, gpt_timer_id_t timer, bool enable)
 Timer timeout interrupt enable/disable. More...
 
static uint32_t GPT_GetRemainCount (TIMERS_Type *base, gpt_timer_id_t timer)
 Timer get timers remain count. More...
 

GPT Timer Manager interfaces

The Timer Manager interfaces are higher level APIs.

It manage the timer channels so that upper layer can require and release the channels dynamically. Also, the Timer Manager interfaces manages the timer callback.

Note
Don't use Timer Manager interfaces together with the basic functional interfaces.
void GPT_MGR_Init (void)
 Initialize the GPT Timer Manager. More...
 
void GPT_MGR_Deinit (void)
 Deinitialize the GPT Timer Manager. More...
 
status_t GPT_MGR_Request (gpt_handle_t *handle)
 Request an available timer channel. More...
 
status_t GPT_MGR_Configure (gpt_handle_t *handle, bool enableInterrupt, uint32_t requestTime, gpt_timer_callback_t callback, void *cbParam)
 Configure the timer channel. More...
 
status_t GPT_MGR_Start (gpt_handle_t *handle)
 Start the timer channel. More...
 
status_t GPT_MGR_Stop (gpt_handle_t *handle)
 Stop the timer channel. More...
 
status_t GPT_MGR_Restart (gpt_handle_t *handle)
 Restart the timer channel. More...
 
status_t GPT_MGR_Reset (gpt_handle_t *handle)
 Reset the timer channel. More...
 
status_t GPT_MGR_Release (gpt_handle_t *handle)
 Release the timer channel. More...
 
status_t GPT_MGR_Poll (gpt_handle_t *handle)
 Checks if timer has expired in polling mode. More...
 
bool GPT_MGR_IsFree (gpt_handle_t *handle)
 Checks if timer is in used. More...
 
status_t GPT_MGR_ChangeCounterResolution (gpt_counter_resolution_t resolution)
 Change the prescaler to change the timer counter resolution. More...
 
gpt_counter_resolution_t GPT_MGR_GetCounterResolution (void)
 Get current timer counter resolution. More...
 

Data Structure Documentation

struct gpt_timer_config_t

Data Fields

uint8_t prescalerFactor
 The prescalerFactor will count at system frequency and generates a tick signal used by the different timers to decrement their counter. More...
 

Field Documentation

uint8_t gpt_timer_config_t::prescalerFactor

As soon as a non-zero value is loaded into field PRESCALING_VALUE of the TIMERS_PRESCALER_REG, the prescaler will decrement a counter at every clock cycle, starting from the prescalerFactor. Once the counter reaches zero, it generates a one cycle tick signal which will be used by the timers to decrement their TIMERS_[TIMER]_COUNT_REG. It will then start again counting from the prescalerFactor. The prescaler will stop counting if prescalerFactor is set to 0

struct gpt_handle_t

Data Fields

uint32_t timerPeriod
 Timer period. More...
 
gpt_timer_callback_t callback
 Timer callback. More...
 
void * cbParam
 Timer callback parameter. More...
 
gpt_timer_id_t timerID
 Timer ID. More...
 
bool enableInterrupt
 Enable interrupt or using polling mode. More...
 

Field Documentation

uint32_t gpt_handle_t::timerPeriod
gpt_timer_callback_t gpt_handle_t::callback
void* gpt_handle_t::cbParam
gpt_timer_id_t gpt_handle_t::timerID
bool gpt_handle_t::enableInterrupt

Macro Definition Documentation

#define FSL_GPT_DRIVER_VERSION   (MAKE_VERSION(2, 1, 0))

Typedef Documentation

typedef void(* gpt_timer_callback_t)(void *param)

Enumeration Type Documentation

Enumerator
kGPT_Timer0 

timer 0

kGPT_Timer1 

timer 1

kGPT_Timer2 

timer 2

kGPT_Timer3 

timer 3

kGPT_TimerInvalid 

Invalid timer.

Enumerator
kGPT_TimerModeSingleShot 

Single shot mode.

kGPT_TimerModeSingleFreeRunning 

Free running mode.

Enumerator
kGPT_CounterResolutionInvalid 

Invalid parameter.

kGPT_CounterResolution1us 

Prescalar corresponding to 1us resolution.

kGPT_CounterResolution2us 

Prescalar corresponding to 2us resolution.

kGPT_CounterResolution3us 

Prescalar corresponding to 3us resolution.

kGPT_CounterResolution4us 

Prescalar corresponding to 4us resolution.

kGPT_CounterResolution5us 

Prescalar corresponding to 5us resolution.

kGPT_CounterResolutionMax 

Invalid parameter.

Function Documentation

void GPT_Init ( TIMERS_Type *  base,
const gpt_timer_config_t config 
)
Parameters
basetimer base pointer.
configtimer configuration pointer
void GPT_Deinit ( TIMERS_Type *  base)
Parameters
basetimer base pointer.
static void GPT_SetPrescalerFactor ( TIMERS_Type *  base,
uint8_t  prescalerFactor 
)
inlinestatic

The prescalerFactor will count at system frequency and generates a tick signal used by the different timers to decrement their counter. As soon as a non-zero value is loaded into field PRESCALING_VALUE of the TIMERS_PRESCALER_REG, the prescaler will decrement a counter at every clock cycle, starting from the prescalerFactor. Once the counter reaches zero, it generates a one cycle tick signal which will be used by the timers to decrement their TIMERS_[TIMERx|WDG]_COUNT_REG. It will then start again counting from the prescalerFactor. The prescaler will stop counting if prescalerFactor is set to 0

Parameters
basetimer base pointer.
prescalerFactorThe prescaler factor value.
static uint8_t GPT_GetPrescalerFactor ( TIMERS_Type *  base)
inlinestatic
Parameters
basetimer base pointer.
Return values
prescalerFactorvalue.
void GPT_StartTimer ( TIMERS_Type *  base,
gpt_timer_id_t  timer,
uint32_t  timeoutCount 
)
Parameters
basetimer base pointer.
timerthe specific timer to be start.
timeoutCountthe initial timeout count of the timer. The total timeout time is determined by (1 / timerCountingFreq_Hz) * timeoutCount.
void GPT_StopTimer ( TIMERS_Type *  base,
gpt_timer_id_t  timer 
)
Parameters
basetimer base pointer.
timerthe specific timer to be stop.
static void GPT_SetTimerMode ( TIMERS_Type *  base,
gpt_timer_id_t  timer,
gpt_timer_mode_t  mode 
)
inlinestatic
Parameters
basetimer base pointer.
timerthe specific timer to be configured.
modetimers mode.
static void GPT_EnableTimeoutStatus ( TIMERS_Type *  base,
gpt_timer_id_t  timer 
)
inlinestatic
Parameters
basetimer base pointer.
timerthe specific timer to be stop.
static void GPT_ClearTimeoutStatus ( TIMERS_Type *  base,
gpt_timer_id_t  timer 
)
inlinestatic
Parameters
basetimer base pointer.
timerthe specific timer to be stop.
static bool GPT_GetTimeoutStatus ( TIMERS_Type *  base,
gpt_timer_id_t  timer 
)
inlinestatic
Parameters
basetimer base pointer.
timerthe specific timer to be stop.
Return values
trueis the timer timeout, false is the timeout still not timeout.
static void GPT_EnableTimeoutInterrupt ( TIMERS_Type *  base,
gpt_timer_id_t  timer,
bool  enable 
)
inlinestatic
Parameters
basetimer base pointer.
timerthe specific timer to be stop.
static uint32_t GPT_GetRemainCount ( TIMERS_Type *  base,
gpt_timer_id_t  timer 
)
inlinestatic
Parameters
basetimer base pointer.
timerthe specific timer id.
void GPT_MGR_Init ( void  )

Initializes the GPT registers and driver internal state.

void GPT_MGR_Deinit ( void  )

Deinitialize the GPT registers and driver internal state.

status_t GPT_MGR_Request ( gpt_handle_t handle)
Parameters
handleThe handle for the timer channel.
Return values
kStatus_SuccessRequested successfully.
kStatus_BusyRequest failed because all channels are busy.
status_t GPT_MGR_Configure ( gpt_handle_t handle,
bool  enableInterrupt,
uint32_t  requestTime,
gpt_timer_callback_t  callback,
void *  cbParam 
)

After configuration, call GPT_MGR_Start to start the time channel.

Parameters
handleThe handle for the timer channel.
enableInterruptPass true to use interrupt mode, pass false to use polling mode.
requestTimeTimer period in microsecond.
callbackCallback function when timer hit, only used in interrupt mode.
cbParamParameter of the callback function.
Return values
kStatus_SuccessConfigured successfully.
kStatus_InvalidArgumentFailed because of invalid argument.
status_t GPT_MGR_Start ( gpt_handle_t handle)
Parameters
handleThe handle for the timer channel.
Return values
kStatus_SuccessConfigured successfully.
kStatus_InvalidArgumentFailed because of invalid argument.
status_t GPT_MGR_Stop ( gpt_handle_t handle)

If the channel works in interrupt mode, this function disables the channel interrupt too.

Parameters
handleThe handle for the timer channel.
Return values
kStatus_SuccessConfigured successfully.
kStatus_InvalidArgumentFailed because of invalid argument.
status_t GPT_MGR_Restart ( gpt_handle_t handle)
Parameters
handleThe handle for the timer channel.
Return values
kStatus_SuccessConfigured successfully.
kStatus_InvalidArgumentFailed because of invalid argument.
status_t GPT_MGR_Reset ( gpt_handle_t handle)
Parameters
handleThe handle for the timer channel.
Return values
kStatus_SuccessConfigured successfully.
kStatus_InvalidArgumentFailed because of invalid argument.
status_t GPT_MGR_Release ( gpt_handle_t handle)
Parameters
handleThe handle for the timer channel.
Return values
kStatus_SuccessConfigured successfully.
kStatus_InvalidArgumentFailed because of invalid argument.
status_t GPT_MGR_Poll ( gpt_handle_t handle)
Parameters
handleThe handle for the timer channel.
Return values
kStatus_SuccessTimer expired.
kStatus_BusyTimer is still running.
kStatus_InvalidArgumentFailed because of invalid argument.
bool GPT_MGR_IsFree ( gpt_handle_t handle)
Parameters
handleThe handle for the timer channel.
Returns
Return true if the channel is free, otherwise returns false.
status_t GPT_MGR_ChangeCounterResolution ( gpt_counter_resolution_t  resolution)
Parameters
resolutionThe new resolution to set.
Return values
kStatus_SuccessConfigured successfully.
kStatus_BusyCould not change the resolution because some channels are running.
kStatus_InvalidArgumentFailed because of invalid argument.
gpt_counter_resolution_t GPT_MGR_GetCounterResolution ( void  )
Returns
Current resolution.