| 1 | #include <time.h> |
| 2 | #include <chrono> |
| 3 | #include "compatibility.h" |
| 4 | |
| 5 | long long mtime, seconds, useconds; |
| 6 | //static struct timeval start, end; |
| 7 | //struct timespec start, end; |
| 8 | |
| 9 | void __msleep(int millisec) |
| 10 | { |
| 11 | struct timespec req; // = {0}; |
| 12 | req.tv_sec = (time_t)millisec / 1000; |
| 13 | req.tv_nsec = (millisec % 1000) * 1000000L; |
| 14 | //nanosleep(&req, (struct timespec *)NULL); |
| 15 | clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL); |
| 16 | } |
| 17 | |
| 18 | void __usleep(int microsec) |
| 19 | { |
| 20 | struct timespec req; // = {0}; |
| 21 | req.tv_sec = (time_t)microsec / 1000000; |
| 22 | req.tv_nsec = (microsec % 1000000) * 1000; |
| 23 | //nanosleep(&req, (struct timespec *)NULL); |
| 24 | clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * This function is added in order to simulate arduino millis() function |
| 29 | */ |
| 30 | |
| 31 | bool timerStarted = false; |
| 32 | |
| 33 | void __start_timer() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | auto start = std::chrono::steady_clock::now(); |
| 38 | |
| 39 | uint32_t __millis() |
| 40 | { |
| 41 | |
| 42 | auto end = std::chrono::steady_clock::now(); |
| 43 | |
| 44 | return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); |
| 45 | } |