Page 1 of 1

Time-stamps?

Posted: Thu Oct 08, 2015 9:57 pm
by igor
Hi,
I would like to generate time stamps, for the purpose of tracking events, with ms resolution, without having to process them immediately.

Some use cases:
* calculation of average duration of a certain event (with start and stop timestamps)
* implementation of moving average (a bit like the previous point, but applied to a stream of events)

What would be the recommended way to do it?
I have noticed the existence of a "Measurement" facility, but that would seem overkill.

thanks, igor

Re: Time-stamps?

Posted: Thu Oct 08, 2015 10:14 pm
by Giovanni
It is not overkill, it does just that. You can use the system time as stamps if you prefer, chVTGetSystemTimeX(), the resolution is what is defined in chconf.h.

Giovanni

Re: Time-stamps?

Posted: Thu Oct 08, 2015 11:49 pm
by igor
Giovanni wrote:It is not overkill, it does just that.


I should have added "for my needs".
In particular, for the moving average scenario, it doesn't seem a good match, as I want to have a few (4 or 8) values in a circular buffer.

Giovanni wrote:You can use the system time as stamps if you prefer, chVTGetSystemTimeX(), the resolution is what is defined in chconf.h.
Giovanni


This is closer to what I had in mind.
On AVR328, which is what I'm using, and is 8 bit, I'll have to call it with interrupts disabled, since the return value is 2 bytes.

thanks a lot, igor

Re: Time-stamps?

Posted: Fri Oct 09, 2015 8:55 am
by Giovanni
chVTGetSystemTime() (without X) has the critical zone internally.

Giovanni

Re: Time-stamps?

Posted: Fri Oct 09, 2015 1:18 pm
by igor
Giovanni wrote:chVTGetSystemTime() (without X) has the critical zone internally.


To be equivalent to me handling the locking explicitly, it would have to rely on gcc being smart enough to optimize away the systime helper variable and instead use mine inside the critical section. Or anyway avoid the hop.