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

Overview

Data Structures

struct  timer_config_t
 Timer config. More...
 

Macros

#define TM_COMMON_TASK_ENABLE   (1)
 The timer manager component. More...
 
#define TIMER_HANDLE_SIZE   (48U)
 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
}
 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.
 
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, timer_mode_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...
 

Field Documentation

uint32_t timer_config_t::srcClock_Hz

The timer source clock.

uint8_t timer_config_t::instance

Invalid instance value will cause initialization failure.

Macro Definition Documentation

#define TM_COMMON_TASK_ENABLE   (1)

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   (48U)
#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.

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.
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 
)
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,
timer_mode_t  timerType,
uint32_t  timerTimeout 
)
Parameters
timerHandlethe handle of the timer
timeModethe mode of the timer, for example: kTimerModeSingleShot for the timer will expire only once, kTimerModeIntervalTimer, the timer will restart each time it expires.
timerTimeoutthe timer timeout in milliseconds unit for kTimerModeSingleShot, kTimerModeIntervalTimer and kTimerModeLowPowerTimer,if kTimerModeSetMinuteTimer timeout for minutes unit, if kTimerModeSetSecondTimer the timeout for seconds unit.
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
timerHandlethe handle of the timer
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  )