arduino PISystemTime::current

This commit is contained in:
Andrey
2022-01-21 17:09:21 +03:00
parent 8296e9a32b
commit 4921a3b0fd
2 changed files with 38 additions and 7 deletions

View File

@@ -19,7 +19,11 @@
#include "piincludes_p.h" #include "piincludes_p.h"
#include "pitime.h" #include "pitime.h"
#ifndef MICRO_PIP
# include "pisystemtests.h" # include "pisystemtests.h"
#elif defined(ARDUINO)
# include <Arduino.h>
#endif
#ifdef WINDOWS #ifdef WINDOWS
extern FILETIME __pi_ftjan1970; extern FILETIME __pi_ftjan1970;
long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;} long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;}
@@ -256,12 +260,19 @@ PISystemTime PISystemTime::current(bool precise_but_not_system) {
clock_get_time(__pi_mac_clock, &t_cur); clock_get_time(__pi_mac_clock, &t_cur);
#elif defined(MICRO_PIP) #elif defined(MICRO_PIP)
timespec t_cur; timespec t_cur;
# ifdef ARDUINO
static const uint32_t offSetSinceEpoch_s = 1581897605UL;
uint32_t mt = millis();
t_cur.tv_sec = offSetSinceEpoch_s + (mt / 1000);
t_cur.tv_nsec = (mt - (mt / 1000)) * 1000000UL;
# else
timeval tv; timeval tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
t_cur.tv_sec = tv.tv_sec; t_cur.tv_sec = tv.tv_sec;
t_cur.tv_nsec = tv.tv_usec * 1000; t_cur.tv_nsec = tv.tv_usec * 1000;
# endif
#else #else
timespec t_cur; timespec t_cur;
clock_gettime(precise_but_not_system ? CLOCK_MONOTONIC : 0, &t_cur); clock_gettime(precise_but_not_system ? CLOCK_MONOTONIC : 0, &t_cur);
@@ -404,22 +415,38 @@ PITimeMeasurer::PITimeMeasurer() {
double PITimeMeasurer::elapsed_n() const { double PITimeMeasurer::elapsed_n() const {
return (PISystemTime::current(true) - t_st).toNanoseconds() - PISystemTests::time_elapsed_ns; return (PISystemTime::current(true) - t_st).toNanoseconds()
#ifndef MICRO_PIP
- PISystemTests::time_elapsed_ns
#endif
;
} }
double PITimeMeasurer::elapsed_u() const { double PITimeMeasurer::elapsed_u() const {
return (PISystemTime::current(true) - t_st).toMicroseconds() - PISystemTests::time_elapsed_ns / 1.E+3; return (PISystemTime::current(true) - t_st).toMicroseconds()
#ifndef MICRO_PIP
- PISystemTests::time_elapsed_ns / 1.E+3
#endif
;
} }
double PITimeMeasurer::elapsed_m() const { double PITimeMeasurer::elapsed_m() const {
return (PISystemTime::current(true) - t_st).toMilliseconds() - PISystemTests::time_elapsed_ns / 1.E+6; return (PISystemTime::current(true) - t_st).toMilliseconds()
#ifndef MICRO_PIP
- PISystemTests::time_elapsed_ns / 1.E+6
#endif
;
} }
double PITimeMeasurer::elapsed_s() const { double PITimeMeasurer::elapsed_s() const {
return (PISystemTime::current(true) - t_st).toSeconds() - PISystemTests::time_elapsed_ns / 1.E+9; return (PISystemTime::current(true) - t_st).toSeconds()
#ifndef MICRO_PIP
- PISystemTests::time_elapsed_ns / 1.E+9
#endif
;
} }

View File

@@ -84,9 +84,12 @@ PIStringList PIVariantTypes::Enum::names() const {
#ifndef MICRO_PIP
PIVariantTypes::IODevice::IODevice() { PIVariantTypes::IODevice::IODevice() {
#ifndef MICRO_PIP
mode = PIIODevice::ReadWrite; mode = PIIODevice::ReadWrite;
#else
mode = 0; // TODO: PIIODevice for MICRO PIP
#endif // MICRO_PIP
options = 0; options = 0;
} }
@@ -113,12 +116,14 @@ PIString PIVariantTypes::IODevice::toPICout() const {
if (mode & 2) {s << "w"; ++rwc;} if (mode & 2) {s << "w"; ++rwc;}
if (rwc == 1) s << "o"; if (rwc == 1) s << "o";
s << ", flags="; s << ", flags=";
#ifndef MICRO_PIP // TODO: PIIODevice for MICRO PIP
if (options != 0) { if (options != 0) {
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead]) if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead])
s << " br"; s << " br";
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite]) if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite])
s << " bw"; s << " bw";
} }
#endif // MICRO_PIP
PIPropertyStorage ps = get(); PIPropertyStorage ps = get();
piForeachC (PIPropertyStorage::Property & p, ps) { piForeachC (PIPropertyStorage::Property & p, ps) {
s << ", " << p.name << "=\"" << p.value.toString() << "\""; s << ", " << p.name << "=\"" << p.value.toString() << "\"";
@@ -126,7 +131,6 @@ PIString PIVariantTypes::IODevice::toPICout() const {
s << ")"; s << ")";
return s; return s;
} }
#endif // MICRO_PIP