Arduino-like millis() function.

Dependents:   QSL_SimplePublish MAX30100_FirstTry MAX30100_FirstTry MAX30100_V04 ... more

Arduino-like millis() function.

Returns the number of milliseconds elapsed since the millisStart() function has been called.
It will roll over back to zero after roughly 49.7 days.
If you would like to create short term timers or to trigger short term events then consider to use Timer, Timeout, Ticker, wait or us_ticker_read. For more details have a look at the Handbook.
In case you are looking for scheduling of long term events then you could be interested also in the RTC library or the Clock library.

Example of use:

#include "mbed.h"
#include "millis.h"

Serial  pc(USBTX, USBRX);

int main() {
    millisStart();
    while(1) {
        pc.printf("millis = %d\r\n", millis());        
        wait(1.0);
    }
}


NOTE: Make sure you call millisStart() before using millis().

Warning

Works only on mbed boards equipped with SysTick!

Files at this revision

API Documentation at this revision

Comitter:
hudakz
Date:
Thu Jun 02 16:51:36 2016 +0000
Parent:
1:69c49c2be760
Commit message:
rev. 02

Changed in this revision

millis.cpp Show annotated file Show diff for this revision Revisions of this file
millis.h Show annotated file Show diff for this revision Revisions of this file
diff -r 69c49c2be760 -r ac7586424119 millis.cpp
--- a/millis.cpp	Thu Jun 02 16:37:40 2016 +0000
+++ b/millis.cpp	Thu Jun 02 16:51:36 2016 +0000
@@ -29,7 +29,8 @@
     _millis++;
 }
 
-extern "C" unsigned long millis(void) {
+unsigned long millis(void) {
     return _millis;
 }
 
+
diff -r 69c49c2be760 -r ac7586424119 millis.h
--- a/millis.h	Thu Jun 02 16:37:40 2016 +0000
+++ b/millis.h	Thu Jun 02 16:51:36 2016 +0000
@@ -19,7 +19,7 @@
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
 
-extern "C" void          millisStart(void);
-extern "C" unsigned long millis(void);
+void           millisStart(void);
+unsigned long  millis(void);
 
 #endif