mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Embed: (wiki syntax)

« Back to documentation index

Timer Class Reference

A general purpose timer. More...

#include <Timer.h>

Inherits NonCopyable< Timer >, and NonCopyable< Timer >.

Inherited by LowPowerTimer, and LowPowerTimer.

Public Member Functions

void start ()
 Start the timer.
void stop ()
 Stop the timer.
void reset ()
 Reset the timer to 0.
float read ()
 Get the time passed in seconds.
int read_ms ()
 Get the time passed in milliseconds.
int read_us ()
 Get the time passed in microseconds.
 operator float ()
 An operator shorthand for read()
us_timestamp_t read_high_resolution_us ()
 Get in a high resolution type the time passed in microseconds.
void start ()
 Start the timer.
void stop ()
 Stop the timer.
void reset ()
 Reset the timer to 0.
float read ()
 Get the time passed in seconds.
int read_ms ()
 Get the time passed in milliseconds.
int read_us ()
 Get the time passed in microseconds.
 operator float ()
 An operator shorthand for read()
us_timestamp_t read_high_resolution_us ()
 Get in a high resolution type the time passed in microseconds.

Private Member Functions

 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.
 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.

Detailed Description

A general purpose timer.

Note:
Synchronization level: Interrupt safe

Example:

 // Count the time to toggle an LED

 #include "mbed.h"

 Timer timer;
 DigitalOut led(LED1);
 int begin, end;

 int main() {
     timer.start();
     begin = timer.read_us();
     led = !led;
     end = timer.read_us();
     printf("Toggle the led takes %d us", end - begin);
 }

Definition at line 52 of file cmsis/BUILD/mbed/drivers/Timer.h.


Member Function Documentation

operator float (  )

An operator shorthand for read()

Definition at line 118 of file Timer.cpp.

operator float (  )

An operator shorthand for read()

float read ( void   )

Get the time passed in seconds.

Returns:
Time passed in seconds

Definition at line 81 of file Timer.cpp.

float read (  )

Get the time passed in seconds.

Returns:
Time passed in seconds
us_timestamp_t read_high_resolution_us (  )

Get in a high resolution type the time passed in microseconds.

Returns a 64 bit integer.

Definition at line 91 of file Timer.cpp.

us_timestamp_t read_high_resolution_us (  )

Get in a high resolution type the time passed in microseconds.

Returns a 64 bit integer.

int read_ms (  )

Get the time passed in milliseconds.

Returns:
Time passed in milliseconds

Definition at line 86 of file Timer.cpp.

int read_ms (  )

Get the time passed in milliseconds.

Returns:
Time passed in milliseconds
int read_us (  )

Get the time passed in microseconds.

Returns:
Time passed in microseconds
int read_us (  )

Get the time passed in microseconds.

Returns:
Time passed in microseconds

Definition at line 76 of file Timer.cpp.

void reset (  )

Reset the timer to 0.

If it was already running, it will continue

Definition at line 110 of file Timer.cpp.

void reset (  )

Reset the timer to 0.

If it was already running, it will continue

void start (  )

Start the timer.

void start ( void   )

Start the timer.

Definition at line 50 of file Timer.cpp.

void stop ( void   )

Stop the timer.

Definition at line 63 of file Timer.cpp.

void stop (  )

Stop the timer.