USTIMER - Microsecond Timer#

Microsecond Delay Timer Driver.

Implements microsecond delays.

The delay is implemented using a hardware timer. USTIMER_Init() must be called prior to using the delay functions. USTIMER_Init() must also be called if HFCORECLK and/or HFPERCLK is changed.

The source files for the USTIMER driver library resides in the emdrv/ustimer folder, and are named ustimer.c and ustimer.h.


Introduction#

The USTIMER driver implements microsecond delay functions. The delay is timed using a hardware TIMER or WTIMER resource. Two delay functions are available, one which uses energy mode EM1 to preserve energy while waiting, and one which performs busy wait.

Note

  • Due to the overhead of setting up and serving TIMER/WTIMER interrupts, the USTIMER_Delay() function will be inaccurate for delays shorter than 200us. If higher accuracy is needed for short delays, consider using USTIMER_DelayIntSafe() or UDELAY_Delay().


Configuration Options#

By default the module use TIMER0. Timer resource selection is stored in a file named ustimer_config.h. A template for this file, containing default value, resides in the emdrv/config folder.

To configure USTIMER, provide your own configuration file. Here is a sample ustimer_config.h file:

#ifndef __SILICON_LABS_USTIMER_CONFIG_H__
#define __SILICON_LABS_USTIMER_CONFIG_H__

#define USTIMER_TIMER USTIMER_TIMER3

#endif


The API#

This section contain brief descriptions of the functions in the API. You will find detailed information on input and output parameters and return values by clicking on the hyperlinked function names. Most functions return an error code, ECODE_EMDRV_USTIMER_OK is returned on success, see ECODE - Error Codes for other error codes.

Your application code must include one header file: ustimer.h.

USTIMER_Init(), USTIMER_DeInit()
These functions initialize and deinitialize the USTIMER driver. Typically USTIMER_Init() is called once in your startup code.

USTIMER_Delay() Delay a given number of microseconds. The MCU enters EM1 during the delay.

USTIMER_DelayIntSafe() Delay a given number of microseconds. The MCU stays in EM0 during the delay. This function can be called in any context and is also thread safe.


Example#

#include "ustimer.h"

int main( void )
{
  // Initialization of USTIMER driver
  USTIMER_Init();

  // Wait for 250 microseconds
  USTIMER_Delay(250);
}

Functions#

Activate and initialize the hardware timer used to pace the 1 microsecond delay functions.

Deinitialize USTIMER driver.

USTIMER_Delay(uint32_t usec)

Delay a given number of microseconds.

USTIMER_DelayIntSafe(uint32_t usec)

Delay a given number of microseconds.

Macros#

#define

Success return value.

Function Documentation#

USTIMER_Init#

Ecode_t USTIMER_Init (void )

Activate and initialize the hardware timer used to pace the 1 microsecond delay functions.

Parameters
N/A

Note

  • Call this function whenever the HFPERCLK and/or HFCORECLK frequency is changed.

Returns


Definition at line 48 of file platform/emdrv/ustimer/inc/ustimer.h

USTIMER_DeInit#

Ecode_t USTIMER_DeInit (void )

Deinitialize USTIMER driver.

Parameters
N/A

Will disable interrupts and turn off the clock to the underlying hardware timer.

Returns


Definition at line 49 of file platform/emdrv/ustimer/inc/ustimer.h

USTIMER_Delay#

Ecode_t USTIMER_Delay (uint32_t usec)

Delay a given number of microseconds.

Parameters
[in]usec

Number of microseconds to delay.

The mcu is put in EM1 during the delay.

Note

  • This function assumes that the timer interrupt needed to wake the mcu up from EM1 is not blocked. This function is not thread safe. Due to the overhead of setting up and serving TIMER/WTIMER interrupts, timing will be inaccurate for delays shorter than 200us. If higher accuracy is needed for short delays, consider using USTIMER_DelayIntSafe() or UDELAY_Delay().

Returns


Definition at line 50 of file platform/emdrv/ustimer/inc/ustimer.h

USTIMER_DelayIntSafe#

Ecode_t USTIMER_DelayIntSafe (uint32_t usec)

Delay a given number of microseconds.

Parameters
[in]usec

Number of microseconds to delay.

This is a busy wait delay not using energy modes to conserve power.

Note

  • This function can be used in any context (interrupts can be disabled). This function is thread safe.

Returns


Definition at line 51 of file platform/emdrv/ustimer/inc/ustimer.h

Macro Definition Documentation#

ECODE_EMDRV_USTIMER_OK#

#define ECODE_EMDRV_USTIMER_OK
Value:
( ECODE_OK )

Success return value.


Definition at line 46 of file platform/emdrv/ustimer/inc/ustimer.h