USTIMEREMDRV

Detailed Description

USTIMER 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.


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__

/// USTIMER configuration option. Use this define to select a TIMER resource.
#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.h and ustimer.h 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);
}

Macros

#define ECODE_EMDRV_USTIMER_OK ( ECODE_OK )
Success return value.

Functions

Ecode_t USTIMER_DeInit (void)
Deinitialize USTIMER driver.
Ecode_t USTIMER_Delay (uint32_t usec)
Delay a given number of microseconds.
Ecode_t USTIMER_DelayIntSafe (uint32_t usec)
Delay a given number of microseconds.
Ecode_t USTIMER_Init (void)
Activate and initialize the hardware timer used to pace the 1 microsecond delay functions.

Function Documentation

Ecode_t USTIMER_DeInit ( void )

Deinitialize USTIMER driver.

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

Returns
ECODE_EMDRV_USTIMER_OK .

Definition at line 188 of file ustimer.c .

References CMU_ClockEnable() , ECODE_EMDRV_USTIMER_OK , TIMER_Enable() , TIMER_IEN_CC0 , TIMER_IFC_CC0 , TIMER_IntClear() , and TIMER_IntDisable() .

Referenced by ezradio_comm_PollCTS() , ezradio_reset() , and ezradioInit() .

Ecode_t USTIMER_Delay ( uint32_t usec )

Delay a given number of microseconds.

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.
Parameters
[in] usec Number of microseconds to delay.
Returns
ECODE_EMDRV_USTIMER_OK .

Definition at line 219 of file ustimer.c .

References ECODE_EMDRV_USTIMER_OK .

Referenced by ezradio_comm_PollCTS() , ezradio_reset() , and ezradioInit() .

Ecode_t USTIMER_DelayIntSafe ( uint32_t usec )

Delay a given number of microseconds.

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.
Parameters
[in] usec Number of microseconds to delay.
Returns
ECODE_EMDRV_USTIMER_OK .

Definition at line 253 of file ustimer.c .

References ECODE_EMDRV_USTIMER_OK .

Ecode_t USTIMER_Init ( void )