| Kinetis SDK API Reference Manual 1.0.0-beta Freescale Semiconductor, Inc.

- Introduction
- Related Pages
- API Usage

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Functions
Microseconds Timer (MSTIMER)

The Kinetis SDK provides both HAL and Peripheral drivers for the Microseconds Timer (MSTIMER) block of Kinetis devices, which is based on the PIT driver. More...

## Functions
void | microseconds_init (void)
| Initialize timer facilities. More...
void | microseconds_shutdown (void)
| Shutdown the microsecond timer. More...
uint64_t | microseconds_get (void)
| Read back current absolute time in microseconds. More...
void | microseconds_delay (uint32_t us)
| Delay a specified time. More...

### Microseconds Driver

# Overview

Microseconds driver provides an easy way to delay specific time or to measure running time of one segment code. The timer will run endlessly before microseconds_shutdown being called. Since the timer is 64 bits, the counter will never reach to 0 in centuries.NOTE: using microseconds driver will change pit settings, so avoid using this if pit is used for other purpose.

# Initialization

To initialize the pit module, simply call microseconds_init(). This will chain pit timer 0 and timer 1 together as a 64 bit lifetime timer, and set period of both timer 0 and timer 1 to maximum value.

# Microseconds Delay

Simply call microseconds_delay with passing in the delay time in unit of microseconds. It performs as busy waiting and could be affected by interrupts.Example code to use microseconds delay:
// Initialize microseconds driver.
microseconds_init();
// Do something.
// Delay for 100 us
microseconds_delay(100);
// Do some other thing.

# Microseconds Get

Microseconds_get function can be used to measure running time of one segment of code. Call microseconds_get at the beginning of target code segment, call microseconds_get at the end of segment. The running time in microseconds unit could be get by subtracting end time from start time.Example code to use microseconds get:
// Get start time
startTime = microseconds_get();
// Code needed to measure.
// Get end time
endTime = microseconds_get();
// Calculate running time.
runningTime = startTime - endTime;

## Function Documentation

void microseconds_init | ( | void |  | ) |

This initializes pit to lifetime timer by chained channel 0 and channel 1 together, and set both channels to maximum counting period. This function should be called before using microseconds driver.

void microseconds_shutdown | ( | void |  | ) |

Disable PIT module and gate control.

uint64_t microseconds_get | ( | void |  | ) |

Returns
  absolute time in unit of microseconds from lifetime timer.

void microseconds_delay | ( | uint32_t | us | ) |

This function does not return until the specified number of microseconds has elapsed.

Parameters

  us | The requested length of time to delay in microseconds.