Simple 64-bit timer for mbed. It is a drastically simplified version of Timer64 class by Tom Doyle. It is meant to be used in single-thread applications, where timer is used frequently, while standard 32-bit Timer is not enough.

Fork of Timer64 by Tom Doyle

Revision:
6:100cf27b43aa
Parent:
3:8396d3e6eb62
--- a/Timer64.h	Mon Mar 28 16:31:42 2016 +0000
+++ b/Timer64.h	Fri Apr 01 16:26:49 2016 +0000
@@ -1,3 +1,22 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2016 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Modified by Tom Doyle    <ThomasEDoyle@gmail.com>
+ *
+ */
+ 
 #ifndef __NEW_TIMER64__
 #define __NEW_TIMER64__
 
@@ -19,6 +38,57 @@
 #define TIMER64_MIN_ROLLOVER_CHECK_IN_MSECS         1000
 #define TIMER64_MAX_ROLLOVER_CHECK_IN_MSECS         65535
 
+/** 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 microsecnods (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:
+ *  
+ *  - start()
+ *  - stop()
+ *  - reset()
+ *  - read_us()
+ *  - read_ms()
+ *  - read()
+ *  - reset()
+ *  - isRunning()
+ *
+ *  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
+ *  @code
+ *  #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);
+ *      }
+ *  }
+ *  @endcode
+*/
+
 class Timer64
 {
 
@@ -28,7 +98,7 @@
 
     /** Initialize the timer - this must be called before the timer can be used
      */
-    int init(uint32_t rolloverCheckTimeInMsecc = TIMER64_15MINUTE_ROLLOVER_CHECK_IN_MSECS);
+    int init(uint32_t rolloverCheckTimeInMsecc = TIMER64_DEFAULT_ROLLOVER_CHECK_IN_MSECS);
 
     /** Release the timer
      */
@@ -59,6 +129,10 @@
     /** Get the time passed in seconds
      */
     int read(double* timeInSec = NULL);
+    
+    /** Check to see if timer is running
+     */
+    int isRunning(bool* running);
 
 private:
     bool _timerInitialized;