MCUXpresso SDK API Reference Manual
Rev 2.12.1
NXP Semiconductors
|
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... | |
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... | |
uint8_t | clockSrcSelect |
Select clock source. More... | |
uint8_t hal_timer_config_t::instance |
uint8_t hal_timer_config_t::clockSrcSelect |
It is for timer clock select, if the lptmr does not want to use the default clock source
#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,
name | The name string of the timer handle. |
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 |
enum hal_timer_status_t |
hal_timer_status_t HAL_TimerInit | ( | hal_timer_handle_t | halTimerHandle, |
hal_timer_config_t * | halTimerConfig | ||
) |
halTimerHandle | HAL 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))]; |
halTimerConfig | A pointer to the HAL timer configuration structure |
kStatus_HAL_TimerSuccess | The timer adapter module initialization succeed. |
kStatus_HAL_TimerOutOfRanger | The timer adapter instance out of ranger. |
void HAL_TimerDeinit | ( | hal_timer_handle_t | halTimerHandle | ) |
halTimerHandle | HAL timer adapter handle |
void HAL_TimerEnable | ( | hal_timer_handle_t | halTimerHandle | ) |
halTimerHandle | HAL timer adapter handle |
void HAL_TimerDisable | ( | hal_timer_handle_t | halTimerHandle | ) |
halTimerHandle | HAL timer adapter handle |
void HAL_TimerInstallCallback | ( | hal_timer_handle_t | halTimerHandle, |
hal_timer_callback_t | callback, | ||
void * | callbackParam | ||
) |
halTimerHandle | HAL timer adapter handle |
callback | The installed callback function by upper layer |
callbackParam | The callback function parameter |
uint32_t HAL_TimerGetCurrentTimerCount | ( | hal_timer_handle_t | halTimerHandle | ) |
halTimerHandle | HAL timer adapter handle |
the | real-time timer counting value and return microseconds. |
hal_timer_status_t HAL_TimerUpdateTimeout | ( | hal_timer_handle_t | halTimerHandle, |
uint32_t | timeout | ||
) |
halTimerHandle | HAL timer adapter handle |
timeout | Timeout time, should be used microseconds. |
kStatus_HAL_TimerSuccess | The timer adapter module update timeout succeed. |
kStatus_HAL_TimerOutOfRanger | The timer adapter set the timeout out of ranger. |
uint32_t HAL_TimerGetMaxTimeout | ( | hal_timer_handle_t | halTimerHandle | ) |
halTimerHandle | HAL timer adapter handle |
get | the real-time timer maximum timeout value and return microseconds. |
void HAL_TimerExitLowpower | ( | hal_timer_handle_t | halTimerHandle | ) |
halTimerHandle | HAL timer adapter handle |
void HAL_TimerEnterLowpower | ( | hal_timer_handle_t | halTimerHandle | ) |
halTimerHandle | HAL timer adapter handle |