-
Notifications
You must be signed in to change notification settings - Fork 7.7k
drivers: counter: introduce counter capture api #89127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
drivers: counter: introduce counter capture api #89127
Conversation
Add a reset counter api to set the time back to 0. Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
bed095d
to
eedf177
Compare
Introduce a counter set value api to set the ticks for 32b and 64b. Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
eedf177
to
f3dec28
Compare
This introduces apis for input capture on the STM32. This is something agnostic enough that is seen on other vendors such as Atmel's SAM line and others. A use case for this would be time stamping a rising and/or falling edge where precision and lack of jitter is important. The only way to currently do this in zephyr is to set up a GPIO interrupt and then read the counter or kernel time... but this can have limitations of software such as the processor may have a lot going on and can be subject to interrupt latencies. Having a hardware 'latch' done of the rising and/or falling edge with respect to a timer can eliminate these imprecisions. How this is to be used, is that an application is to call `capture_callback_set` with the configuration of the channel number, flags (such as falling, rising, or both edges), and then a callback function. Then the `capture_enable` function is to be called to enable this. The callback has the timestamp of the edge in ticks and the edge that it captured (rising or falling). Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Some counters, such as those that use fractional adders, tick at resolutions greater than 4294967295Hz. This changes the freq in the common info to a uint64_t. This retains the existing `counter_get_freq` function which will still return a 32bit value. This also adds a `counter_get_freq_64` function to get a 64bit value for the frequency. Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Add inline helper functions for converting ticks to nanoseconds. Also implement an inline helper for converting microseconds or nanoseconds with a 64bit tick value. Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
f3dec28
to
8b678d7
Compare
How is this functionally different from what is offered by the PWM capture API? |
That PWM capture measures the period and duty cycle of a pulse. This counter capture captures the exact time of a rising and/or falling edge when it happens. |
@XenuIsWatching when would it be a good time for you to present this in the Architecture WG meeting on Tuesdays? |
Hey @carlescufi , sorry for getting back to a bit late, I do plan on getting back to this, but right now I"m dealing with other priorities. I'll ping you went I can get around to making some slides |
This introduces apis for input capture on the STM32. This is something
agnostic enough that is seen on other vendors such as Atmel's SAM line
and others.
A use case for this would be time stamping a rising and/or falling edge
where precision and lack of jitter is important. The only way to currently
do this in zephyr is to set up a GPIO interrupt and then read the counter
or kernel time... but this can have limitations of software such as the
processor may have a lot going on and can be subject to interrupt latencies.
Having a hardware 'latch' done of the rising and/or falling edge with
respect to a timer can eliminate these imprecisions.
How this is to be used, is that an application is to call
capture_callback_set
with the configuration of the channel number, flags(such as falling, rising, or both edges), and then a callback function. Then
the
capture_enable
function is to be called to enable this. The callbackhas the timestamp of the edge in ticks and the edge that it captured (rising
or falling).
This also introduces an api for set the counter time.
Also, this set frequency to be 64 bits rather than 32 bits, as counters,
such as those that use fractional adders, tick at resolutions
greater than 4294967295Hz. This changes the freq in the common info
to a uint64_t. This retains the existing
counter_get_freq
function whichwill still return a 32bit value. This also adds a
counter_get_freq_64
function to get a 64bit value for the frequency.
Add inline helper functions for converting ticks to nanoseconds.
Also implement an inline helper for converting microseconds or
nanoseconds with a 64bit tick value.