Skip to content

Commit 99444dc

Browse files
committed
projects: max78000: gate prints on publish count
The ARM gated console output on the ADIS DATA_CNTR delta, so when the sensor's sample counter froze (reads still succeeding) the threshold was never reached and nothing printed at all -- the stream looked hung even though both sensors were being read on the bus. Gate the ~10 Hz decimation on the RISC-V publish counter (seq), which always advances while the coprocessor is alive, so output keeps flowing regardless of the sensor's counter. Keep gyro integration keyed off the real DATA_CNTR delta, and warn once when DATA_CNTR stalls while seq keeps climbing so the condition is observable. Assisted-by: Claude Opus 4.8 Signed-off-by: Victor Pascu <victor.pascu@analog.com>
1 parent a18d00f commit 99444dc

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

projects/max78000/src/examples/imu_dual_core/imu_dual_core_example.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ int imu_dual_core_example_main(void)
431431
uint32_t prev_dcntr = 0;
432432
uint32_t last_doorbell = risc_v_doorbell_count;
433433
uint32_t last_seq = 0;
434-
uint64_t last_print_samples = 0;
434+
uint32_t last_print_seq = 0;
435+
uint32_t dcntr_stuck = 0;
436+
int dcntr_warned = 0;
435437
int have_prev = 0;
436438

437439
for (;;) {
@@ -504,6 +506,20 @@ int imu_dual_core_example_main(void)
504506
accum[1] += (int64_t)gy * delta;
505507
accum[2] += (int64_t)gz * delta;
506508
total_samples += delta;
509+
dcntr_stuck = 0;
510+
dcntr_warned = 0;
511+
} else {
512+
/*
513+
* seq advanced but DATA_CNTR did not: reads succeed yet the
514+
* sensor is not producing new samples. Warn once so the stall
515+
* is visible instead of the console silently not advancing.
516+
*/
517+
if (++dcntr_stuck == IMU_DCNTR_STUCK_SAMPLES && !dcntr_warned) {
518+
printf("[ARM] WARNING: ADIS DATA_CNTR stuck at %lu over %u "
519+
"samples (sensor not updating; check sync/reset)\r\n",
520+
(unsigned long)dc, (unsigned)IMU_DCNTR_STUCK_SAMPLES);
521+
dcntr_warned = 1;
522+
}
507523
}
508524

509525
roll = (int32_t)(accum[0] / ADIS_GYRO_MDEG_DIV);
@@ -514,15 +530,15 @@ int imu_dual_core_example_main(void)
514530
adxl_read_mg(&mgx, &mgy, &mgz);
515531

516532
/*
517-
* Decimate console output to ~10 Hz so UART never backpressures. The
518-
* RISC-V now free-runs, so gate on the ADIS sample count (which advances
519-
* at the fixed 2 kHz ODR) rather than a loop-iteration count: one line
520-
* per 200 samples is 10 Hz regardless of how fast we poll. Gyro
521-
* integration above still runs on every sample.
533+
* Decimate console output to ~10 Hz. Gate on the RISC-V publish
534+
* counter (seq), which always advances while the coprocessor is alive,
535+
* not on DATA_CNTR -- so output keeps flowing even if the sensor's
536+
* sample counter freezes. Gyro integration above still keys off the
537+
* real DATA_CNTR delta.
522538
*/
523-
if (total_samples - last_print_samples < 200)
539+
if (seq - last_print_seq < 200)
524540
continue;
525-
last_print_samples = total_samples;
541+
last_print_seq = seq;
526542

527543
a_mgx = (int32_t)((int64_t)ax / ADIS_ACCL_LSB_PER_MG);
528544
a_mgy = (int32_t)((int64_t)ay / ADIS_ACCL_LSB_PER_MG);
@@ -537,9 +553,9 @@ int imu_dual_core_example_main(void)
537553
print_milli(" g pmod=", mgx);
538554
print_milli(",", mgy);
539555
print_milli(",", mgz);
540-
/* seq counts RISC-V publishes since the last print; with the ADIS at a
541-
* fixed 2 kHz ODR and a 200-sample (10 Hz) print gate, this shows how
542-
* many raw samples the coprocessor pushed for this line. */
556+
/* n = real ADIS samples (DATA_CNTR deltas), seq = RISC-V publishes,
557+
* +N = publishes since last print. n stalling while seq climbs means
558+
* DATA_CNTR is stuck (see WARNING above). */
543559
printf(" g (n=%lu, seq=%lu, +%lu)\r\n", (unsigned long)total_samples,
544560
(unsigned long)seq, (unsigned long)(seq - last_seq));
545561
last_seq = seq;

projects/max78000/src/examples/imu_dual_core/imu_ipc_shared.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@
115115
*/
116116
#define IMU_RV_LOOP_PERIOD_US 500u
117117

118+
/*
119+
* Consecutive RISC-V publishes with no DATA_CNTR change after which the ARM warns
120+
* the ADIS sample counter is stuck. Sized above the per-print publish count so a
121+
* transient hiccup does not trip it.
122+
*/
123+
#define IMU_DCNTR_STUCK_SAMPLES 400u
124+
118125
/**
119126
* RISC-V lifecycle milestones, published (monotonically) in imu_shared_t.state so
120127
* the ARM can gate its own bring-up on the RISC-V's progress. These are ordered
@@ -143,7 +150,7 @@
143150
/**
144151
* @brief Bring-up stage tag written to imu_shared_t.stage before each risky step,
145152
* so a fault or hang can be localized to the last stage the RISC-V entered even if
146-
* it never returns. Distinct from @state (which only advances on success).
153+
* it never returns. Distinct from `state` (which only advances on success).
147154
*/
148155
#define IMU_STAGE_START 0u
149156
#define IMU_STAGE_SPI_INIT 1u /* inside no_os_spi_init */
@@ -175,7 +182,7 @@
175182
* The RISC-V writes lifecycle, fault, and raw ADIS sample fields. The ARM reads
176183
* those raw samples and owns gyro integration, keeping the math in one place.
177184
*
178-
* Ordering: the RISC-V updates the payload then bumps @seq and rings the host
185+
* Ordering: the RISC-V updates the payload then bumps `seq` and rings the host
179186
* doorbell; the ARM waits the doorbell, then reads a coherent snapshot (both
180187
* cores are data-cacheless, so volatile access + the doorbell handshake are
181188
* sufficient — see the dual_core example notes on why the RISC-V issues no fence).

0 commit comments

Comments
 (0)