MCUXpresso SDK API Reference Manual  Rev 2.15.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
OSTIMER: OS Event Timer Driver

Overview

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/

Files

file  fsl_ostimer.h
 

Typedefs

typedef void(* ostimer_callback_t )(void)
 ostimer callback function. More...
 

Enumerations

enum  _ostimer_flags { kOSTIMER_MatchInterruptFlag = (OSTIMER_OSEVENT_CTRL_OSTIMER_INTRFLAG_MASK) }
 OSTIMER status flags. More...
 

Driver version

#define FSL_OSTIMER_DRIVER_VERSION   (MAKE_VERSION(2, 2, 1))
 OSTIMER driver version. More...
 

Initialization and deinitialization

void OSTIMER_Init (OSTIMER_Type *base)
 Initializes an OSTIMER by turning its bus clock on. More...
 
void OSTIMER_Deinit (OSTIMER_Type *base)
 Deinitializes a OSTIMER instance. More...
 
uint64_t OSTIMER_GrayToDecimal (uint64_t gray)
 Translate the value from gray-code to decimal. More...
 
static uint64_t OSTIMER_DecimalToGray (uint64_t dec)
 Translate the value from decimal to gray-code. More...
 
uint32_t OSTIMER_GetStatusFlags (OSTIMER_Type *base)
 Get OSTIMER status Flags. More...
 
void OSTIMER_ClearStatusFlags (OSTIMER_Type *base, uint32_t mask)
 Clear Status Interrupt Flags. More...
 
status_t OSTIMER_SetMatchRawValue (OSTIMER_Type *base, uint64_t count, ostimer_callback_t cb)
 Set the match raw value for OSTIMER. More...
 
status_t OSTIMER_SetMatchValue (OSTIMER_Type *base, uint64_t count, ostimer_callback_t cb)
 Set the match value for OSTIMER. More...
 
static void OSTIMER_SetMatchRegister (OSTIMER_Type *base, uint64_t value)
 Set value to OSTIMER MATCH register directly. More...
 
static void OSTIMER_EnableMatchInterrupt (OSTIMER_Type *base)
 Enable the OSTIMER counter match interrupt. More...
 
static void OSTIMER_DisableMatchInterrupt (OSTIMER_Type *base)
 Disable the OSTIMER counter match interrupt. More...
 
static uint64_t OSTIMER_GetCurrentTimerRawValue (OSTIMER_Type *base)
 Get current timer raw count value from OSTIMER. More...
 
uint64_t OSTIMER_GetCurrentTimerValue (OSTIMER_Type *base)
 Get current timer count value from OSTIMER. More...
 
static uint64_t OSTIMER_GetCaptureRawValue (OSTIMER_Type *base)
 Get the capture value from OSTIMER. More...
 
uint64_t OSTIMER_GetCaptureValue (OSTIMER_Type *base)
 Get the capture value from OSTIMER. More...
 
void OSTIMER_HandleIRQ (OSTIMER_Type *base, ostimer_callback_t cb)
 OS timer interrupt Service Handler. More...
 

Macro Definition Documentation

#define FSL_OSTIMER_DRIVER_VERSION   (MAKE_VERSION(2, 2, 1))

Typedef Documentation

typedef void(* ostimer_callback_t)(void)

Enumeration Type Documentation

Enumerator
kOSTIMER_MatchInterruptFlag 

Match interrupt flag bit, sets if the match value was reached.

Function Documentation

void OSTIMER_Init ( OSTIMER_Type *  base)
void OSTIMER_Deinit ( OSTIMER_Type *  base)

This function shuts down OSTIMER bus clock

Parameters
baseOSTIMER peripheral base address.
uint64_t OSTIMER_GrayToDecimal ( uint64_t  gray)
Parameters
grayThe gray value input.
Returns
The decimal value.
static uint64_t OSTIMER_DecimalToGray ( uint64_t  dec)
inlinestatic
Parameters
decThe decimal value.
Returns
The gray code of the input value.
uint32_t OSTIMER_GetStatusFlags ( OSTIMER_Type *  base)

This returns the status flag. Currently, only match interrupt flag can be got.

Parameters
baseOSTIMER 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
baseOSTIMER peripheral base address.
maskClear bit mask.
Returns
none
status_t 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
baseOSTIMER peripheral base address.
countOSTIMER timer match value.(Value is gray-code format)
cbOSTIMER callback (can be left as NULL if none, otherwise should be a void func(void)).
Return values
kStatus_Success- Set match raw value and enable interrupt Successfully.
kStatus_Fail- Set match raw value fail.
status_t OSTIMER_SetMatchValue ( 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 OS TIMER.

Parameters
baseOSTIMER peripheral base address.
countOSTIMER timer match value.(Value is decimal format, and this value will be translate to Gray code internally.)
cbOSTIMER callback (can be left as NULL if none, otherwise should be a void func(void)).
Return values
kStatus_Success- Set match value and enable interrupt Successfully.
kStatus_Fail- Set match value fail.
static void OSTIMER_SetMatchRegister ( OSTIMER_Type *  base,
uint64_t  value 
)
inlinestatic

This function writes the input value to OSTIMER MATCH register directly, it does not touch any other registers. Note that, the data format is gray-code. The function OSTIMER_DecimalToGray could convert decimal value to gray code.

Parameters
baseOSTIMER peripheral base address.
valueOSTIMER timer match value (Value is gray-code format).
static void OSTIMER_EnableMatchInterrupt ( OSTIMER_Type *  base)
inlinestatic

Enable the timer counter match interrupt. The interrupt happens when OSTIMER counter matches the value in MATCH registers.

Parameters
baseOSTIMER peripheral base address.
static void OSTIMER_DisableMatchInterrupt ( OSTIMER_Type *  base)
inlinestatic

Disable the timer counter match interrupt. The interrupt happens when OSTIMER counter matches the value in MATCH registers.

Parameters
baseOSTIMER peripheral base address.
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
baseOSTIMER 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
baseOSTIMER 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
baseOSTIMER 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
baseOSTIMER peripheral base address.
Returns
Value of capture register, data format is decimal.
void OSTIMER_HandleIRQ ( OSTIMER_Type *  base,
ostimer_callback_t  cb 
)

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
baseOS timer peripheral base address.
cbcallback scheduled for this instance of OS timer
Returns
none