cvra / platform-abstraction

Platform abstraction layer for microcontrollers
3 stars 6 forks source link

timestamps #42

Closed 31415us closed 10 years ago

31415us commented 10 years ago

at some point we're going to need timestamps to measure time and timedifferences. we should discuss resolutions (milli-, micro-, nano-) and how to achieve synchronization.

antoinealb commented 10 years ago

Yeah, its time to do it. http://stream1.gifsoup.com/view1/1336353/horatio-lunettes-o.gif

antoinealb commented 10 years ago

More seriously : unsigned int, 32 bits, microseconds ?

msplr commented 10 years ago

+1 for uint32 in us

msplr commented 10 years ago
/** Get a timestamp in microseconds */
uint32_t os_timestamp(void);

/** Updates the timestamp and returns the difference to the previous. */
uint32_t os_timestamp_update(uint32_t *ts);

Something like that?

31415us commented 10 years ago

hmm what happens if you update with a past value? or more precisely what exactly are the responsibilities of os_timestamp_update?

msplr commented 10 years ago
uint32_t os_timestamp_update(uint32_t *ts)
{
    uint32_t diff, now;
    now = os_timestamp();
    diff = now - *ts;
    *ts = now;
    return diff;
}

I thought this would be a regular use case, so we could implement it in a simple function directly.

antoinealb commented 10 years ago

I think actually expanding the computation in caller code is more readable.

antoinealb commented 10 years ago

By the way after a bit of thinking I would split this functionality into two modules : The local timestamp in platform abstraction and the clock sync in the network / bus module. What do you think ?

31415us commented 10 years ago

@antoinealb yeah i agree that it's best to separate those two

Stapelzeiger commented 10 years ago

We neet two sorts of timestamps anyway. One monotonic for computation and one that is synced. For the monotonic we should have a function like the one nuft proposed, because it will be used a lot. We could find a clearer name for it though.

antoinealb commented 10 years ago

Maybe something more explicit like timestamp_diff_and_update.

Stapelzeiger commented 10 years ago

yes, that looks good

msplr commented 10 years ago

sounds good.

msplr commented 10 years ago

I think timestamp_diff_and_update() should also be atomic.

Stapelzeiger commented 10 years ago

It should be enough if the timestamp function is atomic

antoinealb commented 10 years ago

The timestamp function obviously has to be atomic, doesn't it ?

Stapelzeiger commented 10 years ago

Well, yes.