From f77d00b0c96c6f88625dd51f8e56496c4490ffc4 Mon Sep 17 00:00:00 2001 From: fxcoder Date: Thu, 6 Jul 2023 05:57:10 +0000 Subject: [PATCH] Revise chtm.c to allow time chaining of same object git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16311 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/rt/src/chtm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/os/rt/src/chtm.c b/os/rt/src/chtm.c index 016b8db0c..6644403f7 100644 --- a/os/rt/src/chtm.c +++ b/os/rt/src/chtm.c @@ -152,11 +152,13 @@ NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp) { NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1, time_measurement_t *tmp2) { - /* Starts new measurement.*/ - tmp2->last = chSysGetRealtimeCounterX(); + /* Get current time for measurement.*/ + rtcnt_t now = chSysGetRealtimeCounterX(); - /* Stops previous measurement using the same time stamp.*/ - tm_stop(tmp1, tmp2->last, (rtcnt_t)0); + /* Stop previous measurement using current time. Update chained only after + stop since the same measurement object may be used.*/ + tm_stop(tmp1, now, (rtcnt_t)0); + tmp2->last = now; } #endif /* CH_CFG_USE_TM == TRUE */