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
Time-stamps?
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Time-stamps?
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
Giovanni
Re: Time-stamps?
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
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Time-stamps?
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.