- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
extern "C" unsigned long millis();
Porting some code from Arduino environment to the Intel IDE (Eclipse) environment, I had need for the arduino mills() function (which is very useful).
The arduino version return ms from program start - my version returns ms from the first time it is called (so I tend to call it first this in main()
It may be useful for someone else so I post the header and the code below - Note: The code works - but I am sure it could have been written betterer!
Header;
Code.
#include <stdio.h> #include <sys/time.h> #include <time.h> #include <unistd.h> static struct timespec tstart={0,0}; static int start_retrieved=0; unsigned long millis() { unsigned long milliseconds; unsigned long n2; unsigned long n; struct timespec tend={0,0}; if (start_retrieved==0) { clock_gettime(CLOCK_MONOTONIC, &tstart); start_retrieved=1; } clock_gettime(CLOCK_MONOTONIC, &tend); n2=(((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) - ((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec)); n=((((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) - ((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec)) -n2)*1000; milliseconds=(n2 * 1000)+n; return(milliseconds); }
Stan
- Tags:
- Internet of Things
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Header code did not make it.
extern "C" unsigned long millis();
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page