Skip to content
Snippets Groups Projects
Commit 0f648924 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

posix: add missing delay_us and delay_ms functions

parent 959f015b
No related branches found
No related tags found
No related merge requests found
#include "arch.h" #include "arch.h"
#include <time.h>
#include <unistd.h> #include <unistd.h>
#if defined(WITH_LOOP) || defined(TIMER_S) #if defined(WITH_LOOP) || defined(TIMER_S)
...@@ -31,4 +32,20 @@ void Arch::idle(void) ...@@ -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; Arch arch;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment