This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: cec-ctl: warn if the SFT is too short
Author:  Hans Verkuil <[email protected]>
Date:    Wed Nov 19 09:25:55 2025 +0100

Warn if the detected Signal Free Time is too short. This helps
debugging SFT-related issues.

The SIGNAL_FREE_TIME defines are moved to cec-info.h so they can
be shared between cec-ctl and cec-compliance.

This patch accidentally ended up in a development branch, squashed
with an unrelated patch. But this is a useful addition to have when
debugging low-level CEC issues.

Signed-off-by: Hans Verkuil <[email protected]>

 utils/cec-compliance/cec-test-adapter.cpp |  9 ++-------
 utils/cec-ctl/cec-pin.cpp                 | 30 ++++++++++++++++++++++++++++++
 utils/libcecutil/cec-info.h               |  5 +++++
 3 files changed, 37 insertions(+), 7 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=02aea36005eaeb8b5dc54b4a35980b220c3eba4d
diff --git a/utils/cec-compliance/cec-test-adapter.cpp 
b/utils/cec-compliance/cec-test-adapter.cpp
index 18b2a065f951..23039c0696e6 100644
--- a/utils/cec-compliance/cec-test-adapter.cpp
+++ b/utils/cec-compliance/cec-test-adapter.cpp
@@ -1111,13 +1111,8 @@ static void print_sfts(unsigned sft[12], const char 
*descr)
 // actually tests a lot more: it also checks Signal Free Time behavior
 // and if the speed of the CEC bus is as expected.
 
-// Some defines dealing with SFTs (from include/media/cec.h):
-// Correct Signal Free times are:
-#define CEC_SIGNAL_FREE_TIME_RETRY             3
-#define CEC_SIGNAL_FREE_TIME_NEW_INITIATOR     5
-#define CEC_SIGNAL_FREE_TIME_NEXT_XFER         7
-// but for measuring we support up to 11:
-#define CEC_SIGNAL_FREE_TIME_MAX               11
+// For measuring SFT we support up to 11:
+#define CEC_SIGNAL_FREE_TIME_MAX       11
 
 // Two defines (copied from include/media/cec.h) that give the maximum
 // number of CEC messages that can be queued up in the transmit and
diff --git a/utils/cec-ctl/cec-pin.cpp b/utils/cec-ctl/cec-pin.cpp
index f35005554bfd..e8360ea3d325 100644
--- a/utils/cec-ctl/cec-pin.cpp
+++ b/utils/cec-ctl/cec-pin.cpp
@@ -93,6 +93,12 @@ static bool bcast;
 static bool cdc;
 static struct cec_msg msg;
 
+static double cur_sft;
+static bool cur_retry;
+static unsigned prev_header;
+static bool prev_failed;
+static bool new_initiator;
+
 static void cec_pin_rx_start_bit_was_high(bool is_high, __u64 usecs, __u64 
usecs_min, bool show)
 {
        bool period_too_long = low_usecs + usecs > CEC_TIM_START_BIT_TOTAL_LONG;
@@ -181,6 +187,13 @@ static void cec_pin_rx_data_bit_was_high(bool is_high, 
__u64 ev_ts,
 
                bool ack = !(bcast ^ bit);
 
+               if (byte_cnt == 0) {
+                       new_initiator = ((byte >> 4) != (prev_header >> 4));
+                       cur_retry = prev_failed && !new_initiator;
+                       prev_failed = true;
+                       prev_header = byte;
+               }
+
                if (msg.len < CEC_MAX_MSG_SIZE)
                        msg.msg[msg.len++] = byte;
                if (show)
@@ -198,6 +211,17 @@ static void cec_pin_rx_data_bit_was_high(bool is_high, 
__u64 ev_ts,
                byte_cnt++;
                if (byte_cnt >= CEC_MAX_MSG_SIZE)
                        eom_reached = true;
+               if (eom && msg.len) {
+                       unsigned sft = new_initiator ? 
CEC_SIGNAL_FREE_TIME_NEW_INITIATOR :
+                               CEC_SIGNAL_FREE_TIME_NEXT_XFER;
+
+                       if (cur_retry)
+                               sft = CEC_SIGNAL_FREE_TIME_RETRY;
+                       if (cur_sft + 0.5 < sft)
+                               printf("%s: warn: signal free time too short 
(%.1f instead of %d)\n",
+                                      ts2s(ts).c_str(), cur_sft, sft);
+                       prev_failed = !ack;
+               }
                if (show && eom && msg.len > 2) {
                        msg.rx_status = CEC_RX_STATUS_OK;
                        msg.rx_ts = ev_ts;
@@ -333,6 +357,11 @@ void log_event_pin(bool is_high, __u64 ev_ts, bool show)
        ts = ev_ts / 1000000000.0;
        if (last_change_ts == 0) {
                last_ts = last_change_ts = last_1_to_0_ts = ev_ts - 
CEC_TIM_DATA_BIT_TOTAL * 16000;
+               cur_sft = 10;
+               cur_retry = false;
+               prev_header = 0;
+               prev_failed = false;
+               new_initiator = true;
                if (is_high)
                        return;
        }
@@ -356,6 +385,7 @@ void log_event_pin(bool is_high, __u64 ev_ts, bool show)
                                            delta, bit_periods);
                        else
                                verb_printf("1 -> 0 (was 1 for %.2f ms)\n", 
delta);
+                       cur_sft = bit_periods;
                } else if (was_high && (ev_ts - last_1_to_0_ts) / 1000000 <= 
10) {
                        verb_printf("1 -> 0 (was 1 for %.2f ms, period of 
previous %spulse %.2f ms)\n",
                                    delta, state == CEC_ST_RECEIVE_START_BIT ? 
"start " : "",
diff --git a/utils/libcecutil/cec-info.h b/utils/libcecutil/cec-info.h
index 8178aa8328d4..8db57180c480 100644
--- a/utils/libcecutil/cec-info.h
+++ b/utils/libcecutil/cec-info.h
@@ -10,6 +10,11 @@
 
 #include <linux/cec.h>
 
+// Some defines dealing with SFTs (from include/media/cec.h):
+#define CEC_SIGNAL_FREE_TIME_RETRY             3
+#define CEC_SIGNAL_FREE_TIME_NEW_INITIATOR     5
+#define CEC_SIGNAL_FREE_TIME_NEXT_XFER         7
+
 #define cec_phys_addr_exp(pa) \
         ((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf
 
_______________________________________________
linuxtv-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to