zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
11k stars 6.69k forks source link

Counter (HW timer) - Resetting counter to zero #32157

Open stoberblog opened 3 years ago

stoberblog commented 3 years ago

Is your enhancement proposal related to a problem? Please describe. I would like a function that allows reset/clearing of a counter (HW timer) to 0.

Describe the solution you'd like A function such as int counter_clear(const struct device *dev);

for the nordic nrf hal, I believe this would link to nrf_timer_task_trigger(get_nrfx_config(dev)->timer, NRF_TIMER_TASK_CLEAR);

Describe alternatives you've considered 1) Directly link to the HAL and call the above directly, 2) OR use relative timers, however this has the issue (well how I read the documentation) in that you can't use relative to loop around the timer (ie if at counter say at 50% and you want a relative timer of 75%, it will fail).

Additional context I am starting the counter, running it x number of cycles and then stopping the counter. When I next use the timer I want it to be starting at 0, not an arbitrary number (due to the delay between interrupt trigger and the calling the timer stop function)

LBleijendaal commented 2 years ago

Any progress on this feature? I need this too. Is there a way to reset the counter in a temporary way before this is implemented?

ahmedwahdan commented 1 year ago

Any progress on this feature?

MarshMilo100 commented 1 month ago

A workaround for those still waiting on this feature is to unset COUNTER_TOP_CFG_DONT_RESET in the configuration flags and call counter_set_top_value() but set the top value to the same as it was before. It appears that there is no check for setting the top value to the same number, but the act of setting the value will reset the counter if that flag is configured properly. https://docs.zephyrproject.org/latest/doxygen/html/group__counter__interface.html#ga2d92f5564cdd1ecc56029c3a45e666f0 Though, it would be nice to have a dedicated function to clear or reset the counter easily.