Time-stamps?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
igor
Posts: 50
Joined: Sun Aug 16, 2015 7:24 pm
Has thanked: 1 time

Time-stamps?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Time-stamps?

Post 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
User avatar
igor
Posts: 50
Joined: Sun Aug 16, 2015 7:24 pm
Has thanked: 1 time

Re: Time-stamps?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Time-stamps?

Post by Giovanni »

chVTGetSystemTime() (without X) has the critical zone internally.

Giovanni
User avatar
igor
Posts: 50
Joined: Sun Aug 16, 2015 7:24 pm
Has thanked: 1 time

Re: Time-stamps?

Post 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.
Post Reply