Add millis()

This commit is contained in:
Joseph C. Lehner 2023-10-18 17:30:40 +02:00
parent 4a814f3f2a
commit b187e3ad66
2 changed files with 10 additions and 3 deletions

View file

@ -166,6 +166,7 @@ int ethsock_ip_add(struct ethsock *sock, uint32_t ipaddr, uint32_t ipmask, struc
int ethsock_ip_del(struct ethsock *sock, struct ethsock_ip_undo **undo); int ethsock_ip_del(struct ethsock *sock, struct ethsock_ip_undo **undo);
time_t time_monotonic(); time_t time_monotonic();
long long millis();
char *lltostr(long long ll, int base); char *lltostr(long long ll, int base);
uint32_t bitcount(uint32_t n); uint32_t bitcount(uint32_t n);
uint32_t netmask(uint32_t count); uint32_t netmask(uint32_t count);

12
util.c
View file

@ -30,15 +30,21 @@
volatile sig_atomic_t g_interrupted = 0; volatile sig_atomic_t g_interrupted = 0;
int verbosity = 0; int verbosity = 0;
time_t time_monotonic() long long millis()
{ {
#ifndef NMRPFLASH_WINDOWS #ifndef NMRPFLASH_WINDOWS
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec; return ts.tv_sec * 1000 + ((ts.tv_nsec + 500000) / 1000000);
#else #else
return round(GetTickCount() / 1000.0); return GetTickCount();
#endif #endif
}
time_t time_monotonic()
{
return millis() / 1000;
} }
char *lltostr(long long ll, int base) char *lltostr(long long ll, int base)