MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Timer_Adapter

Overview

Data Structures

struct  hal_timer_config_t
 HAL timer configuration structure for HAL timer setting. More...
 

Macros

#define HAL_TIMER_HANDLE_SIZE   (20U)
 Definition of timer adapter handle size. More...
 
#define TIMER_HANDLE_DEFINE(name)   uint32_t name[((HAL_TIMER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
 Defines the timer handle. More...
 

Typedefs

typedef void(* hal_timer_callback_t )(void *param)
 The timer adapter component. More...
 
typedef void * hal_timer_handle_t
 HAL timer handle. More...
 

Enumerations

enum  hal_timer_status_t {
  kStatus_HAL_TimerSuccess = kStatus_Success,
  kStatus_HAL_TimerNotSupport = MAKE_STATUS(kStatusGroup_HAL_TIMER, 1),
  kStatus_HAL_TimerIsUsed = MAKE_STATUS(kStatusGroup_HAL_TIMER, 2),
  kStatus_HAL_TimerInvalid = MAKE_STATUS(kStatusGroup_HAL_TIMER, 3),
  kStatus_HAL_TimerOutOfRanger = MAKE_STATUS(kStatusGroup_HAL_TIMER, 4)
}
 HAL timer status. More...
 

Functions

hal_timer_status_t HAL_TimerInit (hal_timer_handle_t halTimerHandle, hal_timer_config_t *halTimerConfig)
 Initializes the timer adapter module for a timer basic operation. More...
 
void HAL_TimerDeinit (hal_timer_handle_t halTimerHandle)
 DeInitilizate the timer adapter module. More...
 
void HAL_TimerEnable (hal_timer_handle_t halTimerHandle)
 Enable the timer adapter module. More...
 
void HAL_TimerDisable (hal_timer_handle_t halTimerHandle)
 Disable the timer adapter module. More...
 
void HAL_TimerInstallCallback (hal_timer_handle_t halTimerHandle, hal_timer_callback_t callback, void *callbackParam)
 Install the timer adapter module callback function. More...
 
uint32_t HAL_TimerGetCurrentTimerCount (hal_timer_handle_t halTimerHandle)
 Get the timer count of the timer adapter. More...
 
hal_timer_status_t HAL_TimerUpdateTimeout (hal_timer_handle_t halTimerHandle, uint32_t timeout)
 Update the timeout of the timer adapter to generate timeout interrupt. More...
 
uint32_t HAL_TimerGetMaxTimeout (hal_timer_handle_t halTimerHandle)
 Get maximum Timer timeout. More...
 
void HAL_TimerExitLowpower (hal_timer_handle_t halTimerHandle)
 Timer adapter power up function. More...
 
void HAL_TimerEnterLowpower (hal_timer_handle_t halTimerHandle)
 Timer adapter power down function. More...
 

Data Structure Documentation

struct hal_timer_config_t

Data Fields

uint32_t timeout
 Timeout of the timer, should use microseconds, for example: if set timeout to 1000, mean 1000 microseconds interval would generate timer timeout interrupt.
 
uint32_t srcClock_Hz
 Source clock of the timer.
 
uint8_t instance
 Hardware timer module instance, for example: if you want use FTM0,then the instance is configured to 0, if you want use FTM2 hardware timer, then configure the instance to 2, detail information please refer to the SOC corresponding RM.Invalid instance value will cause initialization failure. More...
 

Field Documentation

uint8_t hal_timer_config_t::instance

Macro Definition Documentation

#define HAL_TIMER_HANDLE_SIZE   (20U)
#define TIMER_HANDLE_DEFINE (   name)    uint32_t name[((HAL_TIMER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]

This macro is used to define a 4 byte aligned timer handle. Then use "(hal_timer_handle_t)name" to get the timer handle.

The macro should be global and could be optional. You could also define timer handle by yourself.

This is an example,

* TIMER_HANDLE_DEFINE(timerHandle);
*
Parameters
nameThe name string of the timer handle.

Typedef Documentation

typedef void(* hal_timer_callback_t)(void *param)

The timer adapter is built based on the timer SDK driver provided by the NXP MCUXpresso SDK. The timer adapter could provide high accuracy timer for user. Since callback function would be handled in ISR, and timer clock use high accuracy clock, user can get accuracy millisecond timer.

