The MCUXpresso SDK provides a peripheral driver for the OSTIMER module of MCUXpresso SDK devices. OSTIMER driver is created to help user to operate the OSTIMER module. The OSTIMER timer can be used as a low power timer. The APIs can be used to enable the OSTIMER module, initialize it and set the match time, get the current timer count. And the raw value in OS timer register is gray-code type, so both decimal and gray-code format API were added for users. OSTIMER can be used as a wake up source from low power mode.
Function groups
The OSTIMER driver supports operating the module as a time counter.
Initialization and deinitialization
The OSTIMER_Init() function will initialize the OSTIMER and enable the clock for OSTIMER. The OSTIMER_Deinit() function will shut down the bus clock of OSTIMER.
OSTIMER status
The function OSTIMER_GetStatusFlags() will get the current status flag of OSTIMER. The function OSTIMER_ClearStatusFlag() will help clear the status flags.
OSTIMER set match value
For OSTIMER, allow users set the match in two ways, set match value with raw data(gray code) and st the match value with common data(decimal format). OSTIMER_SetMatchRawValue() is used with gray code and OSTIMER_SetMatchValue() is used together with decimal data.
OSTIMER get timer count
The OSTIMER driver allow users to get the timer count in two ways, getting the gray code value by using OSTIMER_GetCaptureRawValue() and getting the decimal data by using OSTIMER_GetCurrentTimerValue().
Typical use case
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/ostimer/
typedef void(* ostimer_callback_t)(void) |
Enumerator |
---|
kOSTIMER_MatchInterruptFlag |
Match interrupt flag bit, sets if the match value was reached.
|
void OSTIMER_Init |
( |
OSTIMER_Type * |
base | ) |
|
void OSTIMER_Deinit |
( |
OSTIMER_Type * |
base | ) |
|
This function shuts down OSTIMER bus clock
- Parameters
-
base | OSTIMER peripheral base address. |
static void OSTIMER_SoftwareReset |
( |
OSTIMER_Type * |
base | ) |
|
|
inlinestatic |
This function will use software to trigger an OSTIMER reset. Please note that, the OS timer reset bit was in PMC->OSTIMERr register.
- Parameters
-
base | OSTIMER peripheral base address. |
uint32_t OSTIMER_GetStatusFlags |
( |
OSTIMER_Type * |
base | ) |
|
This returns the status flag. Currently, only match interrupt flag can be got.
- Parameters
-
base | OSTIMER peripheral base address. |
- Returns
- status register value
void OSTIMER_ClearStatusFlags |
( |
OSTIMER_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
This clears intrrupt status flag. Currently, only match interrupt flag can be cleared.
- Parameters
-
base | OSTIMER peripheral base address. |
- Returns
- none
void OSTIMER_SetMatchRawValue |
( |
OSTIMER_Type * |
base, |
|
|
uint64_t |
count, |
|
|
ostimer_callback_t |
cb |
|
) |
| |
This function will set a match value for OSTIMER with an optional callback. And this callback will be called while the data in dedicated pair match register is equals to the value of central EVTIMER. Please note that, the data format is gray-code, if decimal data was desired, please using OSTIMER_SetMatchValue().
- Parameters
-
base | OSTIMER peripheral base address. |
count | OSTIMER timer match value.(Value is gray-code format) |
cb | OSTIMER callback (can be left as NULL if none, otherwise should be a void func(void)). |
- Returns
- none
This function will set a match value for OSTIMER with an optional callback. And this callback will be called while the data in dedicated pair match register is equals to the value of central OS TIMER.
- Parameters
-
base | OSTIMER peripheral base address. |
count | OSTIMER timer match value.(Value is decimal format, and this value will be translate to Gray code internally.) |
cb | OSTIMER callback (can be left as NULL if none, otherwise should be a void func(void)). |
- Returns
- none
static uint64_t OSTIMER_GetCurrentTimerRawValue |
( |
OSTIMER_Type * |
base | ) |
|
|
inlinestatic |
This function will get a gray code type timer count value from OS timer register. The raw value of timer count is gray code format.
- Parameters
-
base | OSTIMER peripheral base address. |
- Returns
- Raw value of OSTIMER, gray code format.
uint64_t OSTIMER_GetCurrentTimerValue |
( |
OSTIMER_Type * |
base | ) |
|
This function will get a decimal timer count value. The RAW value of timer count is gray code format, will be translated to decimal data internally.
- Parameters
-
base | OSTIMER peripheral base address. |
- Returns
- Value of OSTIMER which will be formated to decimal value.
static uint64_t OSTIMER_GetCaptureRawValue |
( |
OSTIMER_Type * |
base | ) |
|
|
inlinestatic |
This function will get a captured gray-code value from OSTIMER. The Raw value of timer capture is gray code format.
- Parameters
-
base | OSTIMER peripheral base address. |
- Returns
- Raw value of capture register, data format is gray code.
uint64_t OSTIMER_GetCaptureValue |
( |
OSTIMER_Type * |
base | ) |
|
This function will get a capture decimal-value from OSTIMER. The RAW value of timer capture is gray code format, will be translated to decimal data internally.
- Parameters
-
base | OSTIMER peripheral base address. |
- Returns
- Value of capture register, data format is decimal.
This function handles the interrupt and refers to the callback array in the driver to callback user (as per request in OSTIMER_SetMatchValue()). if no user callback is scheduled, the interrupt will simply be cleared.
- Parameters
-
base | OS timer peripheral base address. |
cb | callback scheduled for this instance of OS timer |
- Returns
- none