tmedicci commented on code in PR #16491:
URL: https://github.com/apache/nuttx/pull/16491#discussion_r2157295614


##########
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;
+            }
+          else if ((event_status & (1 << PCNT_LL_WATCH_EVENT_HIGH_LIMIT)) && \
+                   (tmp_count <= (priv->config.high_limit / 2)))

Review Comment:
   Same here. I still didn't get why `(tmp_count <= (priv->config.high_limit / 
2))` is a condition to account for the high limit here. If this event status 
happened, the counter is reset, then the high_limit should be added 
independently of its value. What am I missing here?



##########
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:
   I still didn't get why `(tmp_count >= (priv->config.low_limit / 2))` is a 
condition to account for the low limit here. If this event status happened, the 
counter is reset, then the low_limit should be added independently of its 
value. What am I missing here?



##########
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);

Review Comment:
   To summarize: I see this is a possible solution because the counter may have 
been reset due to overflow. Then, we can check if such an interrupt is 
triggered (not yet serviced), update the temporary counter to account for the 
interrupt.
   
   When ISR runs, it will update the accumulator value and clear the interrupt 
flags and the event status (to be confirmed internally).



##########
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;
+            }
+          else if ((event_status & (1 << PCNT_LL_WATCH_EVENT_HIGH_LIMIT)) && \

Review Comment:
   Please fix long line. It won't be merged on NuttX because long line check 
blocks merging on GH.



-- 
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]

Reply via email to