Modern Apps git

← Modern-Apps.git

findfamily: update tag firmware

Commit
ab928314fa3ea369d29931c27e202dd9de287e90
Author
vayun-mathur <[email protected]>
When
2026-08-23 04:42 UTC (3 months ago)
Parents
e159a1a

Diff

firmware/findfamily-tracker/src/tracker_uwb.c
diff --git a/firmware/findfamily-tracker/src/tracker_uwb.c b/firmware/findfamily-tracker/src/tracker_uwb.cindex 665fdc0976..bc1f3341dc 100644--- a/firmware/findfamily-tracker/src/tracker_uwb.c+++ b/firmware/findfamily-tracker/src/tracker_uwb.c@@ -135,6 +135,40 @@ extern struct l1_config_platform_ops l1_config_platform_ops;  */ uint32_t ff_qorvo_read_dev_id(void); +/*+ * Bring-up instrumentation for the DW3110 interrupt (firmware/qorvo-uwb). llhw arms the+ * interrupt inside llhw_init(), before any session exists. If the line is already asserted by+ * the time it is armed, the rising-edge trigger can never fire and the MAC is never told a+ * frame arrived - which is indistinguishable, in a capture, from a radio that heard nothing.+ * Reported at three fixed points rather than periodically, so it cannot flood the capture.+ */+int ff_qorvo_irq_pin_level(void);+void ff_qorvo_gpio_irq_stats(uint32_t *events, uint32_t *arm_calls);+void ff_qorvo_spi_isr_stats(uint32_t *total, uint32_t *in_isr);+void ff_qorvo_timer_stats(uint32_t *starts, uint32_t *stops, uint32_t *expiries,+			  uint32_t *last_us);++static void log_irq_diag(const char *when)+{+	uint32_t events = 0;+	uint32_t arm_calls = 0;+	uint32_t xfers = 0;+	uint32_t xfers_isr = 0;+	uint32_t t_starts = 0;+	uint32_t t_stops = 0;+	uint32_t t_expiries = 0;+	uint32_t t_last_us = 0;++	ff_qorvo_gpio_irq_stats(&events, &arm_calls);+	ff_qorvo_spi_isr_stats(&xfers, &xfers_isr);+	ff_qorvo_timer_stats(&t_starts, &t_stops, &t_expiries, &t_last_us);+	LOG_INF("IRQ diag (%s): line level=%d, armed %u time(s), ISR entries=%u, "+		"spi xfers=%u (%u from ISR)", when, ff_qorvo_irq_pin_level(), arm_calls,+		events, xfers, xfers_isr);+	LOG_INF("IRQ diag (%s): timer starts=%u stops=%u expiries=%u last_us=%u", when,+		t_starts, t_stops, t_expiries, t_last_us);+}+ /*  * Decoders for the two enums that distinguish the failures this bring-up has to tell  * apart: "never heard anything" (RX_TIMEOUT) from "heard it, STS wrong"@@ -444,6 +478,7 @@ int ff_uwb_init(void)  	stack_ready = true; 	LOG_INF("Qorvo uwbstack up; DW3110 identified");+	log_irq_diag("after llhw_init");  	k_thread_create(&uwb_session_thread_data, uwb_session_stack, 			UWB_SESSION_THREAD_STACK_SIZE, uwb_session_thread, NULL, NULL, NULL,@@ -689,6 +724,7 @@ int ff_uwb_start(const struct ff_uwb_params *params, const uint8_t *secret) 		goto close; 	} 	LOG_INF("FiRa session started");+	log_irq_diag("session started");  	session_active = true; 	atomic_set(&last_activity_ms, (atomic_val_t)k_uptime_get_32());@@ -712,6 +748,8 @@ void ff_uwb_stop(void) 	if (!session_active) { 		return; 	}+	/* Before teardown, so this reports the state at the end of the ACTIVE window. */+	log_irq_diag("session teardown"); 	(void)fira_helper_stop_session(&fira_ctx, session_handle); 	(void)fira_helper_deinit_session(&fira_ctx, session_handle); 	/*
firmware/qorvo-uwb/src/qgpio_zephyr.c
diff --git a/firmware/qorvo-uwb/src/qgpio_zephyr.c b/firmware/qorvo-uwb/src/qgpio_zephyr.cindex 2d1871dbfc..c700d27ae4 100644--- a/firmware/qorvo-uwb/src/qgpio_zephyr.c+++ b/firmware/qorvo-uwb/src/qgpio_zephyr.c@@ -20,6 +20,7 @@ #include <zephyr/drivers/gpio.h> #include <zephyr/kernel.h> #include <zephyr/logging/log.h>+#include <zephyr/sys/atomic.h>  LOG_MODULE_REGISTER(qorvo_qgpio, CONFIG_QORVO_UWB_LOG_LEVEL); @@ -36,6 +37,68 @@ struct cb_entry {  static struct cb_entry callbacks[MAX_CALLBACKS]; +/*+ * The qgpio callback is dispatched from a thread, not from the GPIOTE ISR.+ *+ * The vendor's handler (qplatform_uwb_spi_irq_handler) is `while (irq_high) dwt_isr()`, and+ * dwt_isr() reads SYS_STATUS over SPI. That is legal on Qorvo's nrfx backend, whose+ * qspi_transceive busy-waits on a volatile flag, but not here: Zephyr's spi_transceive()+ * completes via k_sem_take, which cannot wait in ISR context, so every such transfer would+ * fail with -ETIMEDOUT and pend whichever thread happened to be interrupted. qgpio.h permits+ * this — "Considered this called from ISR context unless indicated otherwise on+ * implementation" — so the choice belongs to the backend.+ *+ * The interrupt is deliberately left ARMED while the handler drains. The vendor's loop runs+ * until the line goes low, so an assertion arriving mid-drain is picked up by the loop itself,+ * and a fresh low-to-high transition afterwards produces a new edge and another wakeup.+ * Disabling the trigger around the drain — the usual shape of this refactor — is what would+ * lose an edge. An edge trigger cannot storm while the line stays high, so leaving it armed+ * costs nothing.+ */+static void irq_dispatch_thread(void *a, void *b, void *c);++/*+ * 2048 matches CONFIG_ISR_STACK_SIZE, which is the stack this work ran on until now, so it is+ * a like-for-like size rather than a guess. CONFIG_HW_STACK_PROTECTION is enabled for this+ * board, so an undersized stack faults loudly instead of corrupting a neighbour.+ */+#define IRQ_THREAD_STACK_SIZE 2048++/*+ * Lowest cooperative priority: above every preemptible thread — the Qorvo MAC threads occupy+ * Zephyr 0..6 via qthread_zephyr.c, the poll thread 7, log processing 3 — so MAC work cannot+ * starve the handler it depends on, and cooperative means no timeslice can preempt a drain+ * mid-way. Still below the Bluetooth RX thread at K_PRIO_COOP(CONFIG_BT_RX_PRIO) = -8, so+ * crowd-finding keeps its latency. This is the TRAP-6 tradeoff taken deliberately in BLE's+ * favour.+ */+#define IRQ_THREAD_PRIORITY -1++K_THREAD_DEFINE(qorvo_irq_thread, IRQ_THREAD_STACK_SIZE, irq_dispatch_thread, NULL, NULL, NULL,+		IRQ_THREAD_PRIORITY, 0, 0);++static K_SEM_DEFINE(irq_signal, 0, 1);++/* Which callbacks/pins have fired; a bitmask so one wakeup can serve several. */+static atomic_t irq_pending;++/*+ * Bring-up instrumentation for the transceiver IRQ. llhw arms the DW3110 interrupt+ * (llhw_drv_init -> qplatform_uwb_interrupt_enable) and it is delivered through this file,+ * which until now had no way to report either event: every log statement here is a LOG_ERR,+ * so silence in a capture means "no error", not "armed and delivered".+ *+ * Counters rather than a log line in the callback: logging from the GPIO ISR would perturb+ * the timing being measured, and the arming path is also reached from decamutexon/off around+ * ordinary register access, so it can be hot.+ */+static atomic_t irq_events;+static atomic_t irq_arm_calls;++/* Bounded so a hot arming path cannot flood the capture; as TRACE_XFERS does in qspi_zephyr.c. */+#define IRQ_ARM_TRACE_MAX 8+static unsigned int irq_arm_traced;+ static const struct gpio_dt_spec *spec_of(const struct qgpio *pin) { 	if (pin == NULL || pin->dev == NULL) {@@ -141,19 +204,52 @@ enum qerr qgpio_pin_read(const struct qgpio *qgpio_pin, uint8_t *value) 	return QERR_SUCCESS; } +static const char *trigger_name(gpio_flags_t zephyr_flags)+{+	if (!(zephyr_flags & GPIO_INT_ENABLE)) {+		return "DISABLE";+	}+	if (zephyr_flags & GPIO_INT_EDGE) {+		switch (zephyr_flags & (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1)) {+		case (GPIO_INT_LOW_0 | GPIO_INT_HIGH_1):+			return "EDGE_BOTH";+		case GPIO_INT_HIGH_1:+			return "EDGE_RISING";+		default:+			return "EDGE_FALLING";+		}+	}+	return (zephyr_flags & GPIO_INT_HIGH_1) ? "LEVEL_HIGH" : "LEVEL_LOW";+}+ enum qerr qgpio_pin_irq_configure(const struct qgpio *qgpio_pin, uint32_t flags) { 	const struct gpio_dt_spec *spec = spec_of(qgpio_pin);+	gpio_flags_t zephyr_flags; 	int rc;  	if (spec == NULL) { 		return QERR_EINVAL; 	}-	rc = gpio_pin_interrupt_configure_dt(spec, translate_irq(flags));+	zephyr_flags = translate_irq(flags);+	rc = gpio_pin_interrupt_configure_dt(spec, zephyr_flags); 	if (rc < 0) { 		LOG_ERR("gpio_pin_interrupt_configure_dt: %d", rc); 		return QERR_EIO; 	}+	atomic_inc(&irq_arm_calls);+	if (irq_arm_traced < IRQ_ARM_TRACE_MAX) {+		irq_arm_traced++;+		/*+		 * The level is read *after* arming, which is the point of logging it: an edge+		 * trigger cannot see a line that is already asserted, so "armed EDGE_RISING,+		 * level already 1" is an interrupt that can never fire again and says nothing.+		 */+		LOG_INF("irq armed %s.%u: qgpio=0x%08x -> %s (0x%08x), level now %d",+			spec->port->name, spec->pin, (unsigned int)flags,+			trigger_name(zephyr_flags), (unsigned int)zephyr_flags,+			gpio_pin_get_dt(spec));+	} 	return QERR_SUCCESS; } @@ -164,8 +260,29 @@ static void on_gpio_event(const struct device *port, struct gpio_callback *cb, u 	ARG_UNUSED(port); 	ARG_UNUSED(pins); -	if (entry->cb) {-		entry->cb(entry->arg);+	/* ISR context: signal and return. Nothing here may touch the bus. */+	atomic_inc(&irq_events);+	atomic_or(&irq_pending, (atomic_val_t)BIT(entry - callbacks));+	k_sem_give(&irq_signal);+}++static void irq_dispatch_thread(void *a, void *b, void *c)+{+	ARG_UNUSED(a);+	ARG_UNUSED(b);+	ARG_UNUSED(c);++	for (;;) {+		atomic_val_t pending;++		k_sem_take(&irq_signal, K_FOREVER);+		pending = atomic_and(&irq_pending, 0);++		for (int i = 0; i < MAX_CALLBACKS; i++) {+			if ((pending & BIT(i)) && callbacks[i].used && callbacks[i].cb) {+				callbacks[i].cb(callbacks[i].arg);+			}+		} 	} } @@ -212,5 +329,16 @@ enum qerr qgpio_pin_irq_set_callback(const struct qgpio *qgpio_pin, qgpio_irq_cb 		return QERR_EIO; 	} 	entry->used = true;+	LOG_INF("irq callback registered on %s.%u", spec->port->name, spec->pin); 	return QERR_SUCCESS; }++void ff_qorvo_gpio_irq_stats(uint32_t *events, uint32_t *arm_calls)+{+	if (events != NULL) {+		*events = (uint32_t)atomic_get(&irq_events);+	}+	if (arm_calls != NULL) {+		*arm_calls = (uint32_t)atomic_get(&irq_arm_calls);+	}+}
firmware/qorvo-uwb/src/qhal_extras_zephyr.c
diff --git a/firmware/qorvo-uwb/src/qhal_extras_zephyr.c b/firmware/qorvo-uwb/src/qhal_extras_zephyr.cindex fd3e5f13eb..a1c7c9e6b0 100644--- a/firmware/qorvo-uwb/src/qhal_extras_zephyr.c+++ b/firmware/qorvo-uwb/src/qhal_extras_zephyr.c@@ -139,12 +139,38 @@ void qrtc_resync_rtc_systime(int64_t *rtc_us, uint32_t *systime) 	} 	if (systime) { 		/*-		 * "systime" is the DW3000's own 32-bit system-time counter. The driver-		 * reads it directly, so there is nothing to correlate here beyond-		 * reporting the current RTC; a deep-sleep-across-reset resync would need-		 * the persistent_time machinery this deliberately does not use.+		 * llhw stores this as the anchor tying the DW3110's own timestamp counter to+		 * its DTU timeline (llhw_resync_dtu_systime keeps it, llhw_systime_to_dtu+		 * converts against it). Reporting a constant here does not mean "unused": it+		 * offsets every hardware timestamp by the whole real counter value, and since+		 * the session is time-scheduled, every RX window the MAC computes then refers+		 * to a fiction. The vendor reads the counter for exactly this reason+		 * (qhal/src/nrfx/persistent_time.c, persistent_time_resync_rtc_systime).+		 *+		 * Correlation quality. The two reads are adjacent but NOT atomic, and cannot be+		 * made so here:+		 *  - qrtc_get_us() is tick-granular, so rtc_us alone carries up to one tick,+		 *    30.5 us at 32768 Hz.+		 *  - this read is a blocking SPI transfer. The caller pends on the SPIM+		 *    completion, so the thread YIELDS between the pair, and anything runnable+		 *    then runs: BLE RX (cooperative -8), the transceiver dispatch thread (-1),+		 *    log processing (3). The window is bounded by other work, not by the+		 *    transfer.+		 * At 15.6 DTU/us the best case (tick + transfer, ~50 us) is ~800 DTU; with+		 * preemption it can reach milliseconds, so tens of thousands of DTU.+		 *+		 * Nothing available here closes that. irq_lock() deadlocks, since it masks the+		 * very SPIM completion this read waits on. k_sched_lock() does not help either:+		 * it prevents preemption but not the switch that blocking itself causes. Only a+		 * polling SPI path would, which is what the vendor's nrfx backend has (it+		 * busy-waits on a volatile flag) and ours deliberately does not.+		 *+		 * Tolerable because llhw re-anchors on every MCPS op and every wakeup, so a bad+		 * sample is replaced rather than accumulated, and because the error this+		 * replaces was the entire value of the counter. If ranging proves intermittent+		 * rather than broken, suspect this first. 		 */-		*systime = 0;+		*systime = dwt_readsystimestamphi32(); 	} } 
firmware/qorvo-uwb/src/qplatform_zephyr.c
diff --git a/firmware/qorvo-uwb/src/qplatform_zephyr.c b/firmware/qorvo-uwb/src/qplatform_zephyr.cindex 2ff050d2e1..d538613059 100644--- a/firmware/qorvo-uwb/src/qplatform_zephyr.c+++ b/firmware/qorvo-uwb/src/qplatform_zephyr.c@@ -97,6 +97,16 @@ const struct spi_dt_spec *ff_qorvo_spi_spec(void) 	return &uwb_bus; } +/*+ * Bring-up diagnostic: the current level of the transceiver IRQ line, read through the same+ * devicetree spec the stack itself uses. The overlay declares irq-gpios GPIO_ACTIVE_HIGH, so+ * this logical read equals the physical level on P1.02.+ */+int ff_qorvo_irq_pin_level(void)+{+	return gpio_pin_get_dt(&irq_pin_spec);+}+ uint32_t ff_qorvo_read_dev_id(void) { 	uint8_t tx[5] = { 0x00, 0x00, 0x00, 0x00, 0x00 };
firmware/qorvo-uwb/src/qspi_zephyr.c
diff --git a/firmware/qorvo-uwb/src/qspi_zephyr.c b/firmware/qorvo-uwb/src/qspi_zephyr.cindex 1a3709b8f3..44ca038c8a 100644--- a/firmware/qorvo-uwb/src/qspi_zephyr.c+++ b/firmware/qorvo-uwb/src/qspi_zephyr.c@@ -18,6 +18,7 @@ #include <zephyr/drivers/spi.h> #include <zephyr/kernel.h> #include <zephyr/logging/log.h>+#include <zephyr/sys/atomic.h>  #include <string.h> @@ -47,6 +48,26 @@ static struct qspi the_spi; #define TRACE_XFERS 4 static unsigned int traced; +/*+ * Whether any transfer runs in ISR context, which is what the qgpio deferral exists to+ * eliminate. The error line reports context only when a transfer FAILS; these count every+ * transfer, so "none from ISR" becomes a positive observation rather than an inference from an+ * absence. The total is the control: without it a zero ISR count cannot be distinguished from+ * a counter that never ran.+ */+static atomic_t xfers_total;+static atomic_t xfers_in_isr;++void ff_qorvo_spi_isr_stats(uint32_t *total, uint32_t *in_isr)+{+	if (total != NULL) {+		*total = (uint32_t)atomic_get(&xfers_total);+	}+	if (in_isr != NULL) {+		*in_isr = (uint32_t)atomic_get(&xfers_in_isr);+	}+}+ struct qspi *qspi_open(const struct qspi_instance *instance) { 	const struct device *dev;@@ -128,12 +149,19 @@ enum qerr qspi_transceive(struct qspi *spi, const struct qspi_transfer *xfer) 	struct spi_buf rx_buf; 	struct spi_buf_set tx_set = { .buffers = &tx_buf, .count = 1 }; 	struct spi_buf_set rx_set = { .buffers = &rx_buf, .count = 1 };+	bool in_isr; 	int rc;  	if (spi == NULL || xfer == NULL || spi->dev == NULL) { 		return QERR_EINVAL; 	} +	in_isr = k_is_in_isr();+	atomic_inc(&xfers_total);+	if (in_isr) {+		atomic_inc(&xfers_in_isr);+	}+ 	tx_buf.buf = xfer->tx_buf; 	tx_buf.len = xfer->tx_size; 	rx_buf.buf = xfer->rx_buf;@@ -143,7 +171,14 @@ enum qerr qspi_transceive(struct qspi *spi, const struct qspi_transfer *xfer) 			    xfer->tx_buf ? &tx_set : NULL, 			    xfer->rx_buf ? &rx_set : NULL); 	if (rc < 0) {-		LOG_ERR("spi_transceive failed: %d", rc);+		/*+		 * isr= is the attribution: Zephyr's spi_transceive() completes via+		 * k_sem_take, so a failure with isr=1 is an ISR-context path that should have+		 * been deferred, while isr=0 is an ordinary bus error. The line carries no+		 * caller otherwise, and thread-id prefixing would not help — in an ISR that+		 * records whichever thread was interrupted.+		 */+		LOG_ERR("spi_transceive failed: %d (isr=%d)", rc, (int)in_isr); 		return QERR_EIO; 	} 
firmware/qorvo-uwb/src/qtimer_zephyr.c
diff --git a/firmware/qorvo-uwb/src/qtimer_zephyr.c b/firmware/qorvo-uwb/src/qtimer_zephyr.cindex 823d48df71..7854e59d6d 100644--- a/firmware/qorvo-uwb/src/qtimer_zephyr.c+++ b/firmware/qorvo-uwb/src/qtimer_zephyr.c@@ -20,6 +20,7 @@  #include <zephyr/kernel.h> #include <zephyr/logging/log.h>+#include <zephyr/sys/atomic.h>  LOG_MODULE_REGISTER(qorvo_qtimer, CONFIG_QORVO_UWB_LOG_LEVEL); @@ -36,10 +37,52 @@ struct qtimer {  static struct qtimer timers[MAX_TIMERS]; +/*+ * Bring-up instrumentation. llhw drives its ranging schedule off this timer, so the wait+ * duration it asks for is a number we can read: if the MAC arms for something absurd, the+ * fault is in the time base rather than the radio.+ *+ * Counters are unbounded but the log trace is capped, because a working schedule would arm+ * this every block and flood the capture. Capping alone is not enough though - last time a+ * cap hid exactly the calls that mattered - so the counters and the last requested interval+ * are reported separately and survive past the cap.+ */+#define QTIMER_TRACE_MAX 16+static unsigned int call_traced;+static unsigned int expiry_traced;+static atomic_t starts;+static atomic_t stops;+static atomic_t expiries;+/* Single aligned 32-bit accesses; diagnostic only, deliberately not synchronised. */+static volatile uint32_t last_us;+static volatile bool last_periodic;++void ff_qorvo_timer_stats(uint32_t *starts_out, uint32_t *stops_out, uint32_t *expiries_out,+			  uint32_t *last_us_out)+{+	if (starts_out != NULL) {+		*starts_out = (uint32_t)atomic_get(&starts);+	}+	if (stops_out != NULL) {+		*stops_out = (uint32_t)atomic_get(&stops);+	}+	if (expiries_out != NULL) {+		*expiries_out = (uint32_t)atomic_get(&expiries);+	}+	if (last_us_out != NULL) {+		*last_us_out = last_us;+	}+}+ static void on_expiry(struct k_timer *t) { 	struct qtimer *q = CONTAINER_OF(t, struct qtimer, timer); +	atomic_inc(&expiries);+	if (expiry_traced < QTIMER_TRACE_MAX) {+		expiry_traced++;+		LOG_INF("qtimer expiry");+	} 	if (q->cb) { 		q->cb(q->arg); 	}@@ -75,10 +118,21 @@ enum qerr qtimer_start(const struct qtimer *timer, uint32_t us, bool periodic) 		return QERR_EINVAL; 	} 	q->started_ticks = k_uptime_ticks();+	atomic_inc(&starts);+	last_us = us;+	last_periodic = periodic;+	if (call_traced < QTIMER_TRACE_MAX) {+		call_traced++;+		LOG_INF("qtimer_start: us=%u (%u ms), periodic=%d", us, us / 1000U,+			(int)periodic);+	} 	/* 	 * Note the inverted sense in qtimer.h: it documents `periodic` as "true for a 	 * one-shot timer, false for a cyclic timer". Going by the parameter name rather-	 * than that comment, since the name is what callers read — periodic means repeat.+	 * than that comment, since the name is what callers read - periodic means repeat.+	 * Settled since: the vendor's own nrfx backend re-arms when the flag is true and+	 * disables when it is false (qhal/src/nrfx/qrtc_share.c), so the comment is wrong+	 * and the name is right. llhw passes false, i.e. one-shot, and re-arms each interval. 	 */ 	k_timer_start(&q->timer, K_USEC(us), periodic ? K_USEC(us) : K_NO_WAIT); 	return QERR_SUCCESS;@@ -91,6 +145,11 @@ enum qerr qtimer_stop(const struct qtimer *timer) 	if (q == NULL || !q->used) { 		return QERR_EINVAL; 	}+	atomic_inc(&stops);+	if (call_traced < QTIMER_TRACE_MAX) {+		call_traced++;+		LOG_INF("qtimer_stop");+	} 	k_timer_stop(&q->timer); 	return QERR_SUCCESS; }