ldc1612: implement 25ms watchdog timeout

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
This commit is contained in:
Timofey Titovets 2025-12-22 01:16:59 +01:00
parent e451c9fea2
commit ee137d74b8
2 changed files with 28 additions and 0 deletions

View file

@ -367,6 +367,7 @@ class EddyGatherSamples:
class EddyDescend:
REASON_SENSOR_ERROR = mcu.MCU_trsync.REASON_COMMS_TIMEOUT + 1
REASON_BUS_IO_ERROR = REASON_SENSOR_ERROR + 12
REASON_WATCHDOG_TIMEOUT = REASON_SENSOR_ERROR + 15
def __init__(self, config, sensor_helper, calibration, param_helper):
self._printer = config.get_printer()
self._sensor_helper = sensor_helper
@ -401,6 +402,8 @@ class EddyDescend:
"Communication timeout during homing")
if res == self.REASON_BUS_IO_ERROR:
raise self._printer.command_error("Eddy I2C IO error")
if res == self.REASON_WATCHDOG_TIMEOUT:
raise self._printer.command_error("Eddy watchdog timeout")
raise self._printer.command_error("Eddy current sensor error")
if res != mcu.MCU_trsync.REASON_ENDSTOP_HIT:
return 0.

View file

@ -31,6 +31,7 @@ struct ldc1612 {
struct trsync *ts;
uint8_t homing_flags;
uint8_t trigger_reason, error_reason;
uint32_t watchdog_deadline;
uint32_t trigger_threshold;
uint32_t homing_clock;
};
@ -111,6 +112,27 @@ command_query_ldc1612_home_state(uint32_t *args)
DECL_COMMAND(command_query_ldc1612_home_state,
"query_ldc1612_home_state oid=%c");
// Default TRSYNC_TIMEOUT, limits ODR > 40
#define WATCHDOG_TIMEOUT timer_from_us(25000)
#define WATCHDOG_TIMEOUT_ERROR (0xf)
static void
watchdog_check(struct ldc1612 *ld)
{
if (!ld->homing_flags)
return;
if (timer_is_before(timer_read_time(), ld->watchdog_deadline))
return;
trsync_do_trigger(ld->ts, ld->error_reason + WATCHDOG_TIMEOUT_ERROR);
ld->homing_flags = 0;
}
static void
watchdog_reset(struct ldc1612 *ld)
{
ld->watchdog_deadline = timer_read_time() + WATCHDOG_TIMEOUT;
}
#define DATA_ERROR_AMPLITUDE (1 << 0)
#define DATA_ERROR_WATCHDOG (1 << 1)
#define DATA_ERROR_OVER_RANGE (1 << 2)
@ -203,6 +225,7 @@ ldc1612_query(struct ldc1612 *ld, uint8_t oid)
irq_disable();
ld->flags &= ~LDC_PENDING;
irq_enable();
watchdog_check(ld);
// Force data read on I2C error or Zero Count
if (!(status & (STATUS_DRDY | STATUS_I2C_ERROR | STATUS_ZERO_COUNT)))
return;
@ -225,6 +248,7 @@ ldc1612_query(struct ldc1612 *ld, uint8_t oid)
| ((uint32_t)d[2] << 8)
| ((uint32_t)d[3]);
check_home(ld, data);
watchdog_reset(ld);
// Flush local buffer if needed
if (ld->sb.data_count + BYTES_PER_SAMPLE > ARRAY_SIZE(ld->sb.data))
@ -248,6 +272,7 @@ command_query_ldc1612(uint32_t *args)
irq_disable();
ld->timer.waketime = timer_read_time() + ld->rest_ticks;
sched_add_timer(&ld->timer);
watchdog_reset(ld);
irq_enable();
}
DECL_COMMAND(command_query_ldc1612, "query_ldc1612 oid=%c rest_ticks=%u");