This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 30c51ae36d2121ce2519b9516651c21989c846af
Author: Alan Carvalho de Assis <[email protected]>
AuthorDate: Sat Nov 14 18:34:21 2026 -0300

    drivers/timers/capture: Add edge time stamp operations.
    
    A capture lower half reports the frequency, duty cycle and edge count
    of its input, and notifies the edges through bind(), but the callback
    cannot tell when the edge happened: the counter value latched by the
    hardware on the edge is not available, and neither is the counter
    itself.
    
    Add two optional operations at the end of struct cap_ops_s:
    
    * getcount() reads the current value of the free running counter.
    * getcapture() returns the counter value latched by the hardware on
      the last notified edge.  It is called from the notification
      callback, so the time of the edge does not depend on the interrupt
      latency.
    
    They let kernel drivers, such as a PPS disciplined clock, time stamp
    edges with a capture lower half.  Existing lower halves use designated
    initializers and are not changed.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Alan Carvalho de Assis <[email protected]>
---
 Documentation/os/drivers/character/timers/capture.rst | 18 ++++++++++++++++++
 include/nuttx/timers/capture.h                        | 15 +++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/Documentation/os/drivers/character/timers/capture.rst 
b/Documentation/os/drivers/character/timers/capture.rst
index a9edcd3f920..2e7e5cbadd6 100644
--- a/Documentation/os/drivers/character/timers/capture.rst
+++ b/Documentation/os/drivers/character/timers/capture.rst
@@ -356,6 +356,24 @@ When ``CONFIG_CAPTURE_NOTIFY`` is enabled:
 * Ideal for event-driven applications like tachometers, encoders, and
   frequency counters
 
+Edge Time Stamps
+~~~~~~~~~~~~~~~~
+
+A lower half whose timer counter runs freely can also implement two optional
+operations:
+
+* ``getcount()`` reads the current value of the counter.
+* ``getcapture()`` returns the counter value latched by the hardware on the
+  last notified edge. It is called from the notification callback set by
+  ``bind()``, so the time of the edge does not depend on the interrupt
+  latency.
+
+They are used by kernel drivers built on a capture lower half, such as the
+PPS disciplined PTP clock (``CONFIG_PTP_PPS``, see
+:doc:`/os/drivers/special/ptp`). The STM32 timer capture
+(``arch/arm/src/common/stm32/stm32_capture_m3m4_v1_lowerhalf.c``) implements
+them.
+
 Fake Capture Driver
 ~~~~~~~~~~~~~~~~~~~
 
diff --git a/include/nuttx/timers/capture.h b/include/nuttx/timers/capture.h
index f5d09739c5f..b9d620ebaa2 100644
--- a/include/nuttx/timers/capture.h
+++ b/include/nuttx/timers/capture.h
@@ -281,6 +281,21 @@ struct cap_ops_s
 
   CODE int (*get_input_state)(FAR struct cap_lowerhalf_s *lower,
                               FAR uint8_t *state);
+
+  /* Get the current value of the free running counter that time stamps
+   * the captured edges (optional).
+   */
+
+  CODE int (*getcount)(FAR struct cap_lowerhalf_s *lower,
+                       FAR uint32_t *count);
+
+  /* Get the counter value latched by the hardware on the last captured
+   * edge (optional).  Called from the notification callback, it gives the
+   * time of the edge independently of the interrupt latency.
+   */
+
+  CODE int (*getcapture)(FAR struct cap_lowerhalf_s *lower,
+                         FAR uint32_t *count);
 };
 
 /* This structure provides the publicly visible representation of the

Reply via email to