The timer adapter would be used with different HW timer modules like FTM, PIT, LPTMR. But at the same time, only one HW timer module could be used. On different platforms, different HW timer module would be used. For the platforms which have multiple HW timer modules, one HW timer module would be selected as the default, but it is easy to change the default HW timer module to another. Just two steps to switch the HW timer module: 1.Remove the default HW timer module source file from the project 2.Add the expected HW timer module source file to the project. For example, in platform FRDM-K64F, there are two HW timer modules available, FTM and PIT. FTM is used as the default HW timer, so ftm_adapter.c and timer.h is included in the project by default. If PIT is expected to be used as the HW timer, ftm_adapter.c need to be removed from the project and pit_adapter.c should be included in the project

HAL timer callback function.

typedef void* hal_timer_handle_t

Enumeration Type Documentation

Enumerator
kStatus_HAL_TimerSuccess 

Success.

kStatus_HAL_TimerNotSupport 

Not Support.

kStatus_HAL_TimerIsUsed 

timer is used

kStatus_HAL_TimerInvalid 

timer is invalid

kStatus_HAL_TimerOutOfRanger 

timer is Out Of Ranger

Function Documentation

hal_timer_status_t HAL_TimerInit ( hal_timer_handle_t  halTimerHandle,
hal_timer_config_t halTimerConfig 
)
Note
This API should be called at the beginning of the application using the timer adapter. For Initializes timer adapter,
* TIMER_HANDLE_DEFINE(halTimerHandle);
* hal_timer_config_t halTimerConfig;
* halTimerConfig.timeout = 1000;
* halTimerConfig.srcClock_Hz = BOARD_GetTimeSrcClock();
* halTimerConfig.instance = 0;
* HAL_TimerInit((hal_timer_handle_t)halTimerHandle, &halTimerConfig);
*
Parameters
halTimerHandleHAL timer adapter handle, the handle buffer with size HAL_TIMER_HANDLE_SIZE should be allocated at upper level. The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. You can define the handle in the following two ways: TIMER_HANDLE_DEFINE(halTimerHandle); or uint32_t halTimerHandle[((HAL_TIMER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
halTimerConfigA pointer to the HAL timer configuration structure
Return values
kStatus_HAL_TimerSuccessThe timer adapter module initialization succeed.
kStatus_HAL_TimerOutOfRangerThe timer adapter instance out of ranger.
void HAL_TimerDeinit ( hal_timer_handle_t  halTimerHandle)
Note
This API should be called when not using the timer adapter anymore.
Parameters
halTimerHandleHAL timer adapter handle
void HAL_TimerEnable ( hal_timer_handle_t  halTimerHandle)
Note
This API should be called when enable the timer adapter.
Parameters
halTimerHandleHAL timer adapter handle
void HAL_TimerDisable ( hal_timer_handle_t  halTimerHandle)
Note
This API should be called when disable the timer adapter.
Parameters
halTimerHandleHAL timer adapter handle
void HAL_TimerInstallCallback ( hal_timer_handle_t  halTimerHandle,
hal_timer_callback_t  callback,
void *  callbackParam 
)
Note
This API should be called to when to install callback function for the timer.Since callback function would be handled in ISR, and timer clock use high accuracy clock, user can get accuracy millisecond timer.
Parameters
halTimerHandleHAL timer adapter handle
callbackThe installed callback function by upper layer
callbackParamThe callback function parameter
uint32_t HAL_TimerGetCurrentTimerCount ( hal_timer_handle_t  halTimerHandle)
Note
This API should be return the real-time timer counting value in a range from 0 to a timer period, and return microseconds.
Parameters
halTimerHandleHAL timer adapter handle
Return values
thereal-time timer counting value and return microseconds.
hal_timer_status_t HAL_TimerUpdateTimeout ( hal_timer_handle_t  halTimerHandle,
uint32_t  timeout 
)
Note
This API should be called when need set the timeout of the timer interrupt..
Parameters
halTimerHandleHAL timer adapter handle
TimeoutTimeout time, should be used microseconds.
Return values
kStatus_HAL_TimerSuccessThe timer adapter module update timeout succeed.
kStatus_HAL_TimerOutOfRangerThe timer adapter set the timeout out of ranger.
uint32_t HAL_TimerGetMaxTimeout ( hal_timer_handle_t  halTimerHandle)
Note
This API should to get maximum Timer timeout value to avoid overflow
Parameters
halTimerHandleHAL timer adapter handle
Return values
getthe real-time timer maximum timeout value and return microseconds.
void HAL_TimerExitLowpower ( hal_timer_handle_t  halTimerHandle)
Note
This API should be called by low power module when system exit from sleep mode.
Parameters
halTimerHandleHAL timer adapter handle
void HAL_TimerEnterLowpower ( hal_timer_handle_t  halTimerHandle)
Note
This API should be called by low power module before system enter into sleep mode.
Parameters
halTimerHandleHAL timer adapter handle