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);