Skip to content

Commit

Permalink
Add opencv and flipper clock advance implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsowa committed Dec 15, 2024
1 parent d86cc51 commit 59f88aa
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/system/arduino/opencr/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------*/
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions src/system/flipper/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 59f88aa

Please sign in to comment.