diff --git a/openrtx/include/interfaces/delays.h b/openrtx/include/interfaces/delays.h index 680c7e3c..c3628d2f 100644 --- a/openrtx/include/interfaces/delays.h +++ b/openrtx/include/interfaces/delays.h @@ -48,6 +48,13 @@ void delayMs(unsigned int mseconds); */ void sleepFor(unsigned int seconds, unsigned int mseconds); +/** + * Puts the calling thread in a sleeping state until the system time reaches + * the target value passed as parameter. + * @param timestamp: traget timestamp for the wakeup. + */ +void sleepUntil(long long timestamp); + /** * Get the current value of the system tick. * @return current system tick value. diff --git a/platform/mcu/MK22FN512xxx12/drivers/delays.cpp b/platform/mcu/MK22FN512xxx12/drivers/delays.cpp index 2d8eb3a0..678c837c 100644 --- a/platform/mcu/MK22FN512xxx12/drivers/delays.cpp +++ b/platform/mcu/MK22FN512xxx12/drivers/delays.cpp @@ -58,6 +58,11 @@ void sleepFor(unsigned int seconds, unsigned int mseconds) miosix::Thread::sleep(time); } +void sleepUntil(long long timestamp) +{ + miosix::Thread::sleepUntil(timestamp); +} + long long getTick() { return miosix::getTick(); diff --git a/platform/mcu/STM32F4xx/drivers/delays.cpp b/platform/mcu/STM32F4xx/drivers/delays.cpp index 54d86054..b1311d51 100644 --- a/platform/mcu/STM32F4xx/drivers/delays.cpp +++ b/platform/mcu/STM32F4xx/drivers/delays.cpp @@ -58,6 +58,11 @@ void sleepFor(unsigned int seconds, unsigned int mseconds) miosix::Thread::sleep(time); } +void sleepUntil(long long timestamp) +{ + miosix::Thread::sleepUntil(timestamp); +} + long long getTick() { return miosix::getTick(); diff --git a/platform/mcu/x86_64/drivers/delays.c b/platform/mcu/x86_64/drivers/delays.c index 62c3c820..9d2efa36 100644 --- a/platform/mcu/x86_64/drivers/delays.c +++ b/platform/mcu/x86_64/drivers/delays.c @@ -40,6 +40,13 @@ void sleepFor(unsigned int seconds, unsigned int mseconds) delayMs(time); } +void sleepUntil(long long timestamp) +{ + long long delta = timestamp - getTick(); + if(delta <= 0) return; + delayMs(delta); +} + long long getTick() { /*