64 bit Timer Class.

Embed: (wiki syntax)

« Back to documentation index

Timer64 Class Reference

Timer64 Class Reference

Timer64 class Used to define a 64 bit timer64 that is thread safe. More...

#include <Timer64.h>

Public Member Functions

int init (uint32_t rolloverCheckTimeInMsecc=TIMER64_DEFAULT_ROLLOVER_CHECK_IN_MSECS)
 Initialize the timer - this must be called before the timer can be used.
int release (void)
 Release the timer - must be called from the same thread calling init()
int start (void)
 Start the timer - this method is thread safe.
int stop (void)
 Stop the timer - this method is thread safe.
int reset (void)
 Reset the timer - this method is thread safe.
int read_us (uint64_t *timeInUsec=NULL)
 Read the timer value in microseconds - this method is thread safe.
int read_ms (uint64_t *timeInMsec=NULL)
 Read the timer value in milliseconds - this method is thread safe.
int read (double *timeInSec=NULL)
 Read the timer value in seconds - this method is thread safe.
int isRunning (bool *running)
 Check to see if timer is running - this method is thread safe.

Detailed Description

Timer64 class Used to define a 64 bit timer64 that is thread safe.

The Timer64 behaves in a similiar fashion to the mbed Timer class with the most notable exception that the Timer64 will not rollover after 2^31 microseconds (approximately 35.8 minutes). The Timer64 extends the rollover time to 2^64 microseconds (approximately 585,000 years!)

The Timer64 class is also designed to be thread safe. The following functions can be called from any thread after the class is instaniated and initialized:

It is to be noted that the init() and release() methods need to be called from the same thread.

Give the Timer64 library a try and let me know if it works for you. Will gladly take suggestions on how to make it better.

Simple Example

  #include "mbed.h"
  #include "rtos.h"
  #include "Timer64.h"

 Timer64 timer64;

   int main()
   {
      uint64_t timeInUsec;
      timer64.init();
      timer64.start();
      Thread::wait(100);
      timer64.stop();
      timer64.read_us(&timeInUsec);
      printf("Test - Elapsed time = %llu usec\n\n", timeInUsec);
      timer64.reset();
      timer64.release();
       
      while (1)
      {
          Thread::wait(1000);
      }
  }

Definition at line 93 of file Timer64.h.


Member Function Documentation

int init ( uint32_t  rolloverCheckTimeInMsecc = TIMER64_DEFAULT_ROLLOVER_CHECK_IN_MSECS )

Initialize the timer - this must be called before the timer can be used.

Parameters:
rolloverCheckTimeInMseccspecifies how ofter a rollover check is performed. This parameter is bounded by TIMER64_MIN_ROLLOVER_CHECK_IN_MSECS and TIMER64_MIN_ROLLOVER_CHECK_IN_MSECS with a default value of TIMER64_MIN_ROLLOVER_CHECK_IN_MSECS
Returns:
TIMER64_OK, TIMER64_WARNING_ALREADY_INITIALIZED

Definition at line 37 of file Timer64.cpp.

int isRunning ( bool *  running )

Check to see if timer is running - this method is thread safe.

Parameters:
runningspecifies a pointer to a bool where to save the running status
Returns:
TIMER64_OK, TIMER64_ERROR_NOT_INITIALIZED, TIMER64_ERROR_NULL_POINTER

Definition at line 259 of file Timer64.cpp.

int read ( double *  timeInSec = NULL )

Read the timer value in seconds - this method is thread safe.

Parameters:
timeInMsecspecifies a pointer to a double where to save the current time in seconds
Returns:
TIMER64_OK, TIMER64_ERROR_NOT_INITIALIZED, TIMER64_ERROR_NULL_POINTER,

Definition at line 228 of file Timer64.cpp.

int read_ms ( uint64_t *  timeInMsec = NULL )

Read the timer value in milliseconds - this method is thread safe.

Parameters:
timeInMsecspecifies a pointer to a uint64_t where to save the current time in milliseconds
Returns:
TIMER64_OK, TIMER64_ERROR_NOT_INITIALIZED, TIMER64_ERROR_NULL_POINTER

Definition at line 197 of file Timer64.cpp.

int read_us ( uint64_t *  timeInUsec = NULL )

Read the timer value in microseconds - this method is thread safe.

Parameters:
timeInUsecspecifies a pointer to a uint64_t where to save the current time in microseconds
Returns:
TIMER64_OK, TIMER64_ERROR_NOT_INITIALIZED, TIMER64_ERROR_NULL_POINTER

Definition at line 166 of file Timer64.cpp.

int release ( void   )

Release the timer - must be called from the same thread calling init()

Returns:
TIMER64_OK, TIMER64_WARNING_ALREADY_RELEASED

Definition at line 64 of file Timer64.cpp.

int reset ( void   )

Reset the timer - this method is thread safe.

Returns:
TIMER64_OK, TIMER64_ERROR_NOT_INITIALIZED

Definition at line 140 of file Timer64.cpp.

int start ( void   )

Start the timer - this method is thread safe.

Returns:
TIMER64_OK, TIMER64_ERROR_NOT_INITIALIZED, TIMER64_WARNING_ALREADY_RUNNING

Definition at line 88 of file Timer64.cpp.

int stop ( void   )

Stop the timer - this method is thread safe.

Returns:
TIMER64_OK, TIMER64_ERROR_NOT_INITIALIZED, TIMER64_WARNING_ALREADY_STOPPED

Definition at line 114 of file Timer64.cpp.