From f4b6109d1ca6c810e48a0a04f90fc4c2e63aff83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Wed, 22 Oct 2008 19:24:50 +0000 Subject: [PATCH] make calibration loop more tolerant for less accurate OS timers git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1378 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 5 +++++ jtag/src/svf/svf.c | 1 - jtag/src/tap/cable/generic.c | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 2d4207b7..ab3563e9 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,8 @@ +2008-10-22 Arnim Laeuger + + * src/tap/cable/generic.c: make calibration loop more tolerant for + less accurate OS timers + 2008-10-18 Kolja Waschk #include #include -#include #include #include #include diff --git a/jtag/src/tap/cable/generic.c b/jtag/src/tap/cable/generic.c index 6008b920..595bc295 100644 --- a/jtag/src/tap/cable/generic.c +++ b/jtag/src/tap/cable/generic.c @@ -360,7 +360,7 @@ generic_set_frequency( cable_t *cable, uint32_t new_frequency ) cable->frequency = 0; } else { const double tolerance = 0.1; - const uint32_t loops = 2000; + uint32_t loops = 2048; uint32_t delay = cable->delay; uint32_t frequency = cable->frequency; @@ -375,13 +375,22 @@ generic_set_frequency( cable_t *cable, uint32_t new_frequency ) long double start, end, real_frequency; cable->delay = delay; - start = frealtime(); + start = frealtime(); for (i = 0; i < loops; ++i) { cable->driver->clock(cable, 0, 0, 1); } end = frealtime(); - assert(end > start); + if (end < start) { + printf( _("calibration error, wall clock is not monotonically increasing\n") ); + break; + } + if (end == start) { + /* retry with higher loop count + if the timer is not fine grained enough */ + loops *= 2; + continue; + } real_frequency = (long double)loops / (end - start); printf("new real frequency %Lg, delay %u\n", real_frequency, delay);