-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
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
@@ -329,6 +330,7 @@ static inline int counter_cancel_channel_alarm(struct device *dev, | |||
* @retval -EBUSY if any alarm is active. |
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
@@ -329,6 +330,7 @@ static inline int counter_cancel_channel_alarm(struct device *dev, | |||
* @retval -EBUSY if any alarm is active. | |||
*/ | |||
static inline int counter_set_top_value(struct device *dev, u32_t ticks, | |||
bool reset, |
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
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? |
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
@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. |
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
if (ticks != info->max_top_value) { | ||
LOG_ERR("Wrap can only be set to 0x%x", info->max_top_value); | ||
if ((cfg->ticks != info->max_top_value) || | ||
!(cfg->flags & COUNTER_TOP_CFG_DONT_RESET)) { |
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
@@ -91,10 +91,12 @@ static u32_t counter_gecko_read(struct device *dev) | |||
} | |||
|
|||
static int counter_gecko_set_top_value(struct device *dev, u32_t ticks, | |||
counter_top_callback_t callback, | |||
void *user_data) | |||
const struct counter_top_cfg *top_cfg) |
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
cfg->callback ? true : false); | ||
|
||
if ((cfg->flags & COUNTER_TOP_CFG_DONT_RESET) && | ||
(counter_nrfx_read(dev) > cfg->ticks)) { |
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
cfg->ticks, COUNTER_OVERFLOW_SHORT, | ||
cfg->callback ? true : false); | ||
|
||
if ((cfg->flags & COUNTER_TOP_CFG_DONT_RESET) && |
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
@@ -91,10 +91,12 @@ static u32_t counter_gecko_read(struct device *dev) | |||
} | |||
|
|||
static int counter_gecko_set_top_value(struct device *dev, u32_t ticks, |
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
LOG_ERR("Wrap can only be set to 0x%x", info->max_top_value); | ||
if (cfg->ticks != info->max_top_value){ | ||
LOG_ERR("Wrap can only be set to 0x%x. " | ||
"Counter reset is not supported.", info->max_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.
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. |
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.