I've been looking for a good way to measure time between function calls and the TM module seems to be the way to go.
However I have some questions regarding its usage and implementation.
The TM module is based on the DWT which (if I read the manual correctly) clocks at the same rate as the system clock.
For example in my STM32F405RGT running at 168 MHz, this "timer" counts at 168 MHz.
Now to the questions.
--- The system should know from the initialization it's calculated clock rate (at least the ST start driver does this), is there a way to access this in ChibiOS? I could not find this in the documentation.
This would be very good to have when calculating a time from the counter.
--- The TM module does not seem to allow the chaining of multiple calls using a singe call (except chTMChainMeasurementToX(), but it needs two TM modules).
How is it meant to be used for chaining time measurements?
Code: Select all
...
chTMStopMeasurementX(&mytm); // Stop the old measurement
chTMStartMeasurementX(&mytm); // Start the new measurement
... // Use the measurement in mytm--- The TM module does not seem to take into account overflows of the DWT counter? Something like this is how I believe tm_stop() should be:
Code: Select all
static inline void tm_stop(time_measurement_t *tmp,
rtcnt_t now,
rtcnt_t offset) {
tmp->n++;
if (now > tmp->last) /* No overflow */
tmp->last = now - tmp->last - offset;
else if (now < tmp->last) /* Timer overflow */
tmp->last = ((0xffffffff - tmp->last) + now) - offset;
tmp->cumulative += (rttime_t)tmp->last;
if (tmp->last > tmp->worst)
tmp->worst = tmp->last;
else if (tmp->last < tmp->best)
tmp->best = tmp->last;
}--- What is the meaning of ch.measurement_offset in chTMStopMeasurementX()? Why should an offset be added to the measured time?
Edit: Figured this one out. It is to compensate for the cycles needed to call chTMStopMeasurementX and chTMStartMeasurementX.
Please advice.
Best Regards
Emil