diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-01-31 10:56:12 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-01-31 10:56:12 +0100 |
commit | 0f648924fd832a26978c338af3eb4db6e5919665 (patch) | |
tree | d7cd558a216389e6d26a1b53b7de3f73808c4f04 /src/arch | |
parent | 959f015b3c0082574f874e02bb0ed5c18874fa48 (diff) |
posix: add missing delay_us and delay_ms functions
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/posix/arch.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/arch/posix/arch.cc b/src/arch/posix/arch.cc index 98a3a08..a2d78e9 100644 --- a/src/arch/posix/arch.cc +++ b/src/arch/posix/arch.cc @@ -1,4 +1,5 @@ #include "arch.h" +#include <time.h> #include <unistd.h> #if defined(WITH_LOOP) || defined(TIMER_S) @@ -31,4 +32,20 @@ void Arch::idle(void) { } +void Arch::delay_us(unsigned int const us) +{ + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = us * 1000; + nanosleep(&ts, NULL); +} + +void Arch::delay_ms(unsigned int const ms) +{ + struct timespec ts; + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000; + nanosleep(&ts, NULL); +} + Arch arch; |