From a66f5cec520e2959d22be3a870e63e23f5032144 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 18 Sep 2025 15:11:20 -0400 Subject: [PATCH] msgblock: Add new clock_fill() function Add a new function for filling the fields of 'struct clock_estimate'. Signed-off-by: Kevin O'Connor --- klippy/chelper/msgblock.c | 11 +++++++++++ klippy/chelper/msgblock.h | 2 ++ klippy/chelper/serialqueue.c | 5 +---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/klippy/chelper/msgblock.c b/klippy/chelper/msgblock.c index e6cb298b4..a7385c893 100644 --- a/klippy/chelper/msgblock.c +++ b/klippy/chelper/msgblock.c @@ -207,3 +207,14 @@ clock_from_time(struct clock_estimate *ce, double time) { return (int64_t)((time - ce->conv_time)*ce->est_freq + .5) + ce->conv_clock; } + +// Fill the fields of a 'struct clock_estimate' +void +clock_fill(struct clock_estimate *ce, double est_freq, double conv_time + , uint64_t conv_clock, uint64_t last_clock) +{ + ce->est_freq = est_freq; + ce->conv_time = conv_time; + ce->conv_clock = conv_clock; + ce->last_clock = last_clock; +} diff --git a/klippy/chelper/msgblock.h b/klippy/chelper/msgblock.h index 43ee95325..9bb066313 100644 --- a/klippy/chelper/msgblock.h +++ b/klippy/chelper/msgblock.h @@ -50,5 +50,7 @@ void message_queue_free(struct list_head *root); uint64_t clock_from_clock32(struct clock_estimate *ce, uint32_t clock32); double clock_to_time(struct clock_estimate *ce, uint64_t clock); uint64_t clock_from_time(struct clock_estimate *ce, double time); +void clock_fill(struct clock_estimate *ce, double est_freq, double conv_time + , uint64_t conv_clock, uint64_t last_clock); #endif // msgblock.h diff --git a/klippy/chelper/serialqueue.c b/klippy/chelper/serialqueue.c index ed1215df9..914d4c395 100644 --- a/klippy/chelper/serialqueue.c +++ b/klippy/chelper/serialqueue.c @@ -909,10 +909,7 @@ serialqueue_set_clock_est(struct serialqueue *sq, double est_freq , uint64_t last_clock) { pthread_mutex_lock(&sq->lock); - sq->ce.est_freq = est_freq; - sq->ce.conv_time = conv_time; - sq->ce.conv_clock = conv_clock; - sq->ce.last_clock = last_clock; + clock_fill(&sq->ce, est_freq, conv_time, conv_clock, last_clock); pthread_mutex_unlock(&sq->lock); }