From ae7ca950f236fd4e2ed850a561c56dec9d306b67 Mon Sep 17 00:00:00 2001 From: Seth Morabito Date: Thu, 13 Apr 2023 05:56:35 +0200 Subject: [PATCH] 3B2: Fix for diagnostics timer hang Under certain circumstances, the timer resolution in the Version 3 could become coarse enough that very short timer intervals would lead to an infinite loop of bus errors when running timer firmware diagnostics. --- 3B2/3b2_timer.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/3B2/3b2_timer.c b/3B2/3b2_timer.c index 3b2f515b..61955df2 100644 --- a/3B2/3b2_timer.c +++ b/3B2/3b2_timer.c @@ -92,9 +92,13 @@ #define QUICK_DELAY 100 #endif -#define DELAY_US(C,N) ((TIMER_MODE(C) == 3) ? \ - (TIME_BASE[(N)] * (C)->divider) / 2 : \ - TIME_BASE[(N)] * (C)->divider) +#define MIN_US 100 + +#define CALC_US(C,N) ((TIMER_MODE(C) == 3) ? \ + (TIME_BASE[(N)] * (C)->divider) / 2 : \ + TIME_BASE[(N)] * (C)->divider) + +#define DELAY_US(C,N) (MAX(MIN_US, CALC_US((C),(N)))) #if defined(REV3) /* Microseconds per step (Version 3 system board):