Arduino functions millis, micros and eventually some more to come

Dependents:   DigitalCamera_OV5642_WIZwiki-W7500 BMC F746NG_TestAll Prelude_OV5642_dev

Arduino basic compatibility millis(), micros(), evtl. more to come.

micros() and millis() are uint32_t and have a correct overflow at 2^32-1. micros() has a granularity/resolution of 50. This can be changed by a define. 1 microsecond is not realistic because every count needs an irq. A resolution of 50 microseconds means 20KHz irq. That should not take away more than 1 percent overall processing time.

Committer:
eduardoG26
Date:
Mon Nov 24 17:02:21 2014 +0000
Revision:
0:571ea8a1bbae
Child:
1:d1b960698e70
First Revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eduardoG26 0:571ea8a1bbae 1 // millis as in Arduino...
eduardoG26 0:571ea8a1bbae 2
eduardoG26 0:571ea8a1bbae 3 #include "mbed.h"
eduardoG26 0:571ea8a1bbae 4 #include "millis.h"
eduardoG26 0:571ea8a1bbae 5
eduardoG26 0:571ea8a1bbae 6 static volatile uint32_t MilliSeconds_u32;
eduardoG26 0:571ea8a1bbae 7
eduardoG26 0:571ea8a1bbae 8 static Ticker MilliSecondsTicker;
eduardoG26 0:571ea8a1bbae 9
eduardoG26 0:571ea8a1bbae 10 static void MilliSecondsTickerIRQ()
eduardoG26 0:571ea8a1bbae 11 {
eduardoG26 0:571ea8a1bbae 12 MilliSeconds_u32 ++;
eduardoG26 0:571ea8a1bbae 13 }
eduardoG26 0:571ea8a1bbae 14
eduardoG26 0:571ea8a1bbae 15 uint32_t millis ()
eduardoG26 0:571ea8a1bbae 16 {
eduardoG26 0:571ea8a1bbae 17 return MilliSeconds_u32;
eduardoG26 0:571ea8a1bbae 18 }
eduardoG26 0:571ea8a1bbae 19
eduardoG26 0:571ea8a1bbae 20 void StartMillis ()
eduardoG26 0:571ea8a1bbae 21 {
eduardoG26 0:571ea8a1bbae 22 MilliSecondsTicker.attach_us (&MilliSecondsTickerIRQ, 1000);
eduardoG26 0:571ea8a1bbae 23 }
eduardoG26 0:571ea8a1bbae 24
eduardoG26 0:571ea8a1bbae 25 // End of file