From a5e60e7a666a7bb924644482ca5fa10f9e06484d Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 19 Feb 2020 13:02:06 +0000 Subject: [PATCH] Improved calibration procedure. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13367 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/rt/src/chtm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/os/rt/src/chtm.c b/os/rt/src/chtm.c index c96a33e2a..5ccbf2733 100644 --- a/os/rt/src/chtm.c +++ b/os/rt/src/chtm.c @@ -34,6 +34,13 @@ /* Module local definitions. */ /*===========================================================================*/ +/** + * @brief Number of iterations in the calibration loop. + * @note This is required in order to assess the best result in + * architectures with instruction cache. + */ +#define TM_CALIBRATION_LOOP 4U + /*===========================================================================*/ /* Module exported variables. */ /*===========================================================================*/ @@ -76,15 +83,20 @@ static inline void tm_stop(time_measurement_t *tmp, */ void _tm_init(void) { time_measurement_t tm; + unsigned i; /* Time Measurement subsystem calibration, it does a null measurement and calculates the call overhead which is subtracted to real measurements.*/ ch.tm.offset = (rtcnt_t)0; chTMObjectInit(&tm); - chTMStartMeasurementX(&tm); - chTMStopMeasurementX(&tm); - ch.tm.offset = tm.last; + i = TM_CALIBRATION_LOOP; + do { + chTMStartMeasurementX(&tm); + chTMStopMeasurementX(&tm); + i--; + } while (i > 0U); + ch.tm.offset = tm.best; } /**