MCUXpresso SDK API Reference Manual  Rev 2.12.1
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Timer_Manager

Overview

Data Structures

struct  timer_config_t
 Timer config. More...
 

Macros

#define TM_COMMON_TASK_ENABLE   (0)
 The timer manager component. More...
 
#define TIMER_HANDLE_SIZE   (32U)
 Definition of timer manager handle size. More...
 
#define TIMER_MANAGER_HANDLE_DEFINE(name)   uint32_t name[(TIMER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
 Defines the timer manager handle. More...
 

Enumerations

enum  timer_status_t {
  kStatus_TimerSuccess = kStatus_Success,
  kStatus_TimerInvalidId = MAKE_STATUS(kStatusGroup_TIMERMANAGER, 1),
  kStatus_TimerNotSupport = MAKE_STATUS(kStatusGroup_TIMERMANAGER, 2),
  kStatus_TimerOutOfRange = MAKE_STATUS(kStatusGroup_TIMERMANAGER, 3),
  kStatus_TimerError = MAKE_STATUS(kStatusGroup_TIMERMANAGER, 4)
}
 Timer status. More...
 
enum  timer_mode_t {
  kTimerModeSingleShot = 0x01U,
  kTimerModeIntervalTimer = 0x02U,
  kTimerModeSetMinuteTimer = 0x04U,
  kTimerModeSetSecondTimer = 0x08U,
  kTimerModeLowPowerTimer = 0x10U,
  kTimerModeSetMicrosTimer = 0x20U
}
 Timer modes. More...
 

Functions

timer_status_t TM_Init (timer_config_t *timerConfig)
 Initializes timer manager module with the user configuration structure. More...
 
void TM_Deinit (void)
 Deinitialize timer manager module.
 
void TM_ExitLowpower (void)
 Power up timer manager module.
 
void TM_EnterLowpower (void)
 Power down timer manager module.
 
void TM_EnterTickless (timer_handle_t timerHandle, uint64_t timerTimeout)
 Programs a timer needed for RTOS tickless low power period. More...
 
void TM_ExitTickless (timer_handle_t timerHandle)
 Resyncs timer manager ressources after tickless low power period. More...
 
timer_status_t TM_Open (timer_handle_t timerHandle)
 Open a timer with user handle. More...
 
timer_status_t TM_Close (timer_handle_t timerHandle)
 Close a timer with user handle. More...
 
timer_status_t TM_InstallCallback (timer_handle_t timerHandle, timer_callback_t callback, void *callbackParam)
 Install a specified timer callback. More...
 
timer_status_t TM_Start (timer_handle_t timerHandle, uint8_t timerType, uint32_t timerTimeout)
 Start a specified timer. More...
 
timer_status_t TM_Stop (timer_handle_t timerHandle)
 Stop a specified timer. More...
 
uint8_t TM_IsTimerActive (timer_handle_t timerHandle)
 Check if a specified timer is active. More...
 
uint8_t TM_IsTimerReady (timer_handle_t timerHandle)
 Check if a specified timer is ready. More...
 
uint32_t TM_GetRemainingTime (timer_handle_t timerHandle)
 Returns the remaining time until timeout. More...
 
uint32_t TM_GetFirstExpireTime (uint8_t timerType)
 Get the first expire time of timer. More...
 
timer_handle_t TM_GetFirstTimerWithParam (void *param)
 Returns the handle of the timer of the first allocated timer that has the specified parameter. More...
 
uint8_t TM_AreAllTimersOff (void)
 Check if all timers except the LP timers are OFF. More...
 
uint32_t TM_NotCountedTimeBeforeSleep (void)
 Returns not counted time before system entering in sleep, This function is called by Low Power module. More...
 
void TM_SyncLpmTimers (uint32_t sleepDurationTmrUs)
 Sync low power timer in sleep mode, This function is called by Low Power module;. More...
 
void TM_MakeTimerTaskReady (void)
 Make timer task ready after wakeup from lowpower mode, This function is called by Low Power module;. More...
 
uint64_t TM_GetTimestamp (void)
 Get a time-stamp value. More...
 

Data Structure Documentation

struct timer_config_t

Data Fields

uint32_t srcClock_Hz
 
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. More...
 
uint8_t clockSrcSelect
 Select clock source. More...
 

Field Documentation

uint32_t timer_config_t::srcClock_Hz

The timer source clock frequency.

uint8_t timer_config_t::instance

Invalid instance value will cause initialization failure.

uint8_t timer_config_t::clockSrcSelect

It is timer clock select, if the lptmr does not to use the default clock source

Macro Definition Documentation

#define TM_COMMON_TASK_ENABLE   (0)

The timer manager is built based on the timer adapter component provided by the NXP MCUXpresso SDK. It could provide bellow features: shall support SingleShot,repeater,one minute timer,one second timer and low power mode shall support timer open ,close, start and stop operation, and support callback function install And provide 1ms accuracy timers

The timer manager 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

#define TIMER_HANDLE_SIZE   (32U)
#define TIMER_MANAGER_HANDLE_DEFINE (   name)    uint32_t name[(TIMER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]

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

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

This is an example,

* TIMER_MANAGER_HANDLE_DEFINE(timerManagerHandle);
*
Parameters
nameThe name string of the timer manager handle.

Enumeration Type Documentation

Enumerator
kStatus_TimerSuccess 

Success.

kStatus_TimerInvalidId 

Invalid Id.

kStatus_TimerNotSupport 

Not Support.

kStatus_TimerOutOfRange 

Out Of Range.

kStatus_TimerError 

Fail.

Enumerator
kTimerModeSingleShot 

The timer will expire only once.

kTimerModeIntervalTimer 

The timer will restart each time it expires.

kTimerModeSetMinuteTimer 

The timer will one minute timer.

kTimerModeSetSecondTimer 

The timer will one second timer.

kTimerModeLowPowerTimer 

The timer will low power mode timer.

kTimerModeSetMicrosTimer 

The timer will low power mode timer with microsecond unit.

Function Documentation

timer_status_t TM_Init ( timer_config_t timerConfig)

For Initializes timer manager,

* timer_config_t timerConfig;
* timerConfig.instance = 0;
* timerConfig.srcClock_Hz = BOARD_GetTimerSrcClock();
* TM_Init(&timerConfig);
*
Parameters
timerConfigPointer to user-defined timer configuration structure.
Return values
kStatus_TimerSuccessTimer manager initialization succeed.
kStatus_TimerErrorAn error occurred.
void TM_EnterTickless ( timer_handle_t  timerHandle,
uint64_t  timerTimeout 
)

Starts a timer and sync all timer manager ressources before programming HW timer module. Everything is done by bypassing the timer manager task as this function is usually called under masked interrupts (no context switch).

Parameters
timerHandlethe handle of the timer
timerTimeoutThe timer timeout in microseconds unit
void TM_ExitTickless ( timer_handle_t  timerHandle)

Makes sure to stop the tickless timer and resync all existing timers. Everything is done by bypassing the timer manager task as this function is usually called under masked interrupts (no context switch).

Parameters
timerHandlethe handle of the timer
timer_status_t TM_Open ( timer_handle_t  timerHandle)
Parameters
timerHandlePointer to a memory space of size TIMER_HANDLE_SIZE allocated by the caller. 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_MANAGER_HANDLE_DEFINE(timerHandle); or uint32_t timerHandle[((TIMER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
Return values
kStatus_TimerSuccessTimer open succeed.
kStatus_TimerErrorAn error occurred.
timer_status_t TM_Close ( timer_handle_t  timerHandle)
Parameters
timerHandlethe handle of the timer
Return values
kStatus_TimerSuccessTimer close succeed.
kStatus_TimerErrorAn error occurred.
timer_status_t TM_InstallCallback ( timer_handle_t  timerHandle,
timer_callback_t  callback,
void *  callbackParam 
)
Note
Application need call the function to install specified timer callback before start a timer .
Parameters
timerHandlethe handle of the timer
callbackcallback function
callbackParamparameter to callback function
Return values
kStatus_TimerSuccessTimer install callback succeed.
timer_status_t TM_Start ( timer_handle_t  timerHandle,
uint8_t  timerType,
uint32_t  timerTimeout 
)

TM_Start() starts a specified timer that was previously opened using the TM_Open() API function. The function is a non-blocking API, the funciton will return at once. And the callback function that was previously installed by using the TM_InstallCallback() API function will be called if timer is expired.

Parameters
timerHandlethe handle of the timer
timerTypeThe mode of the timer, for example: kTimerModeSingleShot for the timer will expire only once, kTimerModeIntervalTimer, the timer will restart each time it expires. If low power mode is used at the same time. It should be set like this: kTimerModeSingleShot | kTimerModeLowPowerTimer. kTimerModeSetMicosTimer is microsecond unit, and please note the timer Manager can't make sure the high resolution accuracy than 1ms with kTimerModeSetMicosTimer support, for example if timer manager use 32K OSC timer as clock source, actually the precision of timer is about 31us.
timerTimeoutThe timer timeout in milliseconds unit for kTimerModeSingleShot, kTimerModeIntervalTimer and kTimerModeLowPowerTimer,if kTimerModeSetMinuteTimer timeout for minutes unit, if kTimerModeSetSecondTimer the timeout for seconds unit. the timeout is in microseconds if kTimerModeSetMicrosTimer is used.
Return values
kStatus_TimerSuccessTimer start succeed.
kStatus_TimerErrorAn error occurred.
timer_status_t TM_Stop ( timer_handle_t  timerHandle)
Parameters
timerHandlethe handle of the timer
Return values
kStatus_TimerSuccessTimer stop succeed.
kStatus_TimerErrorAn error occurred.
uint8_t TM_IsTimerActive ( timer_handle_t  timerHandle)
Parameters
timerHandlethe handle of the timer
Return values
return1 if timer is active, return 0 if timer is not active.
uint8_t TM_IsTimerReady ( timer_handle_t  timerHandle)
Parameters
timerHandlethe handle of the timer
Return values
return1 if timer is ready, return 0 if timer is not ready.
uint32_t TM_GetRemainingTime ( timer_handle_t  timerHandle)
Parameters
timerHandlethe handle of the timer
Return values
remainingtime in microseconds until first timer timeouts.
uint32_t TM_GetFirstExpireTime ( uint8_t  timerType)
Parameters
timerTypeThe mode of the timer, for example: kTimerModeSingleShot for the timer will expire only once, kTimerModeIntervalTimer, the timer will restart each time it expires.
Return values
returnthe first expire time of all timer.
timer_handle_t TM_GetFirstTimerWithParam ( void *  param)
Parameters
paramspecified parameter of timer
Return values
returnthe handle of the timer if success.
uint8_t TM_AreAllTimersOff ( void  )
Return values
return1 there are no active non-low power timers, 0 otherwise.
uint32_t TM_NotCountedTimeBeforeSleep ( void  )
Return values
returnmicroseconds that wasn't counted before entering in sleep.
void TM_SyncLpmTimers ( uint32_t  sleepDurationTmrUs)
Parameters
sleepDurationTmrUssleep duration in microseconds unit
void TM_MakeTimerTaskReady ( void  )
uint64_t TM_GetTimestamp ( void  )