Improved calibration procedure.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13367 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2020-02-19 13:02:06 +00:00
parent 9590773bc5
commit a5e60e7a66
1 changed files with 15 additions and 3 deletions

View File

@ -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);
i = TM_CALIBRATION_LOOP;
do {
chTMStartMeasurementX(&tm);
chTMStopMeasurementX(&tm);
ch.tm.offset = tm.last;
i--;
} while (i > 0U);
ch.tm.offset = tm.best;
}
/**