MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
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... | |
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... | |
uint32_t timer_config_t::srcClock_Hz |
The timer source clock.
uint8_t timer_config_t::instance |
Invalid instance value will cause initialization failure.
#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,
name | The name string of the timer manager handle. |
enum timer_status_t |
enum timer_mode_t |
timer_status_t TM_Init | ( | timer_config_t * | timerConfig | ) |
For Initializes timer manager,
timerConfig | Pointer to user-defined timer configuration structure. |
kStatus_TimerSuccess | Timer manager initialization succeed. |
kStatus_TimerError | An error occurred. |
timer_status_t TM_Open | ( | timer_handle_t | timerHandle | ) |
timerHandle | Pointer 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))]; |
kStatus_TimerSuccess | Timer open succeed. |
kStatus_TimerError | An error occurred. |
timer_status_t TM_Close | ( | timer_handle_t | timerHandle | ) |
timerHandle | the handle of the timer |
kStatus_TimerSuccess | Timer close succeed. |
kStatus_TimerError | An error occurred. |
timer_status_t TM_InstallCallback | ( | timer_handle_t | timerHandle, |
timer_callback_t | callback, | ||
void * | callbackParam | ||
) |
timerHandle | the handle of the timer |
callback | callback function |
callbackParam | parameter to callback function |
kStatus_TimerSuccess | Timer install callback succeed. |
timer_status_t TM_Start | ( | timer_handle_t | timerHandle, |
timer_mode_t | timerType, | ||
uint32_t | timerTimeout | ||
) |
timerHandle | the handle of the timer |
timeMode | the mode of the timer, for example: kTimerModeSingleShot for the timer will expire only once, kTimerModeIntervalTimer, the timer will restart each time it expires. |
timerTimeout | the timer timeout in milliseconds unit for kTimerModeSingleShot, kTimerModeIntervalTimer and kTimerModeLowPowerTimer,if kTimerModeSetMinuteTimer timeout for minutes unit, if kTimerModeSetSecondTimer the timeout for seconds unit. |
kStatus_TimerSuccess | Timer start succeed. |
kStatus_TimerError | An error occurred. |
timer_status_t TM_Stop | ( | timer_handle_t | timerHandle | ) |
timerHandle | the handle of the timer |
kStatus_TimerSuccess | Timer stop succeed. |
kStatus_TimerError | An error occurred. |
uint8_t TM_IsTimerActive | ( | timer_handle_t | timerHandle | ) |
timerHandle | the handle of the timer |
return | 1 if timer is active, return 0 if timer is not active. |
uint8_t TM_IsTimerReady | ( | timer_handle_t | timerHandle | ) |
timerHandle | the handle of the timer |
return | 1 if timer is ready, return 0 if timer is not ready. |
uint32_t TM_GetRemainingTime | ( | timer_handle_t | timerHandle | ) |
timerHandle | the handle of the timer |
remaining | time in microseconds until first timer timeouts. |
uint32_t TM_GetFirstExpireTime | ( | uint8_t | timerType | ) |
timerHandle | the handle of the timer |
return | the first expire time of all timer. |
timer_handle_t TM_GetFirstTimerWithParam | ( | void * | param | ) |
param | specified parameter of timer |
return | the handle of the timer if success. |
uint8_t TM_AreAllTimersOff | ( | void | ) |
return | 1 there are no active non-low power timers, 0 otherwise. |
uint32_t TM_NotCountedTimeBeforeSleep | ( | void | ) |
return | microseconds that wasn't counted before entering in sleep. |
void TM_SyncLpmTimers | ( | uint32_t | sleepDurationTmrUs | ) |
sleepDurationTmrUs | sleep duration in microseconds unit |
void TM_MakeTimerTaskReady | ( | void | ) |
uint64_t TM_GetTimestamp | ( | void | ) |