-
Notifications
You must be signed in to change notification settings - Fork 8.2k
counter: Update counter API in order to provide more flexibility #14794
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
counter: Update counter API in order to provide more flexibility #14794
Conversation
5bfcdcb to
21c43d3
Compare
|
All checks are passing now. Review history of this comment for details about previous failed status. |
21c43d3 to
cbe1f20
Compare
include/counter.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add -ENOTSUP error if option is not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
include/counter.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder if it's not worth to bundle options to cfg structure like in counter_set_channel_alarm. It's then easier to add new features without braking backward compatibility (as long as false in option means legacy behavior). Now we exceed boundary of 4 arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that with 5 arguments we are still more efficient that using separate data structure.
206796d to
de46337
Compare
|
@nordic-krch: Could you please look at the last update? |
de46337 to
25adb2c
Compare
25adb2c to
86d5134
Compare
ioannisg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to me. Does the counter test still pass with the modified API?
|
@ioannisg: As seen in the shippable. |
Does Shippable actually run this test on target? |
anangl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of adding the reset parameter is good, but I think it would be indeed better to use a structure for passing the parameters to the counter_set_top_value function, as @nordic-krch suggested earlier. In most cases it will be more efficient than passing 5 arguments to the function (4 via registers and the fifth via stack), especially when the contents of the structure will be constant, what I think can be expected to happen often. And we'll gain the flexibility mentioned by @nordic-krch. Please, consider it once more. The amount of work needed to switch to this approach does not seem to be that big. I can help a bit if needed.
86d5134 to
79e4c82
Compare
|
@pizi-nordic @anangl can you take a look as I've updated it to use configuration struct instead of function arguments. |
79e4c82 to
4f3e5fe
Compare
|
@benpicco, squashed. |
|
@erwango @MaureenHelm can you please take a look and give feedback? |
3be3396 to
36dc9b6
Compare
|
I've added following updates:
Added implementation for 4 drivers which can support that now: |
|
looks good to me. |
|
@mnkp can you take a look at the recent changes? Lets make goal to merge it in 3 months from submitting. One week left. |
|
@anangl could you also take a look? Since you approved there were some changes. |
mnkp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drivers/counter/counter_mcux_rtc.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default COUNTER_TOP_CFG_DONT_RESET is not set so this if statement will evaluate to true. This is change of behavior. I didn't check the datasheet but how come this counter doesn't start counting from 0 when it's reaching the top value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've digged into the manual. Counter can be reset or left free running. I've added implementation to support resetting the counter.
This is change of behavior
well, behavior was a bug according to counter_set_top_value description in master:
Function sets top value and resets the counter to 0 or top value depending on counter direction.
Now it will be clarified.
drivers/counter/counter_gecko_rtcc.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use cfg instead of top_cfg like in all other drivers. To make it more consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
36dc9b6 to
f549332
Compare
drivers/counter/counter_nrfx_timer.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be >=.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
drivers/counter/counter_nrfx_timer.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, even if the counter is reset, we can end up with the top value set lower than the current counter value. Although it could happen only for very low top values and accordingly high latencies between clearing the counter and setting the new compare value, but maybe such unusual scenario should be handled as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Should we use the same approach in counter_nrfx_rtc, for consistency and for people having the need to set top value to 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/counter/counter_gecko_rtcc.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ticks is now a field of the counter_top_cfg structure. Does this compile successfully?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no test that uses that apparently. Fixed.
f549332 to
f7b04e8
Compare
drivers/counter/counter_mcux_rtc.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second part of the message is no longer valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
645a321 to
039f9b9
Compare
039f9b9 to
9757265
Compare
9757265 to
64a3667
Compare
|
@mnkp your comments applied. Anything more? |
64a3667 to
b6c4214
Compare
|
@mnkp gentle ping. |
mnkp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with minor comments.
This commit introduces new top_value setting configuration structure with flag for controlling resetting of the counter during change of top value. Such change allows for zephyrproject-rtos#12068 implementation on hardware which does not provide alarms. Signed-off-by: Piotr Zięcik <[email protected]> Signed-off-by: Krzysztof Chruscinski <[email protected]> Signed-off-by: Benjamin Valentin <[email protected]>
b6c4214 to
10329ce
Compare
This PR introduces new "reset" parameter to the set_top_value()
making resetting counter optional during change of top value.
Such change allows for #12068 implementation on hardware which
does not provide alarms.