Vajnar commented on code in PR #16491:
URL: https://github.com/apache/nuttx/pull/16491#discussion_r2157371076
##########
arch/risc-v/src/common/espressif/esp_pcnt.c:
##########
@@ -642,8 +646,28 @@ static int esp_pcnt_unit_get_count(struct cap_lowerhalf_s
*dev, int *ret)
}
flags = spin_lock_irqsave(&priv->lock);
- *ret = pcnt_ll_get_count(ctx.dev, priv->unit_id) +
- priv->accum_value;
+ tmp_count = pcnt_ll_get_count(ctx.dev, priv->unit_id);
+
+ if (priv->config.accum_count)
+ {
+ intr_status = pcnt_ll_get_intr_status(ctx.dev);
+ if (intr_status & PCNT_LL_UNIT_WATCH_EVENT(priv->unit_id))
+ {
+ event_status = pcnt_ll_get_event_status(ctx.dev, priv->unit_id);
+ if ((event_status & (1 << PCNT_LL_WATCH_EVENT_LOW_LIMIT)) && \
+ (tmp_count >= (priv->config.low_limit / 2)))
+ {
+ tmp_count += priv->config.low_limit;
+ }
Review Comment:
The overflow could happen after calling `pcnt_ll_get_count()` and before
evaluating `pcnt_ll_get_intr_status()` in such case we don't want compensation
and the condition is there to check for this case.
As @ppisa mentioned earlier, this code can work correctly provided we don't
overflow twice per the interval between evaluating `pcnt_ll_get_count()` and
`pcnt_ll_get_intr_status()`. Which maybe should be mentioned somewhere in
documentation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]