From 59f88aad5f70e1c7274a4dcae0107bbd6efe3cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20Sowa?= Date: Mon, 16 Dec 2024 00:06:36 +0100 Subject: [PATCH] Add opencv and flipper clock advance implementations --- src/system/arduino/opencr/system.c | 25 +++++++++++++++++++++++++ src/system/flipper/system.c | 26 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/system/arduino/opencr/system.c b/src/system/arduino/opencr/system.c index e6ea10fce..759a9e7ae 100644 --- a/src/system/arduino/opencr/system.c +++ b/src/system/arduino/opencr/system.c @@ -97,6 +97,9 @@ z_result_t _z_condvar_signal(_z_condvar_t *cv) { return -1; } z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { return -1; } z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return -1; } +z_result_t _z_condvar_wait_until(_z_condvar_t *cv, _z_mutex_t *m, const z_clock_t *abstime, bool *timeout) { + return -1; +} #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ @@ -160,6 +163,28 @@ unsigned long z_clock_elapsed_s(z_clock_t *instant) { return elapsed; } +void z_clock_advance_us(z_clock_t *clock, unsigned long duration) { + clock->tv_sec += duration / 1000000; + clock->tv_nsec += (duration % 1000000) * 1000; + + if (clock->tv_nsec >= 1000000000) { + clock->tv_sec += 1; + clock->tv_nsec -= 1000000000; + } +} + +void z_clock_advance_ms(z_clock_t *clock, unsigned long duration) { + clock->tv_sec += duration / 1000; + clock->tv_nsec += (duration % 1000) * 1000000; + + if (clock->tv_nsec >= 1000000000) { + clock->tv_sec += 1; + clock->tv_nsec -= 1000000000; + } +} + +void z_clock_advance_s(z_clock_t *clock, unsigned long duration) { clock->tv_sec += duration; } + /*------------------ Time ------------------*/ z_time_t z_time_now(void) { z_time_t now; diff --git a/src/system/flipper/system.c b/src/system/flipper/system.c index 3d27aaeb1..0498c334f 100644 --- a/src/system/flipper/system.c +++ b/src/system/flipper/system.c @@ -153,6 +153,10 @@ z_result_t _z_condvar_signal_all(_z_condvar_t* cv) { return -1; } z_result_t _z_condvar_wait(_z_condvar_t* cv, _z_mutex_t* m) { return -1; } +z_result_t _z_condvar_wait_until(_z_condvar_t* cv, _z_mutex_t* m, const z_clock_t* abstime, bool* timeout) { + return -1; +} + /*------------------ Sleep ------------------*/ z_result_t z_sleep_us(size_t time) { furi_delay_us(time); @@ -214,6 +218,28 @@ unsigned long z_clock_elapsed_s(z_clock_t* instant) { return elapsed; } +void z_clock_advance_us(z_clock_t* clock, unsigned long duration) { + clock->tv_sec += duration / 1000000; + clock->tv_nsec += (duration % 1000000) * 1000; + + if (clock->tv_nsec >= 1000000000) { + clock->tv_sec += 1; + clock->tv_nsec -= 1000000000; + } +} + +void z_clock_advance_ms(z_clock_t* clock, unsigned long duration) { + clock->tv_sec += duration / 1000; + clock->tv_nsec += (duration % 1000) * 1000000; + + if (clock->tv_nsec >= 1000000000) { + clock->tv_sec += 1; + clock->tv_nsec -= 1000000000; + } +} + +void z_clock_advance_s(z_clock_t* clock, unsigned long duration) { clock->tv_sec += duration; } + /*------------------ Time ------------------*/ z_time_t z_time_now(void) { z_time_t now;