Skip to content

Need for a Generic Instant/Time/Duration  #122

Open
@tib888

Description

@tib888

Hi All,

I'v run into the need for a generic "Instant" implementation several times.

  • Its implementation could be "tick based", for example running from 72Mhz clock with an u32 counter - this overflows about every 1 minute.
  • Or can be "time based" for example every 1ms an u32 counter is incremented, so we do not have to worry about overflows for about 50 days.

Depending on your application you can decide what resolution ticks you need (and how often you can tolerate an overflow) and what kind of HW resources you have to increase a counter.

Then this implementation of "Instant" trait(s) could be passed to various stuff, like:

  • measure impulse width of an infrared remote control
  • decide between clicks / double clicks
  • switch debounce filters
  • measure the length of light part of the days
  • etc.

Each of these implementations would be generic about the "Instant" trait(s), but all of them likely

  • want to store one or more past instant so it most be Copy
  • calculate the duration between these instants ops::Sub<Output=DURATION>
  • make some calculation with these durations, so DURATION: Default, Copy, ops::Add<Output=DURATION>, ops::Sub<Output=DURATION>
  • calculate a future instant by adding a duration to a past instant
  • compare/order instants, durations
  • convert this duration into a known time unit for example Into < Microseconds >

The std time, duration is too big overhead for an embedded system, with this abstraction each application could be provided with a well optimized time measurement utility.

Please comment!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